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

Commit da07440f authored by Jeff Davidson's avatar Jeff Davidson
Browse files

Platform changes needed for CarrierAppUtils integration tests.

- Propagate fake carrier privilege rules set by
  TelephonyManager#setCarrierTestOverride to UiccProfile. This allows
  us to set rules for testing purposes that exercise the app hiding/
  unhiding logic in CarrierAppUtils.
- Move the location where CarrierAppUtils is invoked from
  SubscriptionInfoUpdater to UiccProfile once the rules have loaded.
  This is a more appropriate home either way as it is more closely
  tied to the precise place where rules have loaded, and since it
  coexists with other app logic that is tied to the platform rules.
  More importantly, moving it here ensures that CarrierAppUtils is
  invoked after a call to setCarrierTestOverride changes the
  privilege rules, which is needed to use this API for testing.

Bug: 150399810
Test: Verified on local build and w/ new carrier app integration test
Change-Id: Idfa5520f17c3e57712a666ffd67de9197ad4b1c7
parent f4c2aab6
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import android.telephony.SignalThresholdInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccAccessRule;
import android.telephony.UssdResponse;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
@@ -115,6 +116,7 @@ import com.android.telephony.Rlog;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
@@ -1889,7 +1891,23 @@ public class GsmCdmaPhone extends Phone {
    public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1,
            String gid2, String pnn, String spn, String carrierPrivilegeRules, String apn) {
        mCarrierResolver.setTestOverrideApn(apn);
        mCarrierResolver.setTestOverrideCarrierPriviledgeRule(carrierPrivilegeRules);
        UiccProfile uiccProfile = mUiccController.getUiccProfileForPhone(getPhoneId());
        if (uiccProfile != null) {
            List<UiccAccessRule> testRules;
            if (carrierPrivilegeRules == null) {
                testRules = null;
            } else if (carrierPrivilegeRules.isEmpty()) {
                testRules = Collections.emptyList();
            } else {
                UiccAccessRule accessRule = new UiccAccessRule(
                        IccUtils.hexStringToBytes(carrierPrivilegeRules), null, 0);
                testRules = Collections.singletonList(accessRule);
            }
            uiccProfile.setTestOverrideCarrierPrivilegeRules(testRules);
        } else {
            // TODO: Fix "privilege" typo throughout telephony.
            mCarrierResolver.setTestOverrideCarrierPriviledgeRule(carrierPrivilegeRules); // NOTYPO
        }
        IccRecords r = null;
        if (isPhoneTypeGsm()) {
            r = mIccRecords.get();
+0 −4
Original line number Diff line number Diff line
@@ -570,10 +570,6 @@ public class SubscriptionInfoUpdater extends Handler {
            }
        }

        // Update set of enabled carrier apps now that the privilege rules may have changed.
        CarrierAppUtils.disableCarrierAppsUntilPrivileged(sContext.getOpPackageName(),
                TelephonyManager.getDefault(), mCurrentlyActiveUserId, sContext);

        /**
         * The sim loading sequence will be
         *  1. ACTION_SUBINFO_CONTENT_CHANGE happens through updateSubscriptionInfoByIccId() above.
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telephony.UiccAccessRule;
import android.text.TextUtils;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandException;
import com.android.telephony.Rlog;

@@ -228,6 +229,14 @@ public class UiccCarrierPrivilegeRules extends Handler {
        openChannel(mAIDInUse);
    }

    @VisibleForTesting
    public UiccCarrierPrivilegeRules(List<UiccAccessRule> rules) {
        mAccessRules = rules;
        mState = new AtomicInteger(STATE_LOADED);
        mRules = "";
        mStatusMessage.log("Loaded from test rules.");
    }

    /**
     * Returns true if the carrier privilege rules have finished loading.
     */
+48 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.uicc;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.usage.UsageStatsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -48,6 +50,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CarrierAppUtils;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.IccCardConstants;
@@ -106,6 +109,7 @@ public class UiccProfile extends IccCard {
    private final UiccCard mUiccCard; //parent
    private CatService mCatService;
    private UiccCarrierPrivilegeRules mCarrierPrivilegeRules;
    private UiccCarrierPrivilegeRules mTestOverrideCarrierPrivilegeRules;
    private boolean mDisposed = false;

    private RegistrantList mCarrierPrivilegeRegistrants = new RegistrantList();
@@ -128,6 +132,7 @@ public class UiccProfile extends IccCard {
    private static final int EVENT_SIM_IO_DONE = 12;
    private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 13;
    private static final int EVENT_CARRIER_CONFIG_CHANGED = 14;
    private static final int EVENT_CARRIER_PRIVILEGES_TEST_OVERRIDE_SET = 15;
    // NOTE: any new EVENT_* values must be added to eventToString.

    private TelephonyManager mTelephonyManager;
@@ -245,6 +250,16 @@ public class UiccProfile extends IccCard {
                    ((Message) ar.userObj).sendToTarget();
                    break;

                case EVENT_CARRIER_PRIVILEGES_TEST_OVERRIDE_SET:
                    if (msg.obj == null) {
                        mTestOverrideCarrierPrivilegeRules = null;
                    } else {
                        mTestOverrideCarrierPrivilegeRules =
                                new UiccCarrierPrivilegeRules((List<UiccAccessRule>) msg.obj);
                    }
                    refresh();
                    break;

                default:
                    loge("handleMessage: Unhandled message with number: " + msg.what);
                    break;
@@ -1250,6 +1265,11 @@ public class UiccProfile extends IccCard {
    }

    private void onCarrierPrivilegesLoadedMessage() {
        // Update set of enabled carrier apps now that the privilege rules may have changed.
        ActivityManager am = mContext.getSystemService(ActivityManager.class);
        CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(),
                mTelephonyManager, am.getCurrentUser(), mContext);

        UsageStatsManager usm = (UsageStatsManager) mContext.getSystemService(
                Context.USAGE_STATS_SERVICE);
        if (usm != null) {
@@ -1317,11 +1337,12 @@ public class UiccProfile extends IccCard {
        if (certPackageMap.isEmpty()) {
            return Collections.emptySet();
        }
        if (mCarrierPrivilegeRules == null) {
        UiccCarrierPrivilegeRules rules = getCarrierPrivilegeRules();
        if (rules == null) {
            return Collections.emptySet();
        }
        Set<String> uninstalledCarrierPackages = new ArraySet<>();
        List<UiccAccessRule> accessRules = mCarrierPrivilegeRules.getAccessRules();
        List<UiccAccessRule> accessRules = rules.getAccessRules();
        for (UiccAccessRule accessRule : accessRules) {
            String certHexString = accessRule.getCertificateHexString().toUpperCase();
            String pkgName = certPackageMap.get(certHexString);
@@ -1661,6 +1682,9 @@ public class UiccProfile extends IccCard {
    /** Returns a reference to the current {@link UiccCarrierPrivilegeRules}. */
    private UiccCarrierPrivilegeRules getCarrierPrivilegeRules() {
        synchronized (mLock) {
            if (mTestOverrideCarrierPrivilegeRules != null) {
                return mTestOverrideCarrierPrivilegeRules;
            }
            return mCarrierPrivilegeRules;
        }
    }
@@ -1728,11 +1752,14 @@ public class UiccProfile extends IccCard {
            case EVENT_ICC_RECORD_EVENTS: return "ICC_RECORD_EVENTS";
            case EVENT_OPEN_LOGICAL_CHANNEL_DONE: return "OPEN_LOGICAL_CHANNEL_DONE";
            case EVENT_CLOSE_LOGICAL_CHANNEL_DONE: return "CLOSE_LOGICAL_CHANNEL_DONE";
            case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: return "TRANSMIT_APDU_LOGICAL_CHANNEL_DONE";
            case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
                return "TRANSMIT_APDU_LOGICAL_CHANNEL_DONE";
            case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: return "TRANSMIT_APDU_BASIC_CHANNEL_DONE";
            case EVENT_SIM_IO_DONE: return "SIM_IO_DONE";
            case EVENT_CARRIER_PRIVILEGES_LOADED: return "CARRIER_PRIVILEGES_LOADED";
            case EVENT_CARRIER_CONFIG_CHANGED: return "CARRIER_CONFIG_CHANGED";
            case EVENT_CARRIER_PRIVILEGES_TEST_OVERRIDE_SET:
                return "CARRIER_PRIVILEGES_TEST_OVERRIDE_SET";
            default: return "UNKNOWN(" + event + ")";
        }
    }
@@ -1759,6 +1786,19 @@ public class UiccProfile extends IccCard {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_PRIVILEGES_LOADED));
    }

    /**
     * Set a test set of carrier privilege rules which will override the actual rules on the SIM.
     *
     * <p>May be null, in which case the rules on the SIM will be used and any previous overrides
     * will be cleared.
     *
     * @see TelephonyManager#setCarrierTestOverride
     */
    public void setTestOverrideCarrierPrivilegeRules(@Nullable List<UiccAccessRule> rules) {
        mHandler.sendMessage(
                mHandler.obtainMessage(EVENT_CARRIER_PRIVILEGES_TEST_OVERRIDE_SET, rules));
    }

    /**
     * Dump
     */
@@ -1812,6 +1852,11 @@ public class UiccProfile extends IccCard {
            pw.println(" mCarrierPrivilegeRules: " + mCarrierPrivilegeRules);
            mCarrierPrivilegeRules.dump(fd, pw, args);
        }
        if (mTestOverrideCarrierPrivilegeRules != null) {
            pw.println(" mTestOverrideCarrierPrivilegeRules: "
                    + mTestOverrideCarrierPrivilegeRules);
            mTestOverrideCarrierPrivilegeRules.dump(fd, pw, args);
        }
        pw.println(" mCarrierPrivilegeRegistrants: size=" + mCarrierPrivilegeRegistrants.size());
        for (int i = 0; i < mCarrierPrivilegeRegistrants.size(); i++) {
            pw.println("  mCarrierPrivilegeRegistrants[" + i + "]="
+2 −0
Original line number Diff line number Diff line
@@ -290,6 +290,8 @@ public class ContextFixture implements TestFixture<Context> {
                return Context.POWER_WHITELIST_MANAGER;
            } else if (serviceClass == SystemConfigManager.class) {
                return Context.SYSTEM_CONFIG_SERVICE;
            } else if (serviceClass == ActivityManager.class) {
                return Context.ACTIVITY_SERVICE;
            }
            return super.getSystemServiceName(serviceClass);
        }