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

Commit 5a4bcc0a authored by Rambo Wang's avatar Rambo Wang
Browse files

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
parent 1ffa981e
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -13368,7 +13368,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);
@@ -13469,7 +13468,6 @@ package android.telephony {
    method @RequiresPermission(android.Manifest.permission.REBOOT) public int prepareForUnattendedReboot();
    method @Deprecated @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<android.telephony.ModemActivityInfo,android.telephony.TelephonyManager.ModemActivityInfoException>);
@@ -13630,10 +13628,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<java.lang.String>, @NonNull int[]);
  }
  public static class TelephonyManager.ModemActivityInfoException extends java.lang.Exception {
    ctor public TelephonyManager.ModemActivityInfoException(int);
    method public int getErrorCode();
+21 −119
Original line number Diff line number Diff line
@@ -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;
@@ -1264,43 +1263,20 @@ 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<CarrierPrivilegesListener> mListener;
        @Nullable private final WeakReference<CarrierPrivilegesCallback> mCallback;
        @NonNull private final WeakReference<CarrierPrivilegesCallback> 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<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
            Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames);
            Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect(
@@ -1314,11 +1290,9 @@ public class TelephonyRegistryManager {
                                            cpc.onCarrierPrivilegesChanged(
                                                    privilegedPkgNamesSet, privilegedUidsSet)));
        }
        }

        @Override
        public void onCarrierServiceChanged(@Nullable String packageName, int uid) {
            if (mCallback != null) {
            Binder.withCleanCallingIdentity(
                    () ->
                            executeSafely(
@@ -1327,85 +1301,13 @@ public class TelephonyRegistryManager {
                                    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<Object,  WeakReference<CarrierPrivilegesCallbackWrapper>>
    private static final WeakHashMap<CarrierPrivilegesCallback,
            WeakReference<CarrierPrivilegesCallbackWrapper>>
            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
     * receive callbacks when the set of packages with carrier privileges changes. The callback will
+0 −81
Original line number Diff line number Diff line
@@ -16787,32 +16787,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.
         *
         * <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.
     *
@@ -16861,61 +16835,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);
    }
    /**
     * Sets a voice service state override from telecom based on the current {@link PhoneAccount}s
     * registered. See {@link PhoneAccount#CAPABILITY_VOICE_CALLING_AVAILABLE}.