From 0aff5099d52dd83aa1a1226a3f1ebcbe1048a0ac Mon Sep 17 00:00:00 2001 From: Rambo Wang Date: Wed, 9 Mar 2022 18:11:04 -0800 Subject: Clear up CarrierPrivilegesListener APIs CarrierPrivilegesListener has been replaced with CarrierPrivilegesCallback. With all clients has been migrated, it is time to remove the obsoleted APIs Bug: 216549778 Test: atest CarrierPrivilegesTrackerTest CarrierServiceTest Test: atest WifiCarrierInfoManagerTest TelephonyRegistryManagerTest Test: atest TelephonySubscriptionTrackerTest Change-Id: I89df21764d3b9945219d810d0dd9bfe3cf5fbea4 Merged-In: I89df21764d3b9945219d810d0dd9bfe3cf5fbea4 (cherry picked from commit 5a4bcc0a9c1f656bd87e2830e56dea37197fdd2b) --- core/api/system-current.txt | 6 - .../telephony/TelephonyRegistryManager.java | 140 ++++----------------- .../java/android/telephony/TelephonyManager.java | 81 ------------ 3 files changed, 21 insertions(+), 206 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index cbfd86e5478f..03cb8bbedf4a 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -11594,7 +11594,6 @@ package android.telephony { } public class TelephonyManager { - method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void addCarrierPrivilegesListener(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener); method @RequiresPermission(anyOf={android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION}) @WorkerThread public void bootstrapAuthenticationRequest(int, @NonNull android.net.Uri, @NonNull android.telephony.gba.UaSecurityProtocolIdentifier, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.BootstrapAuthenticationCallback); method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String); method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult changeIccLockPin(@NonNull String, @NonNull String); @@ -11691,7 +11690,6 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.REBOOT) public int prepareForUnattendedReboot(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean rebootRadio(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerCarrierPrivilegesCallback(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CarrierPrivilegesCallback); - method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void removeCarrierPrivilegesListener(@NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void reportDefaultNetworkStatus(boolean); method @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.MODIFY_PHONE_STATE}) public void requestCellInfoUpdate(@NonNull android.os.WorkSource, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CellInfoCallback); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void requestModemActivityInfo(@NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); @@ -11851,10 +11849,6 @@ package android.telephony { method public default void onCarrierServiceChanged(@Nullable String, int); } - @Deprecated public static interface TelephonyManager.CarrierPrivilegesListener { - method @Deprecated public void onCarrierPrivilegesChanged(@NonNull java.util.List, @NonNull int[]); - } - public static class TelephonyManager.ModemActivityInfoException extends java.lang.Exception { ctor public TelephonyManager.ModemActivityInfoException(int); method public int getErrorCode(); diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java index 0d8b1f83b7fe..9c7f23e56617 100644 --- a/core/java/android/telephony/TelephonyRegistryManager.java +++ b/core/java/android/telephony/TelephonyRegistryManager.java @@ -38,7 +38,6 @@ import android.telephony.Annotation.RadioPowerState; import android.telephony.Annotation.SimActivationState; import android.telephony.Annotation.SrvccState; import android.telephony.TelephonyManager.CarrierPrivilegesCallback; -import android.telephony.TelephonyManager.CarrierPrivilegesListener; import android.telephony.emergency.EmergencyNumber; import android.telephony.ims.ImsReasonInfo; import android.util.ArraySet; @@ -1262,148 +1261,51 @@ public class TelephonyRegistryManager { pkgName, attributionTag, callback, new int[0], notifyNow); } - // TODO(b/216549778): Remove listener logic once all clients switch to CarrierPrivilegesCallback private static class CarrierPrivilegesCallbackWrapper extends ICarrierPrivilegesCallback.Stub implements ListenerExecutor { - // Either mListener or mCallback may be null, never both - @Nullable private final WeakReference mListener; - @Nullable private final WeakReference mCallback; + @NonNull private final WeakReference mCallback; @NonNull private final Executor mExecutor; CarrierPrivilegesCallbackWrapper( @NonNull CarrierPrivilegesCallback callback, @NonNull Executor executor) { - mListener = null; mCallback = new WeakReference<>(callback); mExecutor = executor; } - CarrierPrivilegesCallbackWrapper( - @NonNull CarrierPrivilegesListener listener, @NonNull Executor executor) { - mListener = new WeakReference<>(listener); - mCallback = null; - mExecutor = executor; - } - @Override public void onCarrierPrivilegesChanged( @NonNull List privilegedPackageNames, @NonNull int[] privilegedUids) { - if (mListener != null) { - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mListener::get, - cpl -> - cpl.onCarrierPrivilegesChanged( - privilegedPackageNames, privilegedUids))); - } - - if (mCallback != null) { - // AIDL interface does not support Set, keep the List/Array and translate them here - Set privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames); - Set privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect( - Collectors.toSet()); - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mCallback::get, - cpc -> - cpc.onCarrierPrivilegesChanged( - privilegedPkgNamesSet, privilegedUidsSet))); - } + // AIDL interface does not support Set, keep the List/Array and translate them here + Set privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames); + Set privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect( + Collectors.toSet()); + Binder.withCleanCallingIdentity( + () -> + executeSafely( + mExecutor, + mCallback::get, + cpc -> + cpc.onCarrierPrivilegesChanged( + privilegedPkgNamesSet, privilegedUidsSet))); } @Override public void onCarrierServiceChanged(@Nullable String packageName, int uid) { - if (mCallback != null) { - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mCallback::get, - cpc -> cpc.onCarrierServiceChanged(packageName, uid))); - } + Binder.withCleanCallingIdentity( + () -> + executeSafely( + mExecutor, + mCallback::get, + cpc -> cpc.onCarrierServiceChanged(packageName, uid))); } } - // TODO(b/216549778): Change the map key to CarrierPrivilegesCallback once all clients switch to - // CarrierPrivilegesCallback. Before that, the key is either CarrierPrivilegesCallback or - // CarrierPrivilegesListener, no logic actually depends on the type. @NonNull @GuardedBy("sCarrierPrivilegeCallbacks") - private static final WeakHashMap> + private static final WeakHashMap> sCarrierPrivilegeCallbacks = new WeakHashMap<>(); - /** - * Registers a {@link CarrierPrivilegesListener} on the given {@code logicalSlotIndex} to - * receive callbacks when the set of packages with carrier privileges changes. The callback will - * immediately be called with the latest state. - * - * @param logicalSlotIndex The SIM slot to listen on - * @param executor The executor where {@code listener} will be invoked - * @param listener The callback to register - * - * @deprecated Use {@link #addCarrierPrivilegesCallback} instead. This API will be removed - * prior to API finalization. - */ - @Deprecated - public void addCarrierPrivilegesListener( - int logicalSlotIndex, - @NonNull @CallbackExecutor Executor executor, - @NonNull CarrierPrivilegesListener listener) { - if (listener == null || executor == null) { - throw new IllegalArgumentException("listener and executor must be non-null"); - } - synchronized (sCarrierPrivilegeCallbacks) { - WeakReference existing = - sCarrierPrivilegeCallbacks.get(listener); - if (existing != null && existing.get() != null) { - Log.d(TAG, "addCarrierPrivilegesListener: listener already registered"); - return; - } - CarrierPrivilegesCallbackWrapper wrapper = - new CarrierPrivilegesCallbackWrapper(listener, executor); - sCarrierPrivilegeCallbacks.put(listener, new WeakReference<>(wrapper)); - try { - sRegistry.addCarrierPrivilegesCallback( - logicalSlotIndex, - wrapper, - mContext.getOpPackageName(), - mContext.getAttributionTag()); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - } - - /** - * Unregisters a {@link CarrierPrivilegesListener}. - * - * @param listener The callback to unregister - * - * @deprecated Use {@link #removeCarrierPrivilegesCallback} instead. The callback will prior - * to API finalization. - */ - @Deprecated - public void removeCarrierPrivilegesListener(@NonNull CarrierPrivilegesListener listener) { - if (listener == null) { - throw new IllegalArgumentException("listener must be non-null"); - } - synchronized (sCarrierPrivilegeCallbacks) { - WeakReference ref = - sCarrierPrivilegeCallbacks.remove(listener); - if (ref == null) return; - CarrierPrivilegesCallbackWrapper wrapper = ref.get(); - if (wrapper == null) return; - try { - sRegistry.removeCarrierPrivilegesCallback(wrapper, mContext.getOpPackageName()); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - } - /** * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to * receive callbacks when the set of packages with carrier privileges changes. The callback will diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 9720819f8add..3e3d72655940 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -16239,32 +16239,6 @@ public class TelephonyManager { return null; } - /** - * Callback to listen for when the set of packages with carrier privileges for a SIM changes. - * - * @hide - * @deprecated Use {@link CarrierPrivilegesCallback} instead. This API will be removed soon - * prior to API finalization. - */ - @Deprecated - @SystemApi - public interface CarrierPrivilegesListener { - /** - * Called when the set of packages with carrier privileges has changed. - * - *

Of note, this callback will not be fired if a carrier triggers a SIM profile - * switch and the same set of packages remains privileged after the switch. - * - *

At registration, the callback will receive the current set of privileged packages. - * - * @param privilegedPackageNames The updated set of package names that have carrier - * privileges - * @param privilegedUids The updated set of UIDs that have carrier privileges - */ - void onCarrierPrivilegesChanged( - @NonNull List privilegedPackageNames, @NonNull int[] privilegedUids); - } - /** * Callbacks to listen for when the set of packages with carrier privileges for a SIM changes. * @@ -16313,61 +16287,6 @@ public class TelephonyManager { } } - /** - * Registers a {@link CarrierPrivilegesListener} on the given {@code logicalSlotIndex} to - * receive callbacks when the set of packages with carrier privileges changes. The callback will - * immediately be called with the latest state. - * - * @param logicalSlotIndex The SIM slot to listen on - * @param executor The executor where {@code listener} will be invoked - * @param listener The callback to register - * @hide - * @deprecated Use {@link #registerCarrierPrivilegesCallback} instead. This API will be - * removed prior to API finalization. - */ - @Deprecated - @SystemApi - @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void addCarrierPrivilegesListener( - int logicalSlotIndex, - @NonNull @CallbackExecutor Executor executor, - @NonNull CarrierPrivilegesListener listener) { - if (mContext == null) { - throw new IllegalStateException("Telephony service is null"); - } else if (executor == null || listener == null) { - throw new IllegalArgumentException( - "CarrierPrivilegesListener and executor must be non-null"); - } - mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); - if (mTelephonyRegistryMgr == null) { - throw new IllegalStateException("Telephony registry service is null"); - } - mTelephonyRegistryMgr.addCarrierPrivilegesListener(logicalSlotIndex, executor, listener); - } - - /** - * Unregisters an existing {@link CarrierPrivilegesListener}. - * - * @hide - * @deprecated Use {@link #unregisterCarrierPrivilegesCallback} instead. This API will be - * removed prior to API finalization. - */ - @Deprecated - @SystemApi - @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void removeCarrierPrivilegesListener(@NonNull CarrierPrivilegesListener listener) { - if (mContext == null) { - throw new IllegalStateException("Telephony service is null"); - } else if (listener == null) { - throw new IllegalArgumentException("CarrierPrivilegesListener must be non-null"); - } - mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); - if (mTelephonyRegistryMgr == null) { - throw new IllegalStateException("Telephony registry service is null"); - } - mTelephonyRegistryMgr.removeCarrierPrivilegesListener(listener); - } - /** * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to * receive callbacks when the set of packages with carrier privileges changes. The callback will -- cgit v1.2.3-59-g8ed1b