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

Commit 0192d7f3 authored by Jason Monk's avatar Jason Monk
Browse files

Have ServiceStateTrackers update Plmn/Spn directly

It seems that somehow the info from the ServiceState trackers is
getting out of sync with the Subscription database.  To avoid this
update the info directly rather than going through a sticky broadcast.

Bug: 18752574
Change-Id: I66a3cb30df6478b7313230252ff2560946297d47
parent cf53a4ab
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ public abstract class ServiceStateTracker extends Handler {
    private boolean mImsRegistered = false;

    protected SubscriptionManager mSubscriptionManager;
    protected SubscriptionController mSubscriptionController;
    protected final OnSubscriptionsChangedListener mOnSubscriptionsChangedListener =
            new OnSubscriptionsChangedListener() {
        private int previousSubId = -1; // < 0 is invalid subId
@@ -290,6 +291,7 @@ public abstract class ServiceStateTracker extends Handler {
        mCi.setOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
        mCi.registerForCellInfoList(this, EVENT_UNSOL_CELL_INFO_LIST, null);

        mSubscriptionController = SubscriptionController.getInstance();
        mSubscriptionManager = SubscriptionManager.from(phoneBase.getContext());
        mSubscriptionManager
            .registerOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
+28 −43
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.telephony;

import android.content.BroadcastReceiver;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -159,33 +158,6 @@ public class SubscriptionController extends ISub.Stub {
        }
    };

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (DBG) logd("onReceive " + intent);
            // TODO: Have GsmServiceStateTracker insert this data directly and deprecate
            // this broadcast.
            int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);
            if (intent.getAction().equals(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION)) {
                if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
                    String carrierText = intent.getStringExtra(TelephonyIntents.EXTRA_PLMN);
                    if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
                        // Need to show both plmn and spn.
                        String separator = mContext.getString(
                                com.android.internal.R.string.kg_text_message_separator).toString();
                        carrierText = new StringBuilder().append(carrierText).append(separator)
                                .append(intent.getStringExtra(TelephonyIntents.EXTRA_SPN))
                                .toString();
                    }
                    setCarrierText(carrierText, subId);
                } else if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
                    setCarrierText(intent.getStringExtra(TelephonyIntents.EXTRA_PLMN), subId);
                }
            }
        }
    };

    public static SubscriptionController init(Phone phone) {
        synchronized (SubscriptionController.class) {
            if (sInstance == null) {
@@ -225,7 +197,6 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        registerReceiverIfNeeded();

        if (DBG) logdl("[SubscriptionController] init by Context");
    }
@@ -241,24 +212,10 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        registerReceiverIfNeeded();

        if (DBG) logdl("[SubscriptionController] init by Phone");
    }

    private void registerReceiverIfNeeded() {
        // We only need to register the broadcast receiver if the URI
        // where we are going to store the data is valid.
        // TODO: This can be removed once the SubscriptionController is not running
        // on devices that don't need it, such as TVs.
        if (mContext.getPackageManager().resolveContentProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(), 0) != null) {
            if (DBG) logd("registering SPN updated receiver");
            mContext.registerReceiver(mReceiver,
                    new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
        }
    }

    /**
     * Make sure the caller has the READ_PHONE_STATE permission.
     *
@@ -788,6 +745,34 @@ public class SubscriptionController extends ISub.Stub {
        return 0;
    }

    public void setPlmnSpn(int slotId, boolean showPlmn, String plmn,
            boolean showSpn, String spn) {
        if (mContext.getPackageManager().resolveContentProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(), 0) == null) {
            // No place to store this info, we are done.
            // TODO: This can be removed once SubscriptionController is not running on devices
            // that don't need it, such as TVs.
            return;
        }
        String carrierText = "";
        if (showPlmn) {
            carrierText = plmn;
            if (showSpn) {
                // Need to show both plmn and spn.
                String separator = mContext.getString(
                        com.android.internal.R.string.kg_text_message_separator).toString();
                carrierText = new StringBuilder().append(carrierText).append(separator).append(spn)
                        .toString();
            }
        } else if (showSpn) {
            carrierText = spn;
        }
        int[] subIds = getSubId(slotId);
        for (int i = 0; i < subIds.length; i++) {
            setCarrierText(carrierText, subIds[i]);
        }
    }

    /**
     * Set carrier text by simInfo index
     * @param text new carrier text
+3 −0
Original line number Diff line number Diff line
@@ -588,6 +588,9 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
            intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
            mPhone.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);

            mSubscriptionController.setPlmnSpn(mPhone.getPhoneId(),
                    showPlmn, plmn, false, "");
        }

        mCurPlmn = plmn;
+3 −0
Original line number Diff line number Diff line
@@ -672,6 +672,9 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
            intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
            mPhone.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);

            mSubscriptionController.setPlmnSpn(mPhone.getPhoneId(),
                    showPlmn, plmn, showSpn, spn);
        }

        mCurShowSpn = showSpn;