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

Commit 360cb934 authored by Rambo Wang's avatar Rambo Wang
Browse files

CPT: build carrier privileges cache when AccessRules are loaded

This change builds carrier privileges cache immediately when
knows UiccAccessRule in the profile has been loaded.

Previously CarrierPrivilegesTracker builds the CP cache only
when received SIM_STATE_LOADED. This removes the dependency
from CPT to UiccProfile but brings a tiny delay for clients
like SUW which needs to get carrier packages in the first
place.

Bug: 227809916
Test: atest CarrierPrivilegesTrackerTest
Test: Telephony sanity(Activation, call, sms, data, switching)
Change-Id: Ia6bab2383f106e9033e7e77fc507b53580c4d25f
parent 3497e7d7
Loading
Loading
Loading
Loading
+36 −16
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ public class CarrierPrivilegesTracker extends Handler {
     */
    private static final int ACTION_CLEAR_UICC_RULES = 9;

    /**
     * Action to handle the case when UiccAccessRules has been loaded.
     */
    private static final int ACTION_UICC_ACCESS_RULES_LOADED = 10;

    private final Context mContext;
    private final Phone mPhone;
    private final PackageManager mPackageManager;
@@ -430,6 +435,9 @@ public class CarrierPrivilegesTracker extends Handler {
                handleClearUiccRules();
                break;
            }
            case ACTION_UICC_ACCESS_RULES_LOADED: {
                handleUiccAccessRulesLoaded();
            }
            default: {
                Rlog.e(TAG, "Received unknown msg type: " + msg.what);
                break;
@@ -502,16 +510,8 @@ public class CarrierPrivilegesTracker extends Handler {

        // Only include the UICC rules if the SIM is fully loaded
        if (simState == SIM_STATE_LOADED) {
            mClearUiccRulesUptimeMillis = CLEAR_UICC_RULE_NOT_SCHEDULED;
            removeMessages(ACTION_CLEAR_UICC_RULES);

            updatedUiccRules = getSimRules();

            mLocalLog.log("SIM fully loaded:"
                    + " slotId=" + slotId
                    + " simState=" + simState
                    + " updated SIM-loaded rules=" + updatedUiccRules);
            maybeUpdateRulesAndNotifyRegistrants(mUiccRules, updatedUiccRules);
            mLocalLog.log("SIM fully loaded, handleUiccAccessRulesLoaded.");
            handleUiccAccessRulesLoaded();
        } else {
            if (!mUiccRules.isEmpty()
                    && mClearUiccRulesUptimeMillis == CLEAR_UICC_RULE_NOT_SCHEDULED) {
@@ -519,8 +519,9 @@ public class CarrierPrivilegesTracker extends Handler {
                        SystemClock.uptimeMillis() + CLEAR_UICC_RULES_DELAY_MILLIS;
                sendMessageAtTime(obtainMessage(ACTION_CLEAR_UICC_RULES),
                        mClearUiccRulesUptimeMillis);
                mLocalLog.log("SIM is gone. Delay " + TimeUnit.MILLISECONDS.toSeconds(
                        CLEAR_UICC_RULES_DELAY_MILLIS) + " seconds to clear UICC rules.");
                mLocalLog.log("SIM is gone, simState=" + simState + ". Delay "
                        + TimeUnit.MILLISECONDS.toSeconds(CLEAR_UICC_RULES_DELAY_MILLIS)
                        + " seconds to clear UICC rules.");
            } else {
                mLocalLog.log(
                        "Ignore SIM gone event while UiccRules is empty or waiting to be emptied.");
@@ -528,6 +529,21 @@ public class CarrierPrivilegesTracker extends Handler {
        }
    }

    private void handleUiccAccessRulesLoaded() {
        mClearUiccRulesUptimeMillis = CLEAR_UICC_RULE_NOT_SCHEDULED;
        removeMessages(ACTION_CLEAR_UICC_RULES);

        List<UiccAccessRule> updatedUiccRules = getSimRules();
        mLocalLog.log("UiccAccessRules loaded:"
                + " updated SIM-loaded rules=" + updatedUiccRules);
        maybeUpdateRulesAndNotifyRegistrants(mUiccRules, updatedUiccRules);
    }

    /** Called when UiccAccessRules has been loaded */
    public void onUiccAccessRulesLoaded() {
        sendEmptyMessage(ACTION_UICC_ACCESS_RULES_LOADED);
    }

    private void handleClearUiccRules() {
        mClearUiccRulesUptimeMillis = CLEAR_UICC_RULE_NOT_SCHEDULED;
        removeMessages(ACTION_CLEAR_UICC_RULES);
@@ -574,9 +590,11 @@ public class CarrierPrivilegesTracker extends Handler {
        // installed for a user it wasn't installed in before, which means there will be an
        // additional UID.
        getUidsForPackage(pkg.packageName, /* invalidateCache= */ true);
        mLocalLog.log("Package added/replaced/changed:"
        if (VDBG) {
            Rlog.d(TAG, "Package added/replaced/changed:"
                    + " pkg=" + Rlog.pii(TAG, pkgName)
                    + " cert hashes=" + mInstalledPackageCerts.get(pkgName));
        }

        maybeUpdatePrivilegedPackagesAndNotifyRegistrants();
    }
@@ -603,7 +621,9 @@ public class CarrierPrivilegesTracker extends Handler {
            return;
        }

        mLocalLog.log("Package removed or disabled by user: pkg=" + Rlog.pii(TAG, pkgName));
        if (VDBG) {
            Rlog.d(TAG, "Package removed or disabled by user: pkg=" + Rlog.pii(TAG, pkgName));
        }

        maybeUpdatePrivilegedPackagesAndNotifyRegistrants();
    }
+8 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.util.ArraySet;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CarrierAppUtils;
import com.android.internal.telephony.CarrierPrivilegesTracker;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.IccCardConstants;
@@ -238,6 +239,13 @@ public class UiccProfile extends IccCard {

                case EVENT_CARRIER_PRIVILEGES_LOADED:
                    if (VDBG) log("handleMessage: EVENT_CARRIER_PRIVILEGES_LOADED");
                    Phone phone = PhoneFactory.getPhone(mPhoneId);
                    if (phone != null) {
                        CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
                        if (cpt != null) {
                            cpt.onUiccAccessRulesLoaded();
                        }
                    }
                    onCarrierPrivilegesLoadedMessage();
                    updateExternalState();
                    break;