Android10 dual sim card modification default traffic card problem

need


Switch the default traffic card through AI voice (switch the default sim card)

question


I thought it was just a common requirement. Since you can switch manually in the settings, you just need to find the corresponding system API interface. But after a call on Baidu and reading the incomprehensible documents on the official website, it was finally confirmed that this FMD is not a public interface.

Insert image description here

solution

But fortunately, the previous pile of incomprehensible documents were not in vain. At least it was confirmed that the requirement can be achieved from the system layer. In the end, I finally used my connections that I didn't have to convince the driver engineer to help me recompile the system. In fact, it's not difficult. The main thing is the damn power, oh no, permission.

Finally confirm the following code entry through the pop-up box of switching the sim card in the settings:

@Override
    public void onClick(DialogInterface dialog, int selectionIndex) {
        if (selectionIndex >= 0 && selectionIndex < mSubscriptions.size()) {
            int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            final SubscriptionInfo subscription = mSubscriptions.get(selectionIndex);
            if (subscription != null) {
                subId = subscription.getSubscriptionId();
            }
            final SimDialogActivity activity = (SimDialogActivity) getActivity();
            activity.onSubscriptionSelected(getDialogType(), subId);
        }
    }

If you continue to follow up, you will find that this damn line of code is setDefaultDataSubId(subId);

private void setDefaultDataSubId(final int subId) {
        final SubscriptionManager subscriptionManager = getSystemService(SubscriptionManager.class);
        final TelephonyManager telephonyManager = getSystemService(
                TelephonyManager.class).createForSubscriptionId(subId);
        subscriptionManager.setDefaultDataSubId(subId);
        telephonyManager.setDataEnabled(true);
        Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show();
    }

This is easy to solve. Since the official default is not to make it public, just find a way to make it public. Here I directly customize a system broadcast, and then the application layer directly sends the broadcast for control. I will not post the code here, leaving it to everyone. Guys come and give me advice.

Guess you like

Origin blog.csdn.net/qq_35350654/article/details/128284845