|
|
@ -41,6 +41,7 @@ import com.xypower.mpmaster.sms.SmsSendReceiver;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
@ -911,8 +912,53 @@ public class MpMasterService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void selectSimCard(int num) {
|
|
|
|
public void selectSimCard(int num) {
|
|
|
|
logger.warning("Select SimCard: " + Integer.toString(num));
|
|
|
|
logger.info("Try to Switch To SimCard: " + Integer.toString(num));
|
|
|
|
SysApi.selectSimCard4Data(getApplicationContext(), num);
|
|
|
|
|
|
|
|
|
|
|
|
Context context = getApplicationContext();
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
int activeSubId = SubscriptionManager.getActiveDataSubscriptionId();
|
|
|
|
|
|
|
|
int activeSlotIdx = SubscriptionManager.getSlotIndex(activeSubId);
|
|
|
|
|
|
|
|
if (activeSlotIdx == (num - 1)) {
|
|
|
|
|
|
|
|
logger.info("Active SimCard is already " + Integer.toString(num));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int subIds[] = subscriptionManager.getSubscriptionIds(num - 1);
|
|
|
|
|
|
|
|
if (subIds != null && subIds.length > 0) {
|
|
|
|
|
|
|
|
setDefaultDataSubId(subIds[0]);
|
|
|
|
|
|
|
|
logger.info("Switched To SimCard: " + Integer.toString(num));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
SysApi.selectSimCard4Data(context, num);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
|
|
|
|
|
|
|
|
method.invoke(subscriptionManager, subId);
|
|
|
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
|
|
|
telephonyManager.setDataEnabled(true);
|
|
|
|
|
|
|
|
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
|
|
|
|
|
|
|
|
method1.invoke(telephonyManager, true);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
// Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("getDefaultDataSubscriptionId");
|
|
|
|
|
|
|
|
return (int) method.invoke(subscriptionManager);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug getDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public native static int getInt(int cmd);
|
|
|
|
public native static int getInt(int cmd);
|
|
|
|