1. 程式人生 > >Android 解決雙卡雙待的問題 mtk,展訊,高通

Android 解決雙卡雙待的問題 mtk,展訊,高通

目前國內對於雙卡智慧手機的需求還是很大的,各種複雜的業務會涉及到雙卡模組;而android標準的api又不提供對雙卡的支援。導致國內雙卡模組標準混亂,各個廠商各玩各的。目前我知道的雙卡解決方案就有:mtk,展訊,高通,broadcom等。

由於公司業務需要,必須要對雙卡手機獲取各自的imei,imsi,所以也做了一些研究:

首先是最為應用廣泛的mtk平臺,國內山寨手機以及一些低端品牌雙卡都是做的mtk的雙卡解決方案

private static void initMtkDoubleSim() {


try {



TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);



Class<?> c = Class.forName("com.android.internal.telephony.Phone");



Field fields1 = c.getField("GEMINI_SIM_1");



fields1.setAccessible(true);



simId_1 = (Integer) fields1.get(null);



Field fields2 = c.getField("GEMINI_SIM_2");



fields2.setAccessible(true);



simId_2 = (Integer) fields2.get(null);




Method m = TelephonyManager.class.getDeclaredMethod(





"getSubscriberIdGemini", int.class);



imsi_1 = (String) m.invoke(tm, simId_1);



imsi_2 = (String) m.invoke(tm, simId_2);




Method m1 = TelephonyManager.class.getDeclaredMethod(





"getDeviceIdGemini", int.class);



imei_1 = (String) m1.invoke(tm, simId_1);



imei_2 = (String) m1.invoke(tm, simId_2);




Method mx = TelephonyManager.class.getDeclaredMethod(





"getPhoneTypeGemini", int.class);



phoneType_1 = (Integer) mx.invoke(tm, simId_1);



phoneType_2 = (Integer) mx.invoke(tm, simId_2);




if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {




defaultImsi = imsi_2;



}



if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {




defaultImsi = imsi_1;



}


} catch (Exception e) {



isMtkDoubleSim = false;



return;


}


isMtkDoubleSim = true;

}

 可見,在TelephonyManager中提供了**Gemini的方法,可以用反射很方便地獲取到相應的資訊。

還有

private static void initMtkSecondDoubleSim() {


try {



TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);



Class<?> c = Class.forName("com.android.internal.telephony.Phone");



Field fields1 = c.getField("GEMINI_SIM_1");



fields1.setAccessible(true);



simId_1 = (Integer) fields1.get(null);



Field fields2 = c.getField("GEMINI_SIM_2");



fields2.setAccessible(true);



simId_2 = (Integer) fields2.get(null);




Method mx = TelephonyManager.class.getMethod("getDefault",





int.class);



TelephonyManager tm1 = (TelephonyManager) mx.invoke(tm, simId_1);



TelephonyManager tm2 = (TelephonyManager) mx.invoke(tm, simId_2);




imsi_1 = tm1.getSubscriberId();



imsi_2 = tm2.getSubscriberId();




imei_1 = tm1.getDeviceId();



imei_2 = tm2.getDeviceId();




phoneType_1 = tm1.getPhoneType();



phoneType_2 = tm2.getPhoneType();




if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {




defaultImsi = imsi_2;



}



if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {




defaultImsi = imsi_1;



}



} catch (Exception e) {



isMtkSecondDoubleSim = false;



return;


}


isMtkSecondDoubleSim = true;

}

 看樣子有似乎也是屬於mtk平臺的解決方案,因為都有GEMINI_SIM_1屬性,這種雙卡方案只在聯想278t上發現過;有兩個TelephonyManager例項,根據getDefault方法獲取

下面是展訊平臺的(貌似市面上手機不多啊):

private static void initSpreadDoubleSim() {


try {



Class<?> c = Class





.forName("com.android.internal.telephony.PhoneFactory");



Method m = c.getMethod("getServiceName", String.class, int.class);



spreadTmService = (String) m





.invoke(c, Context.TELEPHONY_SERVICE, 1);




TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);



imsi_1 = tm.getSubscriberId();



imei_1 = tm.getDeviceId();



phoneType_1 = tm.getPhoneType();



TelephonyManager tm1 = (TelephonyManager) mContext.getSystemService(spreadTmService);



imsi_2 = tm1.getSubscriberId();



imei_2 = tm1.getDeviceId();



phoneType_2 = tm1.getPhoneType();



if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {




defaultImsi = imsi_2;



}



if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {




defaultImsi = imsi_1;



}



} catch (Exception e) {



isSpreadDoubleSim = false;



return;


}


isSpreadDoubleSim = true;

}

 這個沒有展訊sdk的話還是很難找的吧?

下面是高通的:(貌似高通做的不咋的有些介面沒有雙卡實現啊)

public static void initQualcommDoubleSim() {
try {
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> cx = Class
.forName("android.telephony.MSimTelephonyManager");
Object obj =mContext.getSystemService(
"phone_msim");
simId_1 = 0;
simId_2 = 1;

Method mx = cx.getMethod("getDataState");
// int stateimei_1 = (Integer) mx.invoke(cx.newInstance());
int stateimei_2 = tm.getDataState();
Method mde = cx.getMethod("getDefault");
Method md = cx.getMethod("getDeviceId", int.class);
Method ms = cx.getMethod("getSubscriberId", int.class);
Method mp = cx.getMethod("getPhoneType");

// Object obj = mde.invoke(cx);

imei_1 = (String) md.invoke(obj, simId_1);
imei_2 = (String) md.invoke(obj, simId_2);

imsi_1 = (String) ms.invoke(obj, simId_1);
imsi_2 = (String) ms.invoke(obj, simId_2);

int statephoneType_1 = tm.getDataState();
int statephoneType_2 = (Integer) mx.invoke(obj);
Log.e("tag", statephoneType_1 +"---"+ statephoneType_2);

// Class<?> msc = Class.forName("android.telephony.MSimSmsManager");
// for (Method m : msc.getMethods()) {
// if (m.getName().equals("sendTextMessage")) {
// m.getParameterTypes();
// }
// Log.e("tag", m.getName());
// }

} catch (Exception e) {
isQualcommDoubleSim = false;
return;
}
isQualcommDoubleSim = true;

}

getPhoneType&getDataState 方法看了底層發現沒有雙卡實現,目前也不知道該咋辦...