安卓通话状态监控之挂电话部分

来源:互联网 发布:网络侵权结果发生地 编辑:程序博客网 时间:2024/04/30 14:21

挂电话部分

在app/phone下

<span style="font-size:18px;"> void handleOnscreenButtonClick(int id) {        if (DBG) log("handleOnscreenButtonClick(id " + id + ")...");        switch (id) {            // Actions while an incoming call is ringing:                     case R.id.endAllCallsButton:                PhoneUtils.hangupAll(mPhone);                break;            default:                Log.w(LOG_TAG, "handleOnscreenButtonClick: unexpected ID " + id);                break;        }        mApp.pokeUserActivity();</span></span>

这里的case R.id.endAllCallsButton:就是挂掉所有电话

PhoneUtils.hangupAll(mPhone);关键之一就在于找这个mphone从哪来的

<span style="font-size:18px;">void setPhone(Phone phone, CallManager cm) {        if (phone != mPhone || mCM != cm) {            mCM = cm;            mPhone = phone;            if (DBG) log("switching to phone: " + phone.getPhoneName());            if (mInCallControlState != null) {                mInCallControlState.setCM(cm);            }            if (mManageConferenceUtils != null) {                mManageConferenceUtils.setCM(cm);            }        }    }</span>

整个class里就这个地方初始化了mphone,查找哪里调用了InCallScreen.java

<span style="font-size:18px;"> setPhone(DualPhoneController.getInstance().getActivePhone(), DualPhoneController.getInstance().getActiveCM());</span>


查找getActivePhone()
<span style="font-size:18px;">    Phone getActivePhone() {        if (isPrimaryOnSim1()) {            return mActiveSimId == ID_SIM_1 ? mApp.phone : mApp.phone2;        }        return mActiveSimId == ID_SIM_1 ? mApp.phone2 : mApp.phone;    }</span>
查找mApp

<span style="font-size:18px;">private DualPhoneController(PhoneGlobals app) {        mApp = app;        mCM = app.mCM;        mCM2 = app.mCM2;        mPrimaryId = Settings.Global.getInt(PhoneGlobals.getInstance().getContentResolver(),                Settings.Global.MOBILE_DATA_SIM,                TelephonyConstants.DSDS_SLOT_1_ID);    }</span>

查找这个函数被调用的地方
<span style="font-size:18px;"> /* package */ static DualPhoneController init(PhoneGlobals app) {        synchronized (NotificationMgr.class) {            if (sInstance == null) {                sInstance = new DualPhoneController(app);            } else {                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);            }            return sInstance;        }    }</span>
所有的问题都在与不论是PhoneGlobals.java还是DualPhoneController.java都在phone这个app内部,而无法在service或者framework里导出

不过在PhoneGlobals.java看到

phone = PhoneFactory.getDefaultPhone();phone2 = PhoneFactory.get2ndPhone();
最终还是用了service里的方法,所以mphone的追踪到此结束


这个

<span style="font-size:18px;"><span style="font-size:18px;">PhoneUtils的定义在package/apps/phone里</span></span>

<span style="font-size:18px;"><span style="font-size:18px;"> static void hangupAll(Phone phone) {        if (phone == null)            return ;        String[] request = new String[1];        request[0] = Integer.toString(                OemTelephonyConstants.RIL_OEM_HOOK_STRING_RELEASE_ALL_CALLS);        phone.invokeOemRilRequestStrings(request, null);    }</span></span>
这个phone的定义在opt/telephony目录下
这里追踪/frameworks/opt/telephony/src/java/com/android/internal/telephony目录下的ril.java

<span style="font-size:18px;"><span style="font-size:18px;">  public void invokeOemRilRequestStrings(String[] strings, Message response) {        RILRequest rr                = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_STRINGS, response, mIs2ndRil);        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));        rr.mParcel.writeStringArray(strings);        send(rr);    }</span></span>
从这里看来phone的这个类型非常关键,phone的定义在

/third/frameworks/opt/telephony/src/java/com/android/internal/telephony$

而在eclipse中想导入这个telephony的包,则去看opt/telephony的目录下的android.mk文件

<span style="font-size:18px;"><span style="font-size:18px;">ifeq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),platform)LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/src/javaLOCAL_SRC_FILES := $(call all-java-files-under, src/java) \$(call all-Iaidl-files-under, src/java) \$(call all-logtags-files-under, src/java)LOCAL_SRC_FILES += $(call all-java-files-under, src/com/asus/dsds/base)ifeq ($(BOARD_USES_QCOM_HARDWARE),true)LOCAL_SRC_FILES += $(call all-java-files-under, src/com/asus/dsds/qc)else    ifeq ($(INTEL_INGREDIENTS_VERSIONS),true)    LOCAL_SRC_FILES += $(call all-java-files-under, src/com/asus/dsds/intel)    else    LOCAL_SRC_FILES += $(call all-java-files-under, src/com/asus/dsds/default)    endifendifLOCAL_JAVA_LIBRARIES := voip-commonLOCAL_MODULE_TAGS := optionalLOCAL_MODULE := telephony-commoninclude $(BUILD_JAVA_LIBRARY)# Include subdirectory makefiles# ============================================================include $(call all-makefiles-under,$(LOCAL_PATH))endif # JAVA platform</span></span>

这里说的
<span style="font-size:18px;"><span style="font-size:18px;">LOCAL_MODULE := telephony-common</span></span>

就是生成的jar的名字

而在out目录下搜索这个包名

find . -name telephony-common*

发现./target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates这个目录下有个classes.jar,将其导入后就发现可以识别phone的类型和callmanager的类型。







<span style="font-size:18px;"><span style="font-size:18px;"><span style="font-size:18px;"><span style="font-size:18px;">public boolean hangupCall() {            enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);            if (mCM.hasActiveFgCall()) {                return PhoneUtils.hangupActiveCall(mCM.getActiveFgCall());            } else if (mCM.hasActiveRingingCall()) {                return PhoneUtils.hangupRingingCall(mCM.getFirstActiveRingingCall());            } else if (mCM.hasActiveBgCall()) {                return PhoneUtils.hangupHoldingCall(mCM.getFirstActiveBgCall());            }</span></span></span></span>

从上面的代码里看,一个PhoneUtils和mCM是需要获取,

获取mcm


<span style="font-size:18px;"><span style="font-size:18px;">mCM1 = CallManager.getInstance();mCM2 = CallManager.getInstance2();</span></span>
获取PhoneUtils

由于并没看到PhoneUtils的定义所以这个类应该是只要包含一个jar包即可使用



0 0
原创粉丝点击