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

挂电话部分

在app/phone下

 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();

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

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

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);
            }
        }
    }

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

 setPhone(DualPhoneController.getInstance().getActivePhone(), DualPhoneController.getInstance().getActiveCM());


查找getActivePhone()
    Phone getActivePhone() {
        if (isPrimaryOnSim1()) {
            return mActiveSimId == ID_SIM_1 ? mApp.phone : mApp.phone2;
        }
        return mActiveSimId == ID_SIM_1 ? mApp.phone2 : mApp.phone;
    }
查找mApp

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);
    }

查找这个函数被调用的地方
 /* 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;
        }
    }
所有的问题都在与不论是PhoneGlobals.java还是DualPhoneController.java都在phone这个app内部,而无法在service或者framework里导出

不过在PhoneGlobals.java看到

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


这个

PhoneUtils的定义在package/apps/phone里

 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);
    }
这个phone的定义在opt/telephony目录下
这里追踪/frameworks/opt/telephony/src/java/com/android/internal/telephony目录下的ril.java

  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);
    }
从这里看来phone的这个类型非常关键,phone的定义在

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

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

ifeq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),platform)

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/src/java
LOCAL_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)
    endif
endif

LOCAL_JAVA_LIBRARIES := voip-common
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := telephony-common

include $(BUILD_JAVA_LIBRARY)

# Include subdirectory makefiles
# ============================================================
include $(call all-makefiles-under,$(LOCAL_PATH))

endif # JAVA platform

这里说的
LOCAL_MODULE := telephony-common

就是生成的jar的名字

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

find . -name telephony-common*

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







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());
            }

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

获取mcm


mCM1 = CallManager.getInstance();
mCM2 = CallManager.getInstance2();
获取PhoneUtils

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



你可能感兴趣的:(安卓通话状态监控之挂电话部分)