Loading src/java/com/android/internal/telephony/CarrierPrivilegesTracker.java +3 −58 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import static android.telephony.TelephonyManager.SIM_STATE_UNKNOWN; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -49,7 +48,6 @@ import android.os.Registrant; import android.os.RegistrantList; import android.os.UserHandle; import android.os.UserManager; import android.telephony.Annotation.CarrierPrivilegeStatus; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; Loading @@ -65,7 +63,6 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccPort; import com.android.internal.telephony.uicc.UiccProfile; import com.android.internal.util.ArrayUtils; import com.android.telephony.Rlog; import java.io.FileDescriptor; Loading Loading @@ -517,13 +514,10 @@ public class CarrierPrivilegesTracker extends Handler { } private void refreshInstalledPackageCache() { // Include DISABLED_UNTIL_USED components. This facilitates cases where a carrier app // is disabled by default, and some other component wants to enable it when it has // gained carrier privileges (as an indication that a matching SIM has been inserted). int flags = PackageManager.GET_SIGNING_CERTIFICATES PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS; | PackageManager.GET_SIGNING_CERTIFICATES; List<PackageInfo> installedPackages = mPackageManager.getInstalledPackagesAsUser( flags, UserHandle.SYSTEM.getIdentifier()); Loading Loading @@ -587,11 +581,6 @@ public class CarrierPrivilegesTracker extends Handler { } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } // 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); } private PrivilegedPackageInfo getCurrentPrivilegedPackagesForAllUsers() { Loading Loading @@ -741,51 +730,7 @@ public class CarrierPrivilegesTracker extends Handler { // best effort. refreshInstalledPackageCache(); } maybeUpdatePrivilegedPackagesAndNotifyRegistrants(); } /** Backing of {@link TelephonyManager#checkCarrierPrivilegesForPackage}. */ public @CarrierPrivilegeStatus int getCarrierPrivilegeStatusForPackage(String packageName) { // TODO(b/205736323) consider if/how we want to account for the RULES_NOT_LOADED and // ERROR_LOADING_RULES constants. Technically those will never be returned today since those // results are only from the SIM rules, but the CC rules' result (which never has these // errors) always supersede them unless something goes super wrong when getting CC. mPrivilegedPackageInfoLock.readLock().lock(); try { return mPrivilegedPackageInfo.mPackageNames.contains(packageName) ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } } /** Backing of {@link TelephonyManager#getPackagesWithCarrierPrivileges}. */ public Set<String> getPackagesWithCarrierPrivileges() { mPrivilegedPackageInfoLock.readLock().lock(); try { return Collections.unmodifiableSet(mPrivilegedPackageInfo.mPackageNames); } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } } /** * Backing of {@link TelephonyManager#hasCarrierPrivileges} and {@link * TelephonyManager#getCarrierPrivilegeStatus(int)}. */ public @CarrierPrivilegeStatus int getCarrierPrivilegeStatusForUid(int uid) { // TODO(b/205736323) consider if/how we want to account for the RULES_NOT_LOADED and // ERROR_LOADING_RULES constants. Technically those will never be returned today since those // results are only from the SIM rules, but the CC rules' result (which never has these // errors) always supersede them unless something goes super wrong when getting CC. mPrivilegedPackageInfoLock.readLock().lock(); try { return ArrayUtils.contains(mPrivilegedPackageInfo.mUids, uid) ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } maybeUpdatePrivilegedPackagesAndNotifyRegistrants(); } } src/java/com/android/internal/telephony/uicc/UiccPort.java +6 −18 Original line number Diff line number Diff line Loading @@ -378,11 +378,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(Signature, String)} * instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatus(Signature, String)} instead. */ @Deprecated public int getCarrierPrivilegeStatus(Signature signature, String packageName) { Loading @@ -395,11 +392,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(PackageManager, String)} * instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatus(PackageManager, String)} instead. */ @Deprecated public int getCarrierPrivilegeStatus(PackageManager packageManager, String packageName) { Loading @@ -412,9 +406,6 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(PackageInfo)} instead. */ @Deprecated Loading @@ -428,11 +419,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatusForCurrentTransaction}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link * UiccProfile#getCarrierPrivilegeStatusForCurrentTransaction(PackageManager)} instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatusForCurrentTransaction(PackageManager)} instead. */ @Deprecated public int getCarrierPrivilegeStatusForCurrentTransaction(PackageManager packageManager) { Loading src/java/com/android/internal/telephony/uicc/UiccProfile.java +0 −1 Original line number Diff line number Diff line Loading @@ -1334,7 +1334,6 @@ public class UiccProfile extends IccCard { } private void onCarrierPrivilegesLoadedMessage() { // TODO(b/211796398): clean up logic below once all carrier privilege check migration done // Update set of enabled carrier apps now that the privilege rules may have changed. ActivityManager am = mContext.getSystemService(ActivityManager.class); CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(), Loading tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java +3 −46 Original line number Diff line number Diff line Loading @@ -105,9 +105,9 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { private static final int[] PRIVILEGED_UIDS = {UID_1, UID_2}; private static final int PM_FLAGS = PackageManager.GET_SIGNING_CERTIFICATES PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS; | PackageManager.GET_SIGNING_CERTIFICATES; @Mock private Signature mSignature; Loading Loading @@ -257,21 +257,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { } } private void verifyCurrentState(Set<String> expectedPackageNames, int[] expectedUids) { assertEquals( expectedPackageNames, mCarrierPrivilegesTracker.getPackagesWithCarrierPrivileges()); for (String packageName : expectedPackageNames) { assertEquals( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS, mCarrierPrivilegesTracker.getCarrierPrivilegeStatusForPackage(packageName)); } for (int uid : expectedUids) { assertEquals( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS, mCarrierPrivilegesTracker.getCarrierPrivilegeStatusForUid(uid)); } } private void verifyRegistrantUpdates(@Nullable int[] expectedUids, int expectedUidUpdates) { assertArrayEquals(expectedUids, mHandler.privilegedUids); assertEquals(expectedUidUpdates, mHandler.numUidUpdates); Loading Loading @@ -306,9 +291,8 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mHandler, REGISTRANT_WHAT, null); mTestableLooper.processAllMessages(); // No updates triggered, but the registrant gets an empty update. verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); // No updates triggered, so TelephonyRegistry doesn't get any updates. verifyCarrierPrivilegesChangedUpdates(List.of()); } Loading @@ -323,7 +307,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mHandler, REGISTRANT_WHAT, null); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -333,7 +316,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mCarrierPrivilegesTracker.unregisterCarrierPrivilegesListener(mHandler); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of()); Loading @@ -341,7 +323,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(INVALID_SUBSCRIPTION_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of(new Pair<>(Set.of(), new int[0]))); } Loading @@ -359,7 +340,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -373,7 +353,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID_INCORRECT); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -387,7 +366,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(INVALID_SUBSCRIPTION_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -406,7 +384,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of(new Pair<>(Set.of(), new int[0]))); } Loading @@ -426,7 +403,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -439,7 +415,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -458,7 +433,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -477,7 +451,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimApplicationStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -493,7 +466,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -511,7 +483,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID_INCORRECT, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -525,7 +496,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_NOT_READY); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -548,7 +518,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -562,7 +531,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -579,7 +547,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -599,7 +566,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), PRIVILEGED_UIDS))); Loading @@ -620,7 +586,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REPLACED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), PRIVILEGED_UIDS))); Loading @@ -645,7 +610,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -669,7 +633,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -688,7 +651,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REMOVED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -703,7 +665,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REMOVED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(null /* expectedUidUpdates */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of()); } Loading @@ -718,7 +679,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect no package will have privilege at last verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -730,7 +690,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect all privileges from Carrier Config come back verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -746,7 +705,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect only PACKAGE_3 will have privilege at last verifyCurrentState(Set.of(PACKAGE_3), new int[]{UID_3}); verifyRegistrantUpdates(new int[]{UID_3}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -759,7 +717,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect all privileges from UICC come back verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading Loading
src/java/com/android/internal/telephony/CarrierPrivilegesTracker.java +3 −58 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import static android.telephony.TelephonyManager.SIM_STATE_UNKNOWN; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -49,7 +48,6 @@ import android.os.Registrant; import android.os.RegistrantList; import android.os.UserHandle; import android.os.UserManager; import android.telephony.Annotation.CarrierPrivilegeStatus; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; Loading @@ -65,7 +63,6 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccPort; import com.android.internal.telephony.uicc.UiccProfile; import com.android.internal.util.ArrayUtils; import com.android.telephony.Rlog; import java.io.FileDescriptor; Loading Loading @@ -517,13 +514,10 @@ public class CarrierPrivilegesTracker extends Handler { } private void refreshInstalledPackageCache() { // Include DISABLED_UNTIL_USED components. This facilitates cases where a carrier app // is disabled by default, and some other component wants to enable it when it has // gained carrier privileges (as an indication that a matching SIM has been inserted). int flags = PackageManager.GET_SIGNING_CERTIFICATES PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS; | PackageManager.GET_SIGNING_CERTIFICATES; List<PackageInfo> installedPackages = mPackageManager.getInstalledPackagesAsUser( flags, UserHandle.SYSTEM.getIdentifier()); Loading Loading @@ -587,11 +581,6 @@ public class CarrierPrivilegesTracker extends Handler { } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } // 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); } private PrivilegedPackageInfo getCurrentPrivilegedPackagesForAllUsers() { Loading Loading @@ -741,51 +730,7 @@ public class CarrierPrivilegesTracker extends Handler { // best effort. refreshInstalledPackageCache(); } maybeUpdatePrivilegedPackagesAndNotifyRegistrants(); } /** Backing of {@link TelephonyManager#checkCarrierPrivilegesForPackage}. */ public @CarrierPrivilegeStatus int getCarrierPrivilegeStatusForPackage(String packageName) { // TODO(b/205736323) consider if/how we want to account for the RULES_NOT_LOADED and // ERROR_LOADING_RULES constants. Technically those will never be returned today since those // results are only from the SIM rules, but the CC rules' result (which never has these // errors) always supersede them unless something goes super wrong when getting CC. mPrivilegedPackageInfoLock.readLock().lock(); try { return mPrivilegedPackageInfo.mPackageNames.contains(packageName) ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } } /** Backing of {@link TelephonyManager#getPackagesWithCarrierPrivileges}. */ public Set<String> getPackagesWithCarrierPrivileges() { mPrivilegedPackageInfoLock.readLock().lock(); try { return Collections.unmodifiableSet(mPrivilegedPackageInfo.mPackageNames); } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } } /** * Backing of {@link TelephonyManager#hasCarrierPrivileges} and {@link * TelephonyManager#getCarrierPrivilegeStatus(int)}. */ public @CarrierPrivilegeStatus int getCarrierPrivilegeStatusForUid(int uid) { // TODO(b/205736323) consider if/how we want to account for the RULES_NOT_LOADED and // ERROR_LOADING_RULES constants. Technically those will never be returned today since those // results are only from the SIM rules, but the CC rules' result (which never has these // errors) always supersede them unless something goes super wrong when getting CC. mPrivilegedPackageInfoLock.readLock().lock(); try { return ArrayUtils.contains(mPrivilegedPackageInfo.mUids, uid) ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; } finally { mPrivilegedPackageInfoLock.readLock().unlock(); } maybeUpdatePrivilegedPackagesAndNotifyRegistrants(); } }
src/java/com/android/internal/telephony/uicc/UiccPort.java +6 −18 Original line number Diff line number Diff line Loading @@ -378,11 +378,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(Signature, String)} * instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatus(Signature, String)} instead. */ @Deprecated public int getCarrierPrivilegeStatus(Signature signature, String packageName) { Loading @@ -395,11 +392,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(PackageManager, String)} * instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatus(PackageManager, String)} instead. */ @Deprecated public int getCarrierPrivilegeStatus(PackageManager packageManager, String packageName) { Loading @@ -412,9 +406,6 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatus}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link UiccProfile#getCarrierPrivilegeStatus(PackageInfo)} instead. */ @Deprecated Loading @@ -428,11 +419,8 @@ public class UiccPort { /** * Exposes {@link UiccCarrierPrivilegeRules#getCarrierPrivilegeStatusForCurrentTransaction}. * * <p>TODO(b/205736323) remove this and downstream once fully moved to CarrierPrivilegesTracker * * @deprecated Please use {@link * UiccProfile#getCarrierPrivilegeStatusForCurrentTransaction(PackageManager)} instead. * @deprecated Please use * {@link UiccProfile#getCarrierPrivilegeStatusForCurrentTransaction(PackageManager)} instead. */ @Deprecated public int getCarrierPrivilegeStatusForCurrentTransaction(PackageManager packageManager) { Loading
src/java/com/android/internal/telephony/uicc/UiccProfile.java +0 −1 Original line number Diff line number Diff line Loading @@ -1334,7 +1334,6 @@ public class UiccProfile extends IccCard { } private void onCarrierPrivilegesLoadedMessage() { // TODO(b/211796398): clean up logic below once all carrier privilege check migration done // Update set of enabled carrier apps now that the privilege rules may have changed. ActivityManager am = mContext.getSystemService(ActivityManager.class); CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(), Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierPrivilegesTrackerTest.java +3 −46 Original line number Diff line number Diff line Loading @@ -105,9 +105,9 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { private static final int[] PRIVILEGED_UIDS = {UID_1, UID_2}; private static final int PM_FLAGS = PackageManager.GET_SIGNING_CERTIFICATES PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS; | PackageManager.GET_SIGNING_CERTIFICATES; @Mock private Signature mSignature; Loading Loading @@ -257,21 +257,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { } } private void verifyCurrentState(Set<String> expectedPackageNames, int[] expectedUids) { assertEquals( expectedPackageNames, mCarrierPrivilegesTracker.getPackagesWithCarrierPrivileges()); for (String packageName : expectedPackageNames) { assertEquals( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS, mCarrierPrivilegesTracker.getCarrierPrivilegeStatusForPackage(packageName)); } for (int uid : expectedUids) { assertEquals( TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS, mCarrierPrivilegesTracker.getCarrierPrivilegeStatusForUid(uid)); } } private void verifyRegistrantUpdates(@Nullable int[] expectedUids, int expectedUidUpdates) { assertArrayEquals(expectedUids, mHandler.privilegedUids); assertEquals(expectedUidUpdates, mHandler.numUidUpdates); Loading Loading @@ -306,9 +291,8 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mHandler, REGISTRANT_WHAT, null); mTestableLooper.processAllMessages(); // No updates triggered, but the registrant gets an empty update. verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); // No updates triggered, so TelephonyRegistry doesn't get any updates. verifyCarrierPrivilegesChangedUpdates(List.of()); } Loading @@ -323,7 +307,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mHandler, REGISTRANT_WHAT, null); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -333,7 +316,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mCarrierPrivilegesTracker.unregisterCarrierPrivilegesListener(mHandler); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of()); Loading @@ -341,7 +323,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(INVALID_SUBSCRIPTION_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of(new Pair<>(Set.of(), new int[0]))); } Loading @@ -359,7 +340,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -373,7 +353,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID_INCORRECT); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -387,7 +366,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(INVALID_SUBSCRIPTION_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -406,7 +384,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0] /* expectedUids */, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of(new Pair<>(Set.of(), new int[0]))); } Loading @@ -426,7 +403,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -439,7 +415,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendCarrierConfigChangedIntent(SUB_ID, PHONE_ID); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -458,7 +433,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -477,7 +451,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimApplicationStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -493,7 +466,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -511,7 +483,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID_INCORRECT, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(null /* expectedUids */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -525,7 +496,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_NOT_READY); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -548,7 +518,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -562,7 +531,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendSimCardStateChangedIntent(PHONE_ID, SIM_STATE_LOADED); mTestableLooper.processAllMessages(); verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -579,7 +547,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), new int[] {UID_1}); verifyRegistrantUpdates(new int[] {UID_1}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), new int[] {UID_1}))); Loading @@ -599,7 +566,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), PRIVILEGED_UIDS))); Loading @@ -620,7 +586,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REPLACED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_1), PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_1), PRIVILEGED_UIDS))); Loading @@ -645,7 +610,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -669,7 +633,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_ADDED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -688,7 +651,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REMOVED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(PACKAGE_2), new int[] {UID_2}); verifyRegistrantUpdates(new int[] {UID_2}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(Set.of(PACKAGE_2), new int[] {UID_2}))); Loading @@ -703,7 +665,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { sendPackageChangedIntent(Intent.ACTION_PACKAGE_REMOVED, PACKAGE_1); mTestableLooper.processAllMessages(); verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(null /* expectedUidUpdates */, 0 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates(List.of()); } Loading @@ -718,7 +679,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect no package will have privilege at last verifyCurrentState(Set.of(), new int[0]); verifyRegistrantUpdates(new int[0], 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -730,7 +690,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect all privileges from Carrier Config come back verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading @@ -746,7 +705,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect only PACKAGE_3 will have privilege at last verifyCurrentState(Set.of(PACKAGE_3), new int[]{UID_3}); verifyRegistrantUpdates(new int[]{UID_3}, 1 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of( Loading @@ -759,7 +717,6 @@ public class CarrierPrivilegesTrackerTest extends TelephonyTest { mTestableLooper.processAllMessages(); // Expect all privileges from UICC come back verifyCurrentState(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS); verifyRegistrantUpdates(PRIVILEGED_UIDS, 2 /* expectedUidUpdates */); verifyCarrierPrivilegesChangedUpdates( List.of(new Pair<>(PRIVILEGED_PACKAGES, PRIVILEGED_UIDS))); Loading