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

Commit 9691d071 authored by Jordan Liu's avatar Jordan Liu
Browse files

Post notifications per subid

Since SST exists per subscription, we should post notifications per
subId. We do this here by posting/canceling notifications with the
optional "tag" argument, so that the unique combination of
tag+notification-id itentifies each notification.

Bug: 69928579
Test: manually verified that mPrevSubId is correct when
cancelAllNotifications is called on sim removal
Change-Id: Ib8836ee75715e7f274a3c365e88c30d8c7c62514
parent 71b259e1
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ public class ServiceStateTracker extends Handler {
    private boolean mCurShowPlmn = false;
    private boolean mCurShowSpn = false;
    private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private int mPrevSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    private boolean mImsRegistered = false;

@@ -274,6 +275,7 @@ public class ServiceStateTracker extends Handler {
            if (DBG) log("SubscriptionListener.onSubscriptionInfoChanged");
            // Set the network type, in case the radio does not restore it.
            int subId = mPhone.getSubId();
            ServiceStateTracker.this.mPrevSubId = mPreviousSubId.get();
            if (mPreviousSubId.getAndSet(subId) != subId) {
                if (SubscriptionManager.isValidSubscriptionId(subId)) {
                    Context context = mPhone.getContext();
@@ -1059,7 +1061,9 @@ public class ServiceStateTracker extends Handler {
            case EVENT_SIM_READY:
                // Reset the mPreviousSubId so we treat a SIM power bounce
                // as a first boot.  See b/19194287
                mOnSubscriptionsChangedListener.mPreviousSubId.set(-1);
                mOnSubscriptionsChangedListener.mPreviousSubId.set(
                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                mPrevSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                mIsSimReady = true;
                pollState();
                // Signal strength polling stops when radio is off
@@ -3442,17 +3446,19 @@ public class ServiceStateTracker extends Handler {
    }

    /**
     * Cancels all notifications posted to NotificationManager. These notifications for restricted
     * state and rejection cause for cs registration are no longer valid after the SIM has been
     * removed.
     * Cancels all notifications posted to NotificationManager for this subId. These notifications
     * for restricted state and rejection cause for cs registration are no longer valid after the
     * SIM has been removed.
     */
    private void cancelAllNotifications() {
        if (DBG) log("setNotification: cancelAllNotifications");
        if (DBG) log("cancelAllNotifications: mPrevSubId=" + mPrevSubId);
        NotificationManager notificationManager = (NotificationManager)
                mPhone.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(PS_NOTIFICATION);
        notificationManager.cancel(CS_NOTIFICATION);
        notificationManager.cancel(CS_REJECT_CAUSE_NOTIFICATION);
        if (SubscriptionManager.isValidSubscriptionId(mPrevSubId)) {
            notificationManager.cancel(Integer.toString(mPrevSubId), PS_NOTIFICATION);
            notificationManager.cancel(Integer.toString(mPrevSubId), CS_NOTIFICATION);
            notificationManager.cancel(Integer.toString(mPrevSubId), CS_REJECT_CAUSE_NOTIFICATION);
        }
    }

    /**
@@ -3465,6 +3471,12 @@ public class ServiceStateTracker extends Handler {
    public void setNotification(int notifyType) {
        if (DBG) log("setNotification: create notification " + notifyType);

        if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
            // notifications are posted per-sub-id, so return if current sub-id is invalid
            loge("cannot setNotification on invalid subid mSubId=" + mSubId);
            return;
        }

        // Needed because sprout RIL sends these when they shouldn't?
        boolean isSetNotification = mPhone.getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_user_notification_of_restrictied_mobile_access);
@@ -3542,7 +3554,7 @@ public class ServiceStateTracker extends Handler {

        if (DBG) {
            log("setNotification, create notification, notifyType: " + notifyType
                    + ", title: " + title + ", details: " + details);
                    + ", title: " + title + ", details: " + details + ", subId: " + mSubId);
        }

        mNotification = new Notification.Builder(context)
@@ -3563,10 +3575,10 @@ public class ServiceStateTracker extends Handler {

        if (notifyType == PS_DISABLED || notifyType == CS_DISABLED) {
            // cancel previous post notification
            notificationManager.cancel(notificationId);
            notificationManager.cancel(Integer.toString(mSubId), notificationId);
        } else {
            // update restricted state notification
            notificationManager.notify(notificationId, mNotification);
            // update restricted state notification for this subId
            notificationManager.notify(Integer.toString(mSubId), notificationId, mNotification);
        }
    }