简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
1.前言
本篇目的:掌握service调试方法解决疑难问题。
2.调试
<1>.service命令
# service
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null | fd f | nfd n | afd f ] ...
Options:
i32: Write the 32-bit integer N into the send parcel.
i64: Write the 64-bit integer N into the send parcel.
f: Write the 32-bit single-precision number N into the send parcel.
d: Write the 64-bit double-precision number N into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
null: Write a null binder into the send parcel.
fd: Write a file descriptor for the file f to the send parcel.
nfd: Write file descriptor n to the send parcel.
afd: Write an ashmem file descriptor for a region containing the data from file f to the send parcel.
<1>.service给"audio"服务发送交互命令
1.frameworks/native/include/audiomanager/IAudioManager.h
class IAudioManager : public IInterface
{
public:
// These transaction IDs must be kept in sync with the method order from
// IAudioService.aidl.
enum {
TRACK_PLAYER = IBinder::FIRST_CALL_TRANSACTION, //=1
PLAYER_ATTRIBUTES = IBinder::FIRST_CALL_TRANSACTION + 1,
PLAYER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 2,
RELEASE_PLAYER = IBinder::FIRST_CALL_TRANSACTION + 3,
TRACK_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 4,
RECORDER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 5,
RELEASE_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 6,
PLAYER_SESSION_ID = IBinder::FIRST_CALL_TRANSACTION + 7,
};
DECLARE_META_INTERFACE(AudioManager)
// The parcels created by these methods must be kept in sync with the
// corresponding methods from IAudioService.aidl and objects it imports.
virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
audio_content_type_t content, const sp<IBinder>& player,
audio_session_t sessionId) = 0;
/*oneway*/ virtual status_t playerAttributes(audio_unique_id_t piid, audio_usage_t usage,
audio_content_type_t content)= 0;
/*oneway*/ virtual status_t playerEvent(audio_unique_id_t piid, player_state_t event,
audio_port_handle_t deviceId) = 0;
/*oneway*/ virtual status_t releasePlayer(audio_unique_id_t piid) = 0;
virtual audio_unique_id_t trackRecorder(const sp<IBinder>& recorder) = 0;
/*oneway*/ virtual status_t recorderEvent(audio_unique_id_t riid, recorder_state_t event) = 0;
/*oneway*/ virtual status_t releaseRecorder(audio_unique_id_t riid) = 0;
/*oneway*/ virtual status_t playerSessionId(audio_unique_id_t piid, audio_session_t sessionId) = 0;
};
TRACK_PLAYER = IBinder::FIRST_CALL_TRANSACTION = 1
2.frameworks/native/services/audiomanager/IAudioManager.cpp
namespace android {
class BpAudioManager : public BpInterface<IAudioManager>
{
public:
explicit BpAudioManager(const sp<IBinder>& impl)
: BpInterface<IAudioManager>(impl)
{
}
virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
audio_content_type_t content, const sp<IBinder>& player, audio_session_t sessionId) {
Parcel data, reply;
data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
data.writeInt32(1); // non-null PlayerIdCard parcelable
// marshall PlayerIdCard data
// get new PIId in reply
const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0);//TRACK_PLAYER = 1
if (res != OK || reply.readExceptionCode() != 0) {
ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID);
return PLAYER_PIID_INVALID;
} else {
const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32();
ALOGV("trackPlayer() returned piid %d", piid);
return piid;
}
}
virtual status_t playerAttributes(audio_unique_id_t piid, audio_usage_t usage,
audio_content_type_t content) {
Parcel data, reply;
data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
data.writeInt32((int32_t) piid);
data.writeInt32(1); // non-null AudioAttributes parcelable
data.writeInt32((int32_t) usage);
data.writeInt32((int32_t) content);
data.writeInt32(0 /*source: none here, this is a player*/);
data.writeInt32(0 /*flags*/);
// write attributes' tags
data.writeInt32(1 /*FLATTEN_TAGS*/);
data.writeString16(String16("")); // no tags
// write attributes' bundle
data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY);
}
};
IMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService");
// ----------------------------------------------------------------------------
};
<2>.通过service给audioservice服务发送TRACK_PLAYER指令
# service call "audio" 1
Result: Parcel(
0x00000000: fffffffc 0000006d 00740041 00650074 '....m...A.t.t.e.'
0x00000010: 0070006d 00200074 006f0074 00720020 'm.p.t. .t.o. .r.'
0x00000020: 00610065 00200064 00720066 006d006f 'e.a.d. .f.r.o.m.'
0x00000030: 00660020 00650069 0064006c 00270020 ' .f.i.e.l.d. .'.'
0x00000040: 006e0069 00200074 006e0061 00720064 'i.n.t. .a.n.d.r.'
0x00000050: 0069006f 002e0064 0065006d 00690064 'o.i.d...m.e.d.i.'
0x00000060: 002e0061 006c0050 00790061 00720065 'a...P.l.a.y.e.r.'
0x00000070: 00610042 00650073 00500024 0061006c 'B.a.s.e.$.P.l.a.'
0x00000080: 00650079 00490072 00430064 00720061 'y.e.r.I.d.C.a.r.'
0x00000090: 002e0064 0050006d 0061006c 00650079 'd...m.P.l.a.y.e.'
0x000000a0: 00540072 00700079 00270065 006f0020 'r.T.y.p.e.'. .o.'
0x000000b0: 0020006e 00200061 0075006e 006c006c 'n. .a. .n.u.l.l.'
0x000000c0: 006f0020 006a0062 00630065 00200074 ' .o.b.j.e.c.t. .'
0x000000d0: 00650072 00650066 00650072 0063006e 'r.e.f.e.r.e.n.c.'
0x000000e0: 00000065 0000032c 00000190 00610009 'e...,.........a.'
0x000000f0: 00200074 006e0061 00720064 0069006f 't. .a.n.d.r.o.i.'
0x00000100: 002e0064 0065006d 00690064 002e0061 'd...m.e.d.i.a...'
0x00000110: 00750041 00690064 0050006f 0061006c 'A.u.d.i.o.P.l.a.'
0x00000120: 00620079 00630061 0043006b 006e006f 'y.b.a.c.k.C.o.n.'
0x00000130: 00690066 00750067 00610072 00690074 'f.i.g.u.r.a.t.i.'
0x00000140: 006e006f 003c002e 006e0069 00740069 'o.n...<.i.n.i.t.'
0x00000150: 0028003e 00750041 00690064 0050006f '>.(.A.u.d.i.o.P.'
0x00000160: 0061006c 00620079 00630061 0043006b 'l.a.y.b.a.c.k.C.'
0x00000170: 006e006f 00690066 00750067 00610072 'o.n.f.i.g.u.r.a.'
0x00000180: 00690074 006e006f 006a002e 00760061 't.i.o.n...j.a.v.'
0x00000190: 003a0061 00330032 00290033 0009000a 'a.:.2.3.3.).....'
0x000001a0: 00740061 00630020 006d006f 0061002e 'a.t. .c.o.m...a.'
0x000001b0: 0064006e 006f0072 00640069 0073002e 'n.d.r.o.i.d...s.'
0x000001c0: 00720065 00650076 002e0072 00750061 'e.r.v.e.r...a.u.'
0x000001d0: 00690064 002e006f 006c0050 00790061 'd.i.o...P.l.a.y.'
0x000001e0: 00610062 006b0063 00630041 00690074 'b.a.c.k.A.c.t.i.'
0x000001f0: 00690076 00790074 006f004d 0069006e 'v.i.t.y.M.o.n.i.'
0x00000200: 006f0074 002e0072 00720074 00630061 't.o.r...t.r.a.c.'
0x00000210: 0050006b 0061006c 00650079 00280072 'k.P.l.a.y.e.r.(.'
0x00000220: 006c0050 00790061 00610062 006b0063 'P.l.a.y.b.a.c.k.'
0x00000230: 00630041 00690074 00690076 00790074 'A.c.t.i.v.i.t.y.'
0x00000240: 006f004d 0069006e 006f0074 002e0072 'M.o.n.i.t.o.r...'
0x00000250: 0061006a 00610076 0031003a 00320036 'j.a.v.a.:.1.6.2.'
0x00000260: 000a0029 00610009 00200074 006f0063 ').....a.t. .c.o.'
0x00000270: 002e006d 006e0061 00720064 0069006f 'm...a.n.d.r.o.i.'
0x00000280: 002e0064 00650073 00760072 00720065 'd...s.e.r.v.e.r.'
0x00000290: 0061002e 00640075 006f0069 0041002e '..a.u.d.i.o...A.'
0x000002a0: 00640075 006f0069 00650053 00760072 'u.d.i.o.S.e.r.v.'
0x000002b0: 00630069 002e0065 00720074 00630061 'i.c.e...t.r.a.c.'
0x000002c0: 0050006b 0061006c 00650079 00280072 'k.P.l.a.y.e.r.(.'
0x000002d0: 00750041 00690064 0053006f 00720065 'A.u.d.i.o.S.e.r.'
0x000002e0: 00690076 00650063 006a002e 00760061 'v.i.c.e...j.a.v.'
0x000002f0: 003a0061 00370039 00390031 000a0029 'a.:.9.7.1.9.)...'
0x00000300: 00610009 00200074 006e0061 00720064 '..a.t. .a.n.d.r.'
0x00000310: 0069006f 002e0064 0065006d 00690064 'o.i.d...m.e.d.i.'
0x00000320: 002e0061 00410049 00640075 006f0069 'a...I.A.u.d.i.o.'
0x00000330: 00650053 00760072 00630069 00240065 'S.e.r.v.i.c.e.$.'
0x00000340: 00740053 00620075 006f002e 0054006e 'S.t.u.b...o.n.T.'
0x00000350: 00610072 0073006e 00630061 00280074 'r.a.n.s.a.c.t.(.'
0x00000360: 00410049 00640075 006f0069 00650053 'I.A.u.d.i.o.S.e.'
0x00000370: 00760072 00630069 002e0065 0061006a 'r.v.i.c.e...j.a.'
0x00000380: 00610076 0031003a 00320032 00290035 'v.a.:.1.2.2.5.).'
0x00000390: 0009000a 00740061 00610020 0064006e '....a.t. .a.n.d.'
0x000003a0: 006f0072 00640069 006f002e 002e0073 'r.o.i.d...o.s...'
0x000003b0: 00690042 0064006e 00720065 0065002e 'B.i.n.d.e.r...e.'
0x000003c0: 00650078 00540063 00610072 0073006e 'x.e.c.T.r.a.n.s.'
0x000003d0: 00630061 00490074 0074006e 00720065 'a.c.t.I.n.t.e.r.'
0x000003e0: 0061006e 0028006c 00690042 0064006e 'n.a.l.(.B.i.n.d.'
0x000003f0: 00720065 006a002e 00760061 003a0061 'e.r...j.a.v.a.:.'
0x00000400: 00310031 00340038 000a0029 00000000 '1.1.8.4.).......')
这里显示调用在A.c.t.i.v.i.t.yM.o.n.i.t.o.r.j.a.v.a.:.1.6.2,即PlaybackActivityMonitor.java文件的162行,仔细阅读会有答案。
<2>.通过service打开SurfaceFlinger刷新率并显示在屏幕上
enableRefreshRateOverlay(static_cast(n))),中的n就是1为开,0为关。
1.打开刷新率
# service call SurfaceFlinger 1034 i32 1
Result: Parcel(NULL)
打开成功后,手机的左上角会显示红色字体的刷新率。
2.关闭刷新率
# service call SurfaceFlinger 1034 i32 0
Result: Parcel(NULL)
关闭成功后,手机的左上角会显示红色字体的刷新率消失。