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

Commit 330b74c5 authored by Kweku Adams's avatar Kweku Adams
Browse files

Add PowerWhitelistManager.getWhitelistedAppIds.

The "XXXExceptIdle" lists and methods are expected to be a superset of
the XXX methods. That's not immediately obvious from the method names.
This effort is to clean up the naming and add documentation so behavior
is better documented. As part of this, we're moving the
getAppIdWhitelisted methods to PowerWhitelistManager to also help
clean up the interface between the apex and the rest of the system.

Bug: 142420609
Bug: 144864180
Bug: 145014493
Test: atest CtsHostsideNetworkTests
Test: atest FrameworksCoreTests:NetworkPolicyManagerTest
Test: atest FrameworksServicesTests:NetworkPolicyManagerServiceTest
Change-Id: I9438a948c916be273f65febd42c3567cc1dc035d
parent 3b2dccfc
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;

import libcore.util.EmptyArray;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
@@ -99,6 +101,28 @@ public class PowerWhitelistManager {
        }
    }

    /**
     * Get a list of app IDs of app that are whitelisted. This does not include temporarily
     * whitelisted apps.
     *
     * @param includingIdle Set to true if the app should be whitelisted from device idle as well
     *                      as other power save restrictions
     * @hide
     */
    @NonNull
    public int[] getWhitelistedAppIds(boolean includingIdle) {
        try {
            if (includingIdle) {
                return mService.getAppIdWhitelist();
            } else {
                return mService.getAppIdWhitelistExceptIdle();
            }
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return EmptyArray.INT;
        }
    }

    /**
     * Add an app to the temporary whitelist for a short amount of time.
     *
+14 −22
Original line number Diff line number Diff line
@@ -171,7 +171,6 @@ import android.os.Environment;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.os.IDeviceIdleController;
import android.os.INetworkManagementService;
import android.os.Message;
import android.os.MessageQueue.IdleHandler;
@@ -180,11 +179,11 @@ import android.os.PowerManager;
import android.os.PowerManager.ServiceType;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
import android.os.PowerWhitelistManager;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.SystemClock;
import android.os.SystemProperties;
@@ -411,7 +410,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

    private IConnectivityManager mConnManager;
    private PowerManagerInternal mPowerManagerInternal;
    private IDeviceIdleController mDeviceIdleController;
    private PowerWhitelistManager mPowerWhitelistManager;

    /** Current cached value of the current Battery Saver mode's setting for restrict background. */
    @GuardedBy("mUidRulesFirstLock")
@@ -618,8 +617,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        mContext = Objects.requireNonNull(context, "missing context");
        mActivityManager = Objects.requireNonNull(activityManager, "missing activityManager");
        mNetworkManager = Objects.requireNonNull(networkManagement, "missing networkManagement");
        mDeviceIdleController = IDeviceIdleController.Stub.asInterface(ServiceManager.getService(
                Context.DEVICE_IDLE_CONTROLLER));
        mPowerWhitelistManager = mContext.getSystemService(PowerWhitelistManager.class);
        mClock = Objects.requireNonNull(clock, "missing Clock");
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
@@ -651,25 +649,19 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    }

    @GuardedBy("mUidRulesFirstLock")
    void updatePowerSaveWhitelistUL() {
        try {
            int[] whitelist = mDeviceIdleController.getAppIdWhitelistExceptIdle();
    private void updatePowerSaveWhitelistUL() {
        int[] whitelist = mPowerWhitelistManager.getWhitelistedAppIds(/* includingIdle */ false);
        mPowerSaveWhitelistExceptIdleAppIds.clear();
            if (whitelist != null) {
        for (int uid : whitelist) {
            mPowerSaveWhitelistExceptIdleAppIds.put(uid, true);
        }
            }
            whitelist = mDeviceIdleController.getAppIdWhitelist();

        whitelist = mPowerWhitelistManager.getWhitelistedAppIds(/* includingIdle */ true);
        mPowerSaveWhitelistAppIds.clear();
            if (whitelist != null) {
        for (int uid : whitelist) {
            mPowerSaveWhitelistAppIds.put(uid, true);
        }
    }
        } catch (RemoteException e) {
        }
    }

    /**
     * Whitelists pre-defined apps for restrict background, but only if the user didn't already