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

Commit 229ce693 authored by Chen Xu's avatar Chen Xu Committed by android-build-merger
Browse files

Merge "reset carrier actions when exits roaming state." into oc-dr1-dev

am: ff5b1b9f

Change-Id: I818246b4cdace19affd432fcce527e7ab2f43619
parents cc940f42 ff5b1b9f
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
@@ -843,12 +843,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
@@ -1053,7 +1053,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
@@ -674,7 +674,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
@@ -579,7 +579,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();
@@ -1003,7 +1003,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);