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

Commit cd9e0d22 authored by Jason Monk's avatar Jason Monk
Browse files

SubscriptionController store SPN brdcst in carrier

Save the current PLMN/SPN in the carrier name of the SubscriptionInfo.

Bug: 18223317
Change-Id: I75ceba8ca8e1d9eb356292296b84a9cdac2e54e2
parent b7fa93b5
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.internal.telephony;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -156,6 +158,32 @@ 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_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) {
@@ -196,6 +224,8 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        mContext.registerReceiver(mReceiver,
                new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));

        if (DBG) logdl("[SubscriptionController] init by Context");
    }
@@ -211,6 +241,8 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        mContext.registerReceiver(mReceiver,
                new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));

        if (DBG) logdl("[SubscriptionController] init by Phone");
    }
@@ -726,6 +758,26 @@ public class SubscriptionController extends ISub.Stub {
        return 0;
    }

    /**
     * Set carrier text by simInfo index
     * @param text new carrier text
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     */
    private int setCarrierText(String text, int subId) {
        if (DBG) logd("[setCarrierText]+ text:" + text + " subId:" + subId);
        enforceSubscriptionPermission();

        ContentValues value = new ContentValues(1);
        value.put(SubscriptionManager.CARRIER_NAME, text);

        int result = mContext.getContentResolver().update(SubscriptionManager.CONTENT_URI, value,
                SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + Long.toString(subId), null);
        notifySubscriptionInfoChanged();

        return result;
    }

    /**
     * Set SIM color tint by simInfo index
     * @param tint the tint color of the SIM