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

Commit f67f2bc1 authored by Rambo Wang's avatar Rambo Wang Committed by Automerger Merge Worker
Browse files

Merge "Introduce CarrierPrivilegesCallback to replace...

Merge "Introduce CarrierPrivilegesCallback to replace CarrierPrivilegesListener" into tm-dev am: 01da9965

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

Change-Id: Ie42962c78ab5601d9a6d518362ea390af1fd4e17
parents 79313123 01da9965
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -13340,7 +13340,7 @@ package android.telephony {
  }
  public class TelephonyManager {
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void addCarrierPrivilegesListener(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener);
    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);
@@ -13440,7 +13440,8 @@ package android.telephony {
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void notifyOtaEmergencyNumberDbInstalled();
    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 removeCarrierPrivilegesListener(@NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener);
    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>);
@@ -13490,6 +13491,7 @@ package android.telephony {
    method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String, String);
    method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean switchSlots(int[]);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void toggleRadioOnOff();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void unregisterCarrierPrivilegesCallback(@NonNull android.telephony.TelephonyManager.CarrierPrivilegesCallback);
    method @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void updateOtaEmergencyNumberDbFilePath(@NonNull android.os.ParcelFileDescriptor);
    method public void updateServiceLocation();
    field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final String ACTION_ANOMALY_REPORTED = "android.telephony.action.ANOMALY_REPORTED";
@@ -13595,8 +13597,13 @@ package android.telephony {
    field public static final int RESULT_SUCCESS = 0; // 0x0
  }
  public static interface TelephonyManager.CarrierPrivilegesListener {
    method public void onCarrierPrivilegesChanged(@NonNull java.util.List<java.lang.String>, @NonNull int[]);
  public static interface TelephonyManager.CarrierPrivilegesCallback {
    method public void onCarrierPrivilegesChanged(@NonNull java.util.Set<java.lang.String>, @NonNull java.util.Set<java.lang.Integer>);
    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 {
+169 −34
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.carrier.CarrierService;
import android.telephony.Annotation.CallState;
import android.telephony.Annotation.DataActivityType;
import android.telephony.Annotation.DisconnectCauses;
@@ -36,6 +37,7 @@ import android.telephony.Annotation.PreciseDisconnectCauses;
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;
@@ -44,17 +46,19 @@ import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.listeners.ListenerExecutor;
import com.android.internal.telephony.ICarrierPrivilegesListener;
import com.android.internal.telephony.ICarrierPrivilegesCallback;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ITelephonyRegistry;

import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
 * A centralized place to notify telephony related status changes, e.g, {@link ServiceState} update
@@ -1260,19 +1264,32 @@ public class TelephonyRegistryManager {
                pkgName, attributionTag, callback, new int[0], notifyNow);
    }

    private static class CarrierPrivilegesListenerWrapper extends ICarrierPrivilegesListener.Stub
    // TODO(b/216549778): Remove listener logic once all clients switch to CarrierPrivilegesCallback
    private static class CarrierPrivilegesCallbackWrapper extends ICarrierPrivilegesCallback.Stub
            implements ListenerExecutor {
        private final WeakReference<CarrierPrivilegesListener> mListener;
        private final Executor mExecutor;
        // Either mListener or mCallback may be null, never both
        @Nullable private final WeakReference<CarrierPrivilegesListener> mListener;
        @Nullable 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;
        }

        CarrierPrivilegesListenerWrapper(CarrierPrivilegesListener listener, Executor executor) {
        CarrierPrivilegesCallbackWrapper(
                @NonNull CarrierPrivilegesListener listener, @NonNull Executor executor) {
            mListener = new WeakReference<>(listener);
            mCallback = null;
            mExecutor = executor;
        }

        @Override
        public void onCarrierPrivilegesChanged(
                List<String> privilegedPackageNames, int[] privilegedUids) {
                @NonNull List<String> privilegedPackageNames, @NonNull int[] privilegedUids) {
            if (mListener != null) {
                Binder.withCleanCallingIdentity(
                        () ->
                                executeSafely(
@@ -1282,12 +1299,43 @@ public class TelephonyRegistryManager {
                                                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(
                        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)));
            }
        }
    }

    @GuardedBy("sCarrierPrivilegeListeners")
    private static final WeakHashMap<
                    CarrierPrivilegesListener, WeakReference<CarrierPrivilegesListenerWrapper>>
            sCarrierPrivilegeListeners = new WeakHashMap<>();
    // 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>>
            sCarrierPrivilegeCallbacks = new WeakHashMap<>();

    /**
     * Registers a {@link CarrierPrivilegesListener} on the given {@code logicalSlotIndex} to
@@ -1297,7 +1345,11 @@ public class TelephonyRegistryManager {
     * @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,
@@ -1305,18 +1357,18 @@ public class TelephonyRegistryManager {
        if (listener == null || executor == null) {
            throw new IllegalArgumentException("listener and executor must be non-null");
        }
        synchronized (sCarrierPrivilegeListeners) {
            WeakReference<CarrierPrivilegesListenerWrapper> existing =
                    sCarrierPrivilegeListeners.get(listener);
        synchronized (sCarrierPrivilegeCallbacks) {
            WeakReference<CarrierPrivilegesCallbackWrapper> existing =
                    sCarrierPrivilegeCallbacks.get(listener);
            if (existing != null && existing.get() != null) {
                Log.d(TAG, "addCarrierPrivilegesListener: listener already registered");
                return;
            }
            CarrierPrivilegesListenerWrapper wrapper =
                    new CarrierPrivilegesListenerWrapper(listener, executor);
            sCarrierPrivilegeListeners.put(listener, new WeakReference<>(wrapper));
            CarrierPrivilegesCallbackWrapper wrapper =
                    new CarrierPrivilegesCallbackWrapper(listener, executor);
            sCarrierPrivilegeCallbacks.put(listener, new WeakReference<>(wrapper));
            try {
                sRegistry.addCarrierPrivilegesListener(
                sRegistry.addCarrierPrivilegesCallback(
                        logicalSlotIndex,
                        wrapper,
                        mContext.getOpPackageName(),
@@ -1331,19 +1383,84 @@ public class TelephonyRegistryManager {
     * 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 (sCarrierPrivilegeListeners) {
            WeakReference<CarrierPrivilegesListenerWrapper> ref =
                    sCarrierPrivilegeListeners.remove(listener);
        synchronized (sCarrierPrivilegeCallbacks) {
            WeakReference<CarrierPrivilegesCallbackWrapper> ref =
                    sCarrierPrivilegeCallbacks.remove(listener);
            if (ref == null) return;
            CarrierPrivilegesListenerWrapper wrapper = ref.get();
            CarrierPrivilegesCallbackWrapper wrapper = ref.get();
            if (wrapper == null) return;
            try {
                sRegistry.removeCarrierPrivilegesListener(wrapper, mContext.getOpPackageName());
                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
     * 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 callback The callback to register
     */
    public void addCarrierPrivilegesCallback(
            int logicalSlotIndex,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull CarrierPrivilegesCallback callback) {
        if (callback == null || executor == null) {
            throw new IllegalArgumentException("callback and executor must be non-null");
        }
        synchronized (sCarrierPrivilegeCallbacks) {
            WeakReference<CarrierPrivilegesCallbackWrapper> existing =
                    sCarrierPrivilegeCallbacks.get(callback);
            if (existing != null && existing.get() != null) {
                Log.d(TAG, "addCarrierPrivilegesCallback: callback already registered");
                return;
            }
            CarrierPrivilegesCallbackWrapper wrapper =
                    new CarrierPrivilegesCallbackWrapper(callback, executor);
            sCarrierPrivilegeCallbacks.put(callback, new WeakReference<>(wrapper));
            try {
                sRegistry.addCarrierPrivilegesCallback(
                        logicalSlotIndex,
                        wrapper,
                        mContext.getOpPackageName(),
                        mContext.getAttributionTag());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Unregisters a {@link CarrierPrivilegesCallback}.
     *
     * @param callback The callback to unregister
     */
    public void removeCarrierPrivilegesCallback(@NonNull CarrierPrivilegesCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("listener must be non-null");
        }
        synchronized (sCarrierPrivilegeCallbacks) {
            WeakReference<CarrierPrivilegesCallbackWrapper> ref =
                    sCarrierPrivilegeCallbacks.remove(callback);
            if (ref == null) return;
            CarrierPrivilegesCallbackWrapper wrapper = ref.get();
            if (wrapper == null) return;
            try {
                sRegistry.removeCarrierPrivilegesCallback(wrapper, mContext.getOpPackageName());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1359,15 +1476,33 @@ public class TelephonyRegistryManager {
     */
    public void notifyCarrierPrivilegesChanged(
            int logicalSlotIndex,
            @NonNull List<String> privilegedPackageNames,
            @NonNull int[] privilegedUids) {
            @NonNull Set<String> privilegedPackageNames,
            @NonNull Set<Integer> privilegedUids) {
        if (privilegedPackageNames == null || privilegedUids == null) {
            throw new IllegalArgumentException(
                    "privilegedPackageNames and privilegedUids must be non-null");
        }
        try {
            sRegistry.notifyCarrierPrivilegesChanged(
                    logicalSlotIndex, privilegedPackageNames, privilegedUids);
            // AIDL doesn't support Set yet. Convert Set to List/Array
            List<String> pkgList = List.copyOf(privilegedPackageNames);
            int[] uids = privilegedUids.stream().mapToInt(Number::intValue).toArray();
            sRegistry.notifyCarrierPrivilegesChanged(logicalSlotIndex, pkgList, uids);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Notify listeners that the {@link CarrierService} for current user has changed.
     *
     * @param logicalSlotIndex the SIM slot the change occurred on
     * @param packageName the package name of the changed {@link CarrierService}
     * @param uid the UID of the changed {@link CarrierService}
     */
    public void notifyCarrierServiceChanged(int logicalSlotIndex, @Nullable String packageName,
            int uid) {
        try {
            sRegistry.notifyCarrierServiceChanged(logicalSlotIndex, packageName, uid);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+2 −1
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@

package com.android.internal.telephony;

oneway interface ICarrierPrivilegesListener {
oneway interface ICarrierPrivilegesCallback {
    void onCarrierPrivilegesChanged(
            in List<String> privilegedPackageNames, in int[] privilegedUids);
    void onCarrierServiceChanged(in String carrierServicePackageName, in int carrierServiceUid);
}
+6 −4
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import android.telephony.PreciseDataConnectionState;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.emergency.EmergencyNumber;
import com.android.internal.telephony.ICarrierPrivilegesListener;
import com.android.internal.telephony.ICarrierPrivilegesCallback;
import com.android.internal.telephony.IPhoneStateListener;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;

@@ -102,9 +102,11 @@ interface ITelephonyRegistry {
    void notifyLinkCapacityEstimateChanged(in int phoneId, in int subId,
            in List<LinkCapacityEstimate> linkCapacityEstimateList);

    void addCarrierPrivilegesListener(
            int phoneId, ICarrierPrivilegesListener callback, String pkg, String featureId);
    void removeCarrierPrivilegesListener(ICarrierPrivilegesListener callback, String pkg);
    void addCarrierPrivilegesCallback(
            int phoneId, ICarrierPrivilegesCallback callback, String pkg, String featureId);
    void removeCarrierPrivilegesCallback(ICarrierPrivilegesCallback callback, String pkg);
    void notifyCarrierPrivilegesChanged(
            int phoneId, in List<String> privilegedPackageNames, in int[] privilegedUids);
    void notifyCarrierServiceChanged(int phoneId, in String packageName, int uid);

}
+65 −20

File changed.

Preview size limit exceeded, changes collapsed.

Loading