Merge "Clear up CarrierPrivilegesListener APIs" am: d25623ae62

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2040804

Change-Id: I8b4527c292650ed2d315db29011508738c82d871
This commit is contained in:
Rambo Wang
2022-03-24 20:01:03 +00:00
committed by Automerger Merge Worker
3 changed files with 21 additions and 206 deletions

View File

@@ -11596,7 +11596,6 @@ package android.telephony {
} }
public class TelephonyManager { 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 @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 @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); method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult changeIccLockPin(@NonNull String, @NonNull String);
@@ -11697,7 +11696,6 @@ package android.telephony {
method @RequiresPermission(android.Manifest.permission.REBOOT) public int prepareForUnattendedReboot(); 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.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 @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(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(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<android.telephony.ModemActivityInfo,android.telephony.TelephonyManager.ModemActivityInfoException>); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void requestModemActivityInfo(@NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.telephony.ModemActivityInfo,android.telephony.TelephonyManager.ModemActivityInfoException>);
@@ -11857,10 +11855,6 @@ package android.telephony {
method public default void onCarrierServiceChanged(@Nullable String, int); method public default void onCarrierServiceChanged(@Nullable String, int);
} }
@Deprecated public static interface TelephonyManager.CarrierPrivilegesListener {
method @Deprecated public void onCarrierPrivilegesChanged(@NonNull java.util.List<java.lang.String>, @NonNull int[]);
}
public static class TelephonyManager.ModemActivityInfoException extends java.lang.Exception { public static class TelephonyManager.ModemActivityInfoException extends java.lang.Exception {
ctor public TelephonyManager.ModemActivityInfoException(int); ctor public TelephonyManager.ModemActivityInfoException(int);
method public int getErrorCode(); method public int getErrorCode();

View File

@@ -38,7 +38,6 @@ import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SimActivationState; import android.telephony.Annotation.SimActivationState;
import android.telephony.Annotation.SrvccState; import android.telephony.Annotation.SrvccState;
import android.telephony.TelephonyManager.CarrierPrivilegesCallback; import android.telephony.TelephonyManager.CarrierPrivilegesCallback;
import android.telephony.TelephonyManager.CarrierPrivilegesListener;
import android.telephony.emergency.EmergencyNumber; import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsReasonInfo; import android.telephony.ims.ImsReasonInfo;
import android.util.ArraySet; import android.util.ArraySet;
@@ -1262,43 +1261,20 @@ public class TelephonyRegistryManager {
pkgName, attributionTag, callback, new int[0], notifyNow); 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 private static class CarrierPrivilegesCallbackWrapper extends ICarrierPrivilegesCallback.Stub
implements ListenerExecutor { implements ListenerExecutor {
// Either mListener or mCallback may be null, never both @NonNull private final WeakReference<CarrierPrivilegesCallback> mCallback;
@Nullable private final WeakReference<CarrierPrivilegesListener> mListener;
@Nullable private final WeakReference<CarrierPrivilegesCallback> mCallback;
@NonNull private final Executor mExecutor; @NonNull private final Executor mExecutor;
CarrierPrivilegesCallbackWrapper( CarrierPrivilegesCallbackWrapper(
@NonNull CarrierPrivilegesCallback callback, @NonNull Executor executor) { @NonNull CarrierPrivilegesCallback callback, @NonNull Executor executor) {
mListener = null;
mCallback = new WeakReference<>(callback); mCallback = new WeakReference<>(callback);
mExecutor = executor; mExecutor = executor;
} }
CarrierPrivilegesCallbackWrapper(
@NonNull CarrierPrivilegesListener listener, @NonNull Executor executor) {
mListener = new WeakReference<>(listener);
mCallback = null;
mExecutor = executor;
}
@Override @Override
public void onCarrierPrivilegesChanged( public void onCarrierPrivilegesChanged(
@NonNull List<String> privilegedPackageNames, @NonNull int[] privilegedUids) { @NonNull List<String> 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 // AIDL interface does not support Set, keep the List/Array and translate them here
Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames); Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames);
Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect( Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect(
@@ -1312,11 +1288,9 @@ public class TelephonyRegistryManager {
cpc.onCarrierPrivilegesChanged( cpc.onCarrierPrivilegesChanged(
privilegedPkgNamesSet, privilegedUidsSet))); privilegedPkgNamesSet, privilegedUidsSet)));
} }
}
@Override @Override
public void onCarrierServiceChanged(@Nullable String packageName, int uid) { public void onCarrierServiceChanged(@Nullable String packageName, int uid) {
if (mCallback != null) {
Binder.withCleanCallingIdentity( Binder.withCleanCallingIdentity(
() -> () ->
executeSafely( executeSafely(
@@ -1325,85 +1299,13 @@ public class TelephonyRegistryManager {
cpc -> cpc.onCarrierServiceChanged(packageName, uid))); 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 @NonNull
@GuardedBy("sCarrierPrivilegeCallbacks") @GuardedBy("sCarrierPrivilegeCallbacks")
private static final WeakHashMap<Object, WeakReference<CarrierPrivilegesCallbackWrapper>> private static final WeakHashMap<CarrierPrivilegesCallback,
WeakReference<CarrierPrivilegesCallbackWrapper>>
sCarrierPrivilegeCallbacks = new 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<CarrierPrivilegesCallbackWrapper> 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<CarrierPrivilegesCallbackWrapper> 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 * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to
* receive callbacks when the set of packages with carrier privileges changes. The callback will * receive callbacks when the set of packages with carrier privileges changes. The callback will

View File

@@ -16425,32 +16425,6 @@ public class TelephonyManager {
return null; 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.
*
* <p>Of note, this callback will <b>not</b> be fired if a carrier triggers a SIM profile
* switch and the same set of packages remains privileged after the switch.
*
* <p>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<String> privilegedPackageNames, @NonNull int[] privilegedUids);
}
/** /**
* Callbacks to listen for when the set of packages with carrier privileges for a SIM changes. * Callbacks to listen for when the set of packages with carrier privileges for a SIM changes.
* *
@@ -16499,61 +16473,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 * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to
* receive callbacks when the set of packages with carrier privileges changes. The callback will * receive callbacks when the set of packages with carrier privileges changes. The callback will