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

Commit 3860bcb2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Reset carrier actions when APN change"

parents 64c6af7e e8d83a41
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Message;
import android.os.Registrant;
import android.os.RegistrantList;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.LocalLog;
@@ -63,6 +64,7 @@ public class CarrierActionAgent extends Handler {
    public static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED             = 5;
    public static final int EVENT_DATA_ROAMING_OFF                         = 6;
    public static final int EVENT_SIM_STATE_CHANGED                        = 7;
    public static final int EVENT_APN_SETTINGS_CHANGED                     = 8;

    /** Member variables */
    private final Phone mPhone;
@@ -169,6 +171,8 @@ public class CarrierActionAgent extends Handler {
                    mSettingsObserver.observe(
                            Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON),
                            EVENT_APM_SETTINGS_CHANGED);
                    mSettingsObserver.observe(
                            Telephony.Carriers.CONTENT_URI, EVENT_APN_SETTINGS_CHANGED);
                    if (mPhone.getServiceStateTracker() != null) {
                        mPhone.getServiceStateTracker().registerForDataRoamingOff(
                                this, EVENT_DATA_ROAMING_OFF, null, false);
@@ -182,6 +186,11 @@ public class CarrierActionAgent extends Handler {
                    }
                }
                break;
            case EVENT_APN_SETTINGS_CHANGED:
                log("EVENT_APN_SETTINGS_CHANGED");
                // Reset carrier actions when APN change.
                carrierActionReset();
                break;
            default:
                loge("Unknown carrier action: " + msg.what);
        }
+42 −0
Original line number Diff line number Diff line
@@ -139,6 +139,48 @@ public class CarrierActionAgentTest extends TelephonyTest {
        assertEquals(true, ((AsyncResult) message.getValue().obj).result);
    }

    @Test
    @SmallTest
    public void testCarrierActionResetOnAPNChange() {
        // Setting observer register at sim loading
        final Intent intent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        intent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_LOADED);
        mContext.sendBroadcast(intent);
        waitForMs(200);

        // no carrier actions triggered from sim loading since there are same as the current one
        ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class);
        verify(mDataActionHandler, times(0)).sendMessageAtTime(message.capture(), anyLong());
        verify(mRadioActionHandler, times(0)).sendMessageAtTime(message.capture(), anyLong());

        // disable metered apns and radio
        mCarrierActionAgentUT.carrierActionSetRadioEnabled(false);
        mCarrierActionAgentUT.carrierActionSetMeteredApnsEnabled(false);
        waitForMs(200);

        verify(mDataActionHandler, times(1)).sendMessageAtTime(message.capture(), anyLong());
        assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what);
        assertEquals(false, ((AsyncResult) message.getValue().obj).result);

        verify(mRadioActionHandler, times(1)).sendMessageAtTime(message.capture(), anyLong());
        assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what);
        assertEquals(false, ((AsyncResult) message.getValue().obj).result);

        // Simulate APN change
        mFakeContentResolver.notifyChange(Telephony.Carriers.CONTENT_URI, null);
        waitForMs(200);

        // Carrier actions triggered from APN change
        verify(mDataActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong());
        assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what);
        assertEquals(true, ((AsyncResult) message.getValue().obj).result);

        verify(mRadioActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong());
        assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what);
        assertEquals(true, ((AsyncResult) message.getValue().obj).result);
    }

    @After
    public void tearDown() throws Exception {
        Settings.Global.putInt(mFakeContentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);