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

Commit 22f13141 authored by Chen Xu's avatar Chen Xu Committed by Android (Google) Code Review
Browse files

Merge "update carrierIdProvider with current active subs"

parents a6abfa91 a0a8091a
Loading
Loading
Loading
Loading
+25 −14
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.internal.telephony;

import static android.provider.Telephony.CarrierIdentification;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -94,10 +95,11 @@ public class CarrierIdentifier extends Handler {
    private final ContentObserver mContentObserver = new ContentObserver(this) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            logd("onChange URI: " + uri);
            if (CONTENT_URL_PREFER_APN.equals(uri.getLastPathSegment())) {
                logd("onChange URI: " + uri);
                sendEmptyMessage(PREFER_APN_UPDATE_EVENT);
            } else {
            } else if (CarrierIdentification.All.CONTENT_URI.equals(uri)) {
                logd("onChange URI: " + uri);
                sendEmptyMessage(CARRIER_ID_DB_UPDATE_EVENT);
            }
        }
@@ -152,7 +154,7 @@ public class CarrierIdentifier extends Handler {
        mContext.getContentResolver().registerContentObserver(CONTENT_URL_PREFER_APN, false,
                mContentObserver);
        mContext.getContentResolver().registerContentObserver(
                Telephony.CarrierIdentification.CONTENT_URI, false, mContentObserver);
                Telephony.CarrierIdentification.All.CONTENT_URI, false, mContentObserver);
        SubscriptionManager.from(mContext).addOnSubscriptionsChangedListener(
                mOnSubscriptionsChangedListener);
        PreferenceManager.getDefaultSharedPreferences(mContext)
@@ -244,9 +246,10 @@ public class CarrierIdentifier extends Handler {
    private void loadCarrierMatchingRulesOnMccMnc() {
        try {
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            Cursor cursor = mContext.getContentResolver().query(CarrierIdentification.CONTENT_URI,
            Cursor cursor = mContext.getContentResolver().query(
                    CarrierIdentification.All.CONTENT_URI,
                    /* projection */ null,
                    /* selection */ CarrierIdentification.MCCMNC + "=?",
                    /* selection */ CarrierIdentification.All.MCCMNC + "=?",
                    /* selectionArgs */ new String[]{mccmnc}, null);
            try {
                if (cursor != null) {
@@ -318,21 +321,29 @@ public class CarrierIdentifier extends Handler {
            intent.putExtra(TelephonyManager.EXTRA_CARRIER_NAME, mCarrierName);
            intent.putExtra(TelephonyManager.EXTRA_SUBSCRIPTION_ID, mPhone.getSubId());
            mContext.sendBroadcast(intent);

            // update current subscriptions
            ContentValues cv = new ContentValues();
            cv.put(CarrierIdentification.CID, mCarrierId);
            cv.put(CarrierIdentification.NAME, mCarrierName);
            mContext.getContentResolver().update(
                    Uri.withAppendedPath(CarrierIdentification.CONTENT_URI,
                    Integer.toString(mPhone.getSubId())), cv, null, null);
        }
    }

    private CarrierMatchingRule makeCarrierMatchingRule(Cursor cursor) {
        return new CarrierMatchingRule(
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.MCCMNC)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.MCCMNC)),
                cursor.getString(cursor.getColumnIndexOrThrow(
                        CarrierIdentification.IMSI_PREFIX_XPATTERN)),
                        CarrierIdentification.All.IMSI_PREFIX_XPATTERN)),
                cursor.getString(cursor.getColumnIndexOrThrow(
                        CarrierIdentification.ICCID_PREFIX)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.GID1)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.GID2)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.PLMN)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.SPN)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.APN)),
                        CarrierIdentification.All.ICCID_PREFIX)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.GID1)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.GID2)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.PLMN)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.SPN)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.All.APN)),
                cursor.getInt(cursor.getColumnIndexOrThrow(CarrierIdentification.CID)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.NAME)));
    }
@@ -571,7 +582,7 @@ public class CarrierIdentifier extends Handler {

    private int getCarrierListVersion() {
        final Cursor cursor = mContext.getContentResolver().query(
                Uri.withAppendedPath(Telephony.CarrierIdentification.CONTENT_URI,
                Uri.withAppendedPath(Telephony.CarrierIdentification.All.CONTENT_URI,
                "get_version"), null, null, null);
        cursor.moveToFirst();
        return cursor.getInt(0);
+15 −12
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.telephony;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
@@ -84,8 +83,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
        logd("CarrierIdentifierTest +Setup!");
        super.setUp(getClass().getSimpleName());
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                CarrierIdentification.CONTENT_URI.getAuthority(),
                new CarrierIdContentProvider());
                CarrierIdentification.AUTHORITY, new CarrierIdContentProvider());
        // start handler thread
        mCarrierIdentifierHandler = new CarrierIdentifierHandler(getClass().getSimpleName());
        mCarrierIdentifierHandler.start();
@@ -204,18 +202,18 @@ public class CarrierIdentifierTest extends TelephonyTest {
            logd("   selectionArgs = " + Arrays.toString(selectionArgs));
            logd("   sortOrder = " + sortOrder);

            if (CarrierIdentification.CONTENT_URI.getAuthority().equals(
            if (CarrierIdentification.All.CONTENT_URI.getAuthority().equals(
                    uri.getAuthority())) {
                MatrixCursor mc = new MatrixCursor(
                        new String[]{CarrierIdentification._ID,
                                CarrierIdentification.MCCMNC,
                                CarrierIdentification.GID1,
                                CarrierIdentification.GID2,
                                CarrierIdentification.PLMN,
                                CarrierIdentification.IMSI_PREFIX_XPATTERN,
                                CarrierIdentification.ICCID_PREFIX,
                                CarrierIdentification.SPN,
                                CarrierIdentification.APN,
                                CarrierIdentification.All.MCCMNC,
                                CarrierIdentification.All.GID1,
                                CarrierIdentification.All.GID2,
                                CarrierIdentification.All.PLMN,
                                CarrierIdentification.All.IMSI_PREFIX_XPATTERN,
                                CarrierIdentification.All.ICCID_PREFIX,
                                CarrierIdentification.All.SPN,
                                CarrierIdentification.All.APN,
                                CarrierIdentification.NAME,
                                CarrierIdentification.CID});

@@ -282,5 +280,10 @@ public class CarrierIdentifierTest extends TelephonyTest {
            }
            return null;
        }
        @Override
        public int update(android.net.Uri uri, android.content.ContentValues values,
                java.lang.String selection, java.lang.String[] selectionArgs) {
            return 0;
        }
    }
}