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

Commit 67ea90e5 authored by Danny Baumann's avatar Danny Baumann
Browse files

Send out a new SPN_STRINGS_UPDATED broadcast if the sub ID changes.

The sub ID is part of the broadcast's extras, so the broadcast needs to
be refreshed if it changes.
Also move the PLMN/SPN localization from Keyguard to here so that the
localized name is written to the SIM DB.

Change-Id: I7e4ee04b7b9a0ddcaebad89a3c68661accd3f1c5
parent 35001445
Loading
Loading
Loading
Loading
+73 −2
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.internal.telephony;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.AsyncResult;
@@ -27,6 +29,7 @@ import android.os.Registrant;
import android.os.RegistrantList;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.telephony.CellInfo;
import android.telephony.ServiceState;
@@ -35,11 +38,11 @@ import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.NativeTextHelper;
import android.util.Pair;
import android.util.TimeUtils;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.content.Context;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -81,6 +84,13 @@ public abstract class ServiceStateTracker extends Handler {
    // so we don't want the reference to change.
    protected final CellInfo mCellInfo;

    // PLMN/SPN data we last broadcasted
    private int mCurSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private String mCurPlmn;
    private boolean mCurShowPlmn = false;
    private String mCurSpn;
    private boolean mCurShowSpn = false;

    protected SignalStrength mSignalStrength = new SignalStrength();

    // TODO - this should not be public, right now used externally GsmConnetion.
@@ -241,7 +251,6 @@ public abstract class ServiceStateTracker extends Handler {
            if (DBG) log("SubscriptionListener.onSubscriptionInfoChanged");
            // Set the network type, in case the radio does not restore it.
            int subId = mPhoneBase.getSubId();
            int previousSubId = mPhoneBase.getSubId();
            if (previousSubId != subId) {
                previousSubId = subId;
                if (SubscriptionManager.isValidSubscriptionId(subId)) {
@@ -270,10 +279,18 @@ public abstract class ServiceStateTracker extends Handler {
                        editor.commit();
                    }
                }
                updateSpnDisplay();
            }
        }
    };

    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateSpnDisplay();
        }
    };

    protected ServiceStateTracker(PhoneBase phoneBase, CommandsInterface ci, CellInfo cellInfo) {
        mPhoneBase = phoneBase;
        mCellInfo = cellInfo;
@@ -289,6 +306,9 @@ public abstract class ServiceStateTracker extends Handler {
        mSubscriptionManager
            .addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);

        mPhoneBase.getContext().registerReceiver(mReceiver,
                new IntentFilter(Intent.ACTION_LOCALE_CHANGED));

        mPhoneBase.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
            ServiceState.rilRadioTechnologyToString(ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN));
        mCi.registerForImsNetworkStateChanged(this, EVENT_IMS_STATE_CHANGED, null);
@@ -307,6 +327,7 @@ public abstract class ServiceStateTracker extends Handler {
        mCi.unregisterForCellInfoList(this);
        mSubscriptionManager
            .removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
        mPhoneBase.getContext().unregisterReceiver(mReceiver);
    }

    public boolean getDesiredPowerState() {
@@ -942,6 +963,11 @@ public abstract class ServiceStateTracker extends Handler {
        pw.println(" mDontPollSignalStrength=" + mDontPollSignalStrength);
        pw.println(" mPendingRadioPowerOffAfterDataOff=" + mPendingRadioPowerOffAfterDataOff);
        pw.println(" mPendingRadioPowerOffAfterDataOffTag=" + mPendingRadioPowerOffAfterDataOffTag);
        pw.println(" mCurSubId=" + mCurSubId);
        pw.println(" mCurSpn=" + mCurSpn);
        pw.println(" mCurShowSpn=" + mCurShowSpn);
        pw.println(" mCurPlmn=" + mCurPlmn);
        pw.println(" mCurShowPlmn=" + mCurShowPlmn);
        pw.flush();
    }

@@ -1101,4 +1127,49 @@ public abstract class ServiceStateTracker extends Handler {
    protected int getPhoneId() {
        return mPhoneBase.getPhoneId();
    }

    private String adaptCarrierNameToLocale(Context context, String name) {
        return NativeTextHelper.getLocalString(context, name,
                com.android.internal.R.array.origin_carrier_names,
                com.android.internal.R.array.locale_carrier_names);
    }

    protected void sendSpnStringsBroadcastIfNeeded(String plmn, boolean showPlmn,
            String spn, boolean showSpn) {
        final Context context = mPhoneBase.getContext();
        final int phoneId = mPhoneBase.getPhoneId();
        final int subId = mPhoneBase.getSubId();

        if (context.getResources().getBoolean(
                    com.android.internal.R.bool.config_monitor_locale_change)) {
            plmn = adaptCarrierNameToLocale(context, plmn);
            spn = adaptCarrierNameToLocale(context, spn);
        }

        if (subId != mCurSubId
                || showPlmn != mCurShowPlmn
                || showSpn != mCurShowSpn
                || !TextUtils.equals(spn, mCurSpn)
                || !TextUtils.equals(plmn, mCurPlmn)) {
            if (DBG) {
                log(String.format("sendSpnStringsBroadcast:" +
                        " showPlmn='%b' plmn='%s' showSpn='%b' spn='%s' for sub %d",
                        showPlmn, plmn, showSpn, spn, subId));
            }
            Intent intent = new Intent(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
            intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
            intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId, subId);
            mPhoneBase.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
        }

        mCurShowSpn = showSpn;
        mCurShowPlmn = showPlmn;
        mCurSpn = spn;
        mCurPlmn = plmn;
        mCurSubId = subId;
    }
}
+28 −24
Original line number Diff line number Diff line
@@ -171,20 +171,11 @@ public class SubscriptionController extends ISub.Stub {
            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);
                }
                setPlmnSpn(subId,
                        intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false),
                        intent.getStringExtra(TelephonyIntents.EXTRA_PLMN),
                        intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false),
                        intent.getStringExtra(TelephonyIntents.EXTRA_SPN));
            }
        }
    };
@@ -860,13 +851,11 @@ public class SubscriptionController extends ISub.Stub {
     * @param spn spn to be included in carrier text
     * @return true if carrier text is set, false otherwise
     */
    public boolean setPlmnSpn(int slotId, boolean showPlmn, String plmn,
    public boolean setPlmnSpn(int subId, boolean showPlmn, String plmn,
            boolean showSpn, String spn) {
        int[] subIds = getSubId(slotId);
        if (mContext.getPackageManager().resolveContentProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(), 0) == null ||
                subIds == null ||
                !SubscriptionManager.isValidSubscriptionId(subIds[0])) {
                !SubscriptionManager.isValidSubscriptionId(subId)) {
            // No place to store this info. Notify registrants of the change anyway as they
            // might retrieve the SPN/PLMN text from the SST sticky broadcast.
            // TODO: This can be removed once SubscriptionController is not running on devices
@@ -875,22 +864,37 @@ public class SubscriptionController extends ISub.Stub {
            notifySubscriptionInfoChanged();
            return false;
        }
        String carrierText = "";

        if (plmn != null && showPlmn && spn != null && showSpn) {
            if (mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_spn_display_control)) {
                logd("[setPlmnSpn] Do not display SPN string when PLMN and SPN both need to show"
                        + "and PLMN string is not null");
                showSpn = false;
            }
        }

        final 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)
                carrierText = new StringBuilder()
                        .append(plmn)
                        .append(separator)
                        .append(spn)
                        .toString();
            } else {
                carrierText = plmn;
            }
        } else if (showSpn) {
            carrierText = spn;
        } else {
            carrierText = "";
        }
        for (int i = 0; i < subIds.length; i++) {
            setCarrierText(carrierText, subIds[i]);
        }

        setCarrierText(carrierText, subId);
        return true;
    }

+1 −26
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.SubscriptionManager;
import android.telephony.cdma.CdmaCellLocation;
import android.text.TextUtils;
import android.util.EventLog;
@@ -130,9 +129,6 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
    private PowerManager.WakeLock mWakeLock;
    private static final String WAKELOCK_TAG = "ServiceStateTracker";

    /** Contains the name of the registered network in CDMA (either ONS or ERI text). */
    protected String mCurPlmn = null;

    protected String mMdn;
    protected int mHomeSystemId[] = null;
    protected int mHomeNetworkId[] = null;
@@ -603,27 +599,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                    "of service, set plmn='" + plmn + "'");
        }

        if (!TextUtils.equals(plmn, mCurPlmn)) {
            // Allow A blank plmn, "" to set showPlmn to true. Previously, we
            // would set showPlmn to true only if plmn was not empty, i.e. was not
            // null and not blank. But this would cause us to incorrectly display
            // "No Service". Now showPlmn is set to true for any non null string.
            boolean showPlmn = plmn != null;
            if (DBG) {
                log(String.format("updateSpnDisplay: changed sending intent" +
                            " showPlmn='%b' plmn='%s'", showPlmn, plmn));
            }
            Intent intent = new Intent(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, false);
            intent.putExtra(TelephonyIntents.EXTRA_SPN, "");
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
            intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
            mPhone.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
        }

        mCurPlmn = plmn;
        sendSpnStringsBroadcastIfNeeded(plmn, plmn != null, "", false);
    }

    /**
@@ -2110,7 +2086,6 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
        pw.println(" mSavedTime=" + mSavedTime);
        pw.println(" mSavedAtTime=" + mSavedAtTime);
        pw.println(" mWakeLock=" + mWakeLock);
        pw.println(" mCurPlmn=" + mCurPlmn);
        pw.println(" mMdn=" + mMdn);
        pw.println(" mHomeSystemId=" + mHomeSystemId);
        pw.println(" mHomeNetworkId=" + mHomeNetworkId);
+3 −37
Original line number Diff line number Diff line
@@ -48,8 +48,9 @@ import android.telephony.CellLocation;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.TimeUtils;
@@ -65,7 +66,6 @@ import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.RestrictedState;
import com.android.internal.telephony.ServiceStateTracker;
import android.telephony.SubscriptionManager;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.dataconnection.DcTrackerBase;
@@ -157,12 +157,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
    private PowerManager.WakeLock mWakeLock;
    private static final String WAKELOCK_TAG = "ServiceStateTracker";

    /** Keep track of SPN display rules, so we only broadcast intent if something changes. */
    private String mCurSpn = null;
    private String mCurPlmn = null;
    private boolean mCurShowPlmn = false;
    private boolean mCurShowSpn = false;

    /** Notification type. */
    static final int PS_ENABLED = 1001;            // Access Control blocks data service
    static final int PS_DISABLED = 1002;           // Access Control enables data service
@@ -643,31 +637,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
            showSpn = false;
        }

        // Update SPN_STRINGS_UPDATED_ACTION IFF any value changes
        if (showPlmn != mCurShowPlmn
                || showSpn != mCurShowSpn
                || !TextUtils.equals(spn, mCurSpn)
                || !TextUtils.equals(plmn, mCurPlmn)) {
            if (DBG) {
                log(String.format("updateSpnDisplay: changed" +
                        " sending intent rule=" + rule +
                        " showPlmn='%b' plmn='%s' showSpn='%b' spn='%s'",
                        showPlmn, plmn, showSpn, spn));
            }
            Intent intent = new Intent(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
            intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
            intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
            intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
            mPhone.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
        }

        mCurShowSpn = showSpn;
        mCurShowPlmn = showPlmn;
        mCurSpn = spn;
        mCurPlmn = plmn;
        sendSpnStringsBroadcastIfNeeded(plmn, showPlmn, spn, showSpn);
    }

    /**
@@ -2168,10 +2138,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
        pw.println(" mReportedGprsNoReg=" + mReportedGprsNoReg);
        pw.println(" mNotification=" + mNotification);
        pw.println(" mWakeLock=" + mWakeLock);
        pw.println(" mCurSpn=" + mCurSpn);
        pw.println(" mCurShowSpn=" + mCurShowSpn);
        pw.println(" mCurPlmn=" + mCurPlmn);
        pw.println(" mCurShowPlmn=" + mCurShowPlmn);
        pw.flush();
    }