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

Commit 9705ad65 authored by Jordan Liu's avatar Jordan Liu Committed by android-build-merger
Browse files

Merge "CarrierServiceStateTracker: Solve problems with dual sim"

am: 118bec00

Change-Id: Ibca6edc2ddb2192c54db0f00612edf899c9134ea
parents 13b9f26e 118bec00
Loading
Loading
Loading
Loading
+46 −10
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Message;
@@ -64,6 +65,12 @@ public class CarrierServiceStateTracker extends Handler {
    public static final int NOTIFICATION_PREF_NETWORK = 1000;
    public static final int NOTIFICATION_EMERGENCY_NETWORK = 1001;

    @VisibleForTesting
    public static final String EMERGENCY_NOTIFICATION_TAG = "EmergencyNetworkNotification";

    @VisibleForTesting
    public static final String PREF_NETWORK_NOTIFICATION_TAG = "PrefNetworkNotification";

    public CarrierServiceStateTracker(Phone phone, ServiceStateTracker sst) {
        this.mPhone = phone;
        this.mSST = sst;
@@ -238,7 +245,7 @@ public class CarrierServiceStateTracker extends Handler {
            Rlog.i(LOG_TAG, "starting timer for notifications." + notificationType.getTypeId());
            sendMessageDelayed(notificationMsg, getDelay(notificationType));
        } else {
            cancelNotification(notificationType.getTypeId());
            cancelNotification(notificationType);
            Rlog.i(LOG_TAG, "canceling notifications: " + notificationType.getTypeId());
        }
    }
@@ -307,17 +314,18 @@ public class CarrierServiceStateTracker extends Handler {
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning)
                .setColor(context.getResources().getColor(
                       com.android.internal.R.color.system_notification_accent_color));

        getNotificationManager(context).notify(notificationType.getTypeId(), builder.build());
        getNotificationManager(context).notify(notificationType.getNotificationTag(),
                notificationType.getNotificationId(), builder.build());
    }

    /**
     * Cancel notifications if a registration is pending or has been sent.
     **/
    public void cancelNotification(int notificationId) {
    public void cancelNotification(NotificationType notificationType) {
        Context context = mPhone.getContext();
        removeMessages(notificationId);
        getNotificationManager(context).cancel(notificationId);
        removeMessages(notificationType.getTypeId());
        getNotificationManager(context).cancel(
                notificationType.getNotificationTag(), notificationType.getNotificationId());
    }

    /**
@@ -352,6 +360,16 @@ public class CarrierServiceStateTracker extends Handler {
         **/
        int getTypeId();

        /**
         * returns notification id.
         **/
        int getNotificationId();

        /**
         * returns notification tag.
         **/
        String getNotificationTag();

        /**
         * returns the notification builder, for the notification to be displayed.
         **/
@@ -392,6 +410,14 @@ public class CarrierServiceStateTracker extends Handler {
            return mTypeId;
        }

        public int getNotificationId() {
            return mPhone.getSubId();
        }

        public String getNotificationTag() {
            return PREF_NETWORK_NOTIFICATION_TAG;
        }

        /**
         * Contains logic on sending notifications.
         */
@@ -415,9 +441,10 @@ public class CarrierServiceStateTracker extends Handler {
            notificationIntent.putExtra("expandable", true);
            PendingIntent settingsIntent = PendingIntent.getActivity(context, 0, notificationIntent,
                    PendingIntent.FLAG_ONE_SHOT);
            CharSequence title = context.getText(
            Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId());
            CharSequence title = res.getText(
                    com.android.internal.R.string.NetworkPreferenceSwitchTitle);
            CharSequence details = context.getText(
            CharSequence details = res.getText(
                    com.android.internal.R.string.NetworkPreferenceSwitchSummary);
            return new Notification.Builder(context)
                    .setContentTitle(title)
@@ -462,6 +489,14 @@ public class CarrierServiceStateTracker extends Handler {
            return mTypeId;
        }

        public int getNotificationId() {
            return mPhone.getSubId();
        }

        public String getNotificationTag() {
            return EMERGENCY_NOTIFICATION_TAG;
        }

        /**
         * Contains logic on sending notifications,
         */
@@ -481,9 +516,10 @@ public class CarrierServiceStateTracker extends Handler {
         */
        public Notification.Builder getNotificationBuilder() {
            Context context = mPhone.getContext();
            CharSequence title = context.getText(
            Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId());
            CharSequence title = res.getText(
                    com.android.internal.R.string.EmergencyCallWarningTitle);
            CharSequence details = context.getText(
            CharSequence details = res.getText(
                    com.android.internal.R.string.EmergencyCallWarningSummary);
            return new Notification.Builder(context)
                    .setContentTitle(title)
+17 −10
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
    private CarrierServiceStateTracker mCarrierSST;
    private CarrierServiceStateTrackerTestHandler mCarrierServiceStateTrackerTestHandler;

    private static final int SUB_ID = 1;

    NotificationManager mNotificationManager;
    PersistableBundle mBundle;

@@ -79,7 +81,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
        logd(LOG_TAG + "Setup!");
        super.setUp(getClass().getSimpleName());
        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mPhone.getSubId()).thenReturn(1);
        when(mPhone.getSubId()).thenReturn(SUB_ID);
        mCarrierServiceStateTrackerTestHandler =
                new CarrierServiceStateTrackerTestHandler(getClass().getSimpleName());
        mCarrierServiceStateTrackerTestHandler.start();
@@ -115,9 +117,10 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
        mSpyCarrierSST.handleMessage(notificationMsg);
        waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT);
        verify(mNotificationManager).cancel(
                CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK);
                CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID);
        verify(mNotificationManager).cancel(
                CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK);
                CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID);

    }

    @Test
@@ -135,9 +138,11 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
        mSpyCarrierSST.handleMessage(notificationMsg);
        waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT);
        verify(mNotificationManager).notify(
                eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class));
                eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG),
                eq(SUB_ID), isA(Notification.class));
        verify(mNotificationManager).notify(
                eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK), any());
                eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG),
                eq(SUB_ID), any());
    }

    @Test
@@ -169,7 +174,9 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
                Settings.Global.getUriFor(prefNetworkMode));
        waitForMs(500);
        verify(mNotificationManager, atLeast(1)).notify(
                eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class));
                eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG),
                eq(SUB_ID), isA(Notification.class));


        Settings.Global.putInt(mContext.getContentResolver(), prefNetworkMode,
                RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
@@ -177,7 +184,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
                Settings.Global.getUriFor(prefNetworkMode));
        waitForMs(500);
        verify(mNotificationManager, atLeast(1)).cancel(
                CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK);
                CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID);
    }

    @Test
@@ -207,13 +214,13 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest {
        mSpyCarrierSST.handleMessage(notificationMsg);
        waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT);
        verify(mNotificationManager).notify(
                eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK),
                isA(Notification.class));
                eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG),
                eq(SUB_ID), isA(Notification.class));

        doReturn(false).when(mPhone).isWifiCallingEnabled();
        mSpyCarrierSST.handleMessage(notificationMsg);
        waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT);
        verify(mNotificationManager, atLeast(2)).cancel(
                CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK);
                CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID);
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -1332,7 +1332,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals("test1", getNotificationTitle(postedNotification));

        sst.setNotification(ServiceStateTracker.PS_DISABLED);
        verify(nm).cancel(anyString(), anyInt());
        verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.PS_NOTIFICATION);
    }

    @Test
@@ -1360,7 +1360,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals("test2", getNotificationTitle(postedNotification));

        sst.setNotification(ServiceStateTracker.CS_DISABLED);
        verify(nm).cancel(anyString(), anyInt());
        verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION);
    }

    @Test
@@ -1387,7 +1387,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals("test3", getNotificationTitle(postedNotification));

        sst.setNotification(ServiceStateTracker.CS_DISABLED);
        verify(nm).cancel(anyString(), anyInt());
        verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION);
    }

    @Test
@@ -1415,7 +1415,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals("test4", getNotificationTitle(postedNotification));

        sst.setNotification(ServiceStateTracker.CS_DISABLED);
        verify(nm).cancel(anyString(), anyInt());
        verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION);
        sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED);
    }