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

Commit e5376931 authored by Mark Fasheh's avatar Mark Fasheh
Browse files

ActivityManager: Throw correct exception during Uid Frozen registration

registerUidFrozenStateChangedCallback is throwing
IllegalArgumentException, but the javadoc says it throws
IllegalStateException. We want to follow the doc in this case so fix the
function to throw IllegalStateException.

While we're here we can add some missing permission and Null checks.

We were also missing a description for onUidFrozenStateChanged, add one.

Bug: 274010383
Test: Compiled
Change-Id: Ie798ba87f043a8a45a8d3233d275ccab9f97d14f
parent 1c00ee51
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ public class ActivityManager {
     * Map of callbacks that have registered for {@link UidFrozenStateChanged} events.
     * Will be called when a Uid has become frozen or unfrozen.
     */
    final ArrayMap<UidFrozenStateChangedCallback, Executor> mFrozenStateChangedCallbacks =
    private final ArrayMap<UidFrozenStateChangedCallback, Executor> mFrozenStateChangedCallbacks =
             new ArrayMap<>();

    private final IUidFrozenStateChangedCallback mFrozenStateChangedCallback =
@@ -284,6 +284,8 @@ public class ActivityManager {
        public @interface UidFrozenState {}

        /**
         * Notify the client that the frozen states of an array of UIDs have changed.
         *
         * @param uids The UIDs for which the frozen state has changed
         * @param frozenStates Frozen state for each UID index, Will be set to
         *               {@link UidFrozenStateChangedCallback#UID_FROZEN_STATE_FROZEN}
@@ -316,9 +318,11 @@ public class ActivityManager {
    public void registerUidFrozenStateChangedCallback(
            @NonNull Executor executor,
            @NonNull UidFrozenStateChangedCallback callback) {
        Preconditions.checkNotNull(executor, "executor cannot be null");
        Preconditions.checkNotNull(callback, "callback cannot be null");
        synchronized (mFrozenStateChangedCallbacks) {
            if (mFrozenStateChangedCallbacks.containsKey(callback)) {
                throw new IllegalArgumentException("Callback already registered: " + callback);
                throw new IllegalStateException("Callback already registered: " + callback);
            }
            mFrozenStateChangedCallbacks.put(callback, executor);
            if (mFrozenStateChangedCallbacks.size() > 1) {
@@ -344,6 +348,7 @@ public class ActivityManager {
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public void unregisterUidFrozenStateChangedCallback(
            @NonNull UidFrozenStateChangedCallback callback) {
        Preconditions.checkNotNull(callback, "callback cannot be null");
        synchronized (mFrozenStateChangedCallbacks) {
            mFrozenStateChangedCallbacks.remove(callback);
            if (mFrozenStateChangedCallbacks.isEmpty()) {
+2 −0
Original line number Diff line number Diff line
@@ -879,6 +879,8 @@ interface IActivityManager {
    /** Logs API state change to associate with an FGS, used for FGS Type Metrics */
    void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
    void registerUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
    void unregisterUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback);
}