Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d6ff795 authored by fionaxu's avatar fionaxu
Browse files

reset carrier actions when exits roaming state.

carrier apps might restrict mobile data if users enter roaming state
without any romaing plan/balance. however when users exit roaming state,
we should reset carrier data restrictions to re-evaluate data state.

Test: manual test roaming on->off->on by setprop
telephony.test.forceRoaming

Bug: 63819703
Change-Id: If91042054ce973c384fe03aa0b733de9f8033bf6
parent 42705ae4
Loading
Loading
Loading
Loading
+42 −22
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ public class CarrierActionAgent extends Handler {
    public static final int CARRIER_ACTION_RESET                         = 2;
    public static final int EVENT_APM_SETTINGS_CHANGED                   = 3;
    public static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED           = 4;
    public static final int EVENT_DATA_ROAMING_OFF                       = 5;
    public static final int EVENT_SIM_STATE_CHANGED                      = 6;

    /** Member variables */
    private final Phone mPhone;
@@ -84,21 +86,7 @@ public class CarrierActionAgent extends Handler {
                    // ignore rebroadcast since carrier apps are direct boot aware.
                    return;
                }
                if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState)) {
                    sendEmptyMessage(CARRIER_ACTION_RESET);
                    String mobileData = Settings.Global.MOBILE_DATA;
                    if (TelephonyManager.getDefault().getSimCount() != 1) {
                        mobileData = mobileData + mPhone.getSubId();
                    }
                    mSettingsObserver.observe(Settings.Global.getUriFor(mobileData),
                            EVENT_MOBILE_DATA_SETTINGS_CHANGED);
                    mSettingsObserver.observe(
                            Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON),
                            EVENT_APM_SETTINGS_CHANGED);
                } else if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) {
                    sendEmptyMessage(CARRIER_ACTION_RESET);
                    mSettingsObserver.unobserve();
                }
                sendMessage(obtainMessage(EVENT_SIM_STATE_CHANGED, iccState));
            }
        }
    };
@@ -132,22 +120,46 @@ public class CarrierActionAgent extends Handler {
                break;
            case CARRIER_ACTION_RESET:
                log("CARRIER_ACTION_RESET");
                carrierActionSetMeteredApnsEnabled(true);
                carrierActionSetRadioEnabled(true);
                // notify configured carrier apps for reset
                mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(
                        new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET));
                carrierActionReset();
                break;
            case EVENT_APM_SETTINGS_CHANGED:
                log("EVENT_APM_SETTINGS_CHANGED");
                if ((Settings.Global.getInt(mPhone.getContext().getContentResolver(),
                        Settings.Global.AIRPLANE_MODE_ON, 0) != 0)) {
                    sendEmptyMessage(CARRIER_ACTION_RESET);
                    carrierActionReset();
                }
                break;
            case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
                log("EVENT_MOBILE_DATA_SETTINGS_CHANGED");
                if (!mPhone.getDataEnabled()) sendEmptyMessage(CARRIER_ACTION_RESET);
                if (!mPhone.getDataEnabled()) carrierActionReset();
                break;
            case EVENT_DATA_ROAMING_OFF:
                log("EVENT_DATA_ROAMING_OFF");
                // reset carrier actions when exit roaming state.
                carrierActionReset();
                break;
            case EVENT_SIM_STATE_CHANGED:
                String iccState = (String) msg.obj;
                if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState)) {
                    log("EVENT_SIM_STATE_CHANGED status: " + iccState);
                    carrierActionReset();
                    String mobileData = Settings.Global.MOBILE_DATA;
                    if (TelephonyManager.getDefault().getSimCount() != 1) {
                        mobileData = mobileData + mPhone.getSubId();
                    }
                    mSettingsObserver.observe(Settings.Global.getUriFor(mobileData),
                            EVENT_MOBILE_DATA_SETTINGS_CHANGED);
                    mSettingsObserver.observe(
                            Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON),
                            EVENT_APM_SETTINGS_CHANGED);
                    mPhone.getServiceStateTracker().registerForDataRoamingOff(
                            this, EVENT_DATA_ROAMING_OFF, null, false);
                } else if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) {
                    log("EVENT_SIM_STATE_CHANGED status: " + iccState);
                    carrierActionReset();
                    mSettingsObserver.unobserve();
                    mPhone.getServiceStateTracker().unregisterForDataRoamingOff(this);
                }
                break;
            default:
                loge("Unknown carrier action: " + msg.what);
@@ -179,6 +191,14 @@ public class CarrierActionAgent extends Handler {
        sendMessage(obtainMessage(CARRIER_ACTION_SET_METERED_APNS_ENABLED, enabled));
    }

    private void carrierActionReset() {
        carrierActionSetMeteredApnsEnabled(true);
        carrierActionSetRadioEnabled(true);
        // notify configured carrier apps for reset
        mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(
                new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET));
    }

    private RegistrantList getRegistrantsFromAction(int action) {
        switch (action) {
            case CARRIER_ACTION_SET_METERED_APNS_ENABLED:
+3 −2
Original line number Diff line number Diff line
@@ -842,12 +842,13 @@ public class ServiceStateTracker extends Handler {
     * @param h handler to notify
     * @param what what code of message when delivered
     * @param obj placed in Message.obj
     * @param notifyNow notify upon registration if data roaming is off
     */
    public void registerForDataRoamingOff(Handler h, int what, Object obj) {
    public void registerForDataRoamingOff(Handler h, int what, Object obj, boolean notifyNow) {
        Registrant r = new Registrant(h, what, obj);
        mDataRoamingOffRegistrants.add(r);

        if (!mSS.getDataRoaming()) {
        if (notifyNow && !mSS.getDataRoaming()) {
            r.notifyRegistrant();
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -1058,7 +1058,7 @@ public class DataConnection extends StateMachine {
            mPhone.getServiceStateTracker().registerForDataRoamingOn(getHandler(),
                    DataConnection.EVENT_DATA_CONNECTION_ROAM_ON, null);
            mPhone.getServiceStateTracker().registerForDataRoamingOff(getHandler(),
                    DataConnection.EVENT_DATA_CONNECTION_ROAM_OFF, null);
                    DataConnection.EVENT_DATA_CONNECTION_ROAM_OFF, null, true);

            // Add ourselves to the list of data connections
            mDcController.addDc(DataConnection.this);
+1 −1
Original line number Diff line number Diff line
@@ -713,7 +713,7 @@ public class DcTracker extends Handler {
        mPhone.getServiceStateTracker().registerForDataRoamingOn(this,
                DctConstants.EVENT_ROAMING_ON, null);
        mPhone.getServiceStateTracker().registerForDataRoamingOff(this,
                DctConstants.EVENT_ROAMING_OFF, null);
                DctConstants.EVENT_ROAMING_OFF, null, true);
        mPhone.getServiceStateTracker().registerForPsRestrictedEnabled(this,
                DctConstants.EVENT_PS_RESTRICT_ENABLED, null);
        mPhone.getServiceStateTracker().registerForPsRestrictedDisabled(this,
+2 −2
Original line number Diff line number Diff line
@@ -576,7 +576,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {

        waitForMs(100);

        sst.registerForDataRoamingOff(mTestHandler, EVENT_DATA_ROAMING_OFF, null);
        sst.registerForDataRoamingOff(mTestHandler, EVENT_DATA_ROAMING_OFF, null, true);

        // Disable roaming
        doReturn(true).when(mPhone).isPhoneTypeGsm();
@@ -1000,7 +1000,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {

        waitForMs(200);

        sst.registerForDataRoamingOff(mTestHandler, EVENT_DATA_ROAMING_OFF, null);
        sst.registerForDataRoamingOff(mTestHandler, EVENT_DATA_ROAMING_OFF, null, true);
        sst.registerForVoiceRoamingOff(mTestHandler, EVENT_VOICE_ROAMING_OFF, null);
        sst.registerForDataConnectionDetached(mTestHandler, EVENT_DATA_CONNECTION_DETACHED, null);