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

Commit 518380d8 authored by Kweku Adams's avatar Kweku Adams
Browse files

Add removeFromWhitelist method to PowerWhitelistManager.

The remove/restoreSystemWhitelist methods don't seem to be used
anywhere, so I've left them out for now.

Bug: 142420609
Bug: 144864180
Test: atest PowerWhitelistTest
Change-Id: I669f805044deab0817766be8c3671d6375087ce0
parent d9f637b1
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -30,7 +30,11 @@ import java.util.Collections;
import java.util.List;

/**
 * Interface to access and modify the power save whitelist.
 * Interface to access and modify the permanent and temporary power save whitelist. The two lists
 * are kept separately. Apps placed on the permanent whitelist are only removed via an explicit
 * removeFromWhitelist call. Apps whitelisted by default by the system cannot be removed. Apps
 * placed on the temporary whitelist are removed from that whitelist after a predetermined amount of
 * time.
 *
 * @hide
 */
@@ -140,6 +144,22 @@ public class PowerWhitelistManager {
        }
    }

    /**
     * Remove an app from the permanent power save whitelist. Only apps that were added via
     * {@link #addToWhitelist(String)} or {@link #addToWhitelist(List)} will be removed. Apps
     * whitelisted by default by the system cannot be removed.
     *
     * @param packageName The app to remove from the whitelist
     */
    @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
    public void removeFromWhitelist(@NonNull String packageName) {
        try {
            mService.removePowerSaveWhitelistApp(packageName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Add an app to the temporary whitelist for a short amount of time.
     *
@@ -158,12 +178,14 @@ public class PowerWhitelistManager {
    }

    /**
     * Add an app to the temporary whitelist for a short amount of time for a specific reason.
     * Add an app to the temporary whitelist for a short amount of time for a specific reason. The
     * temporary whitelist is kept separately from the permanent whitelist and apps are
     * automatically removed from the temporary whitelist after a predetermined amount of time.
     *
     * @param packageName The package to add to the temp whitelist
     * @param event       The reason to add the app to the temp whitelist
     * @param reason A human-readable reason explaining why the app is temp whitelisted. Only used
     *               for logging purposes
     * @param reason      A human-readable reason explaining why the app is temp whitelisted. Only
     *                    used for logging purposes
     * @return The duration (in milliseconds) that the app is whitelisted for
     */
    @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST)
+4 −1
Original line number Diff line number Diff line
@@ -1595,7 +1595,10 @@ public class DeviceIdleController extends SystemService
                    null);
            long ident = Binder.clearCallingIdentity();
            try {
                removePowerSaveWhitelistAppInternal(name);
                if (!removePowerSaveWhitelistAppInternal(name)
                        && mPowerSaveWhitelistAppsExceptIdle.containsKey(name)) {
                    throw new UnsupportedOperationException("Cannot remove system whitelisted app");
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
+1 −0
Original line number Diff line number Diff line
@@ -8386,6 +8386,7 @@ package android.os {
  public class PowerWhitelistManager {
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void addToWhitelist(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void addToWhitelist(@NonNull java.util.List<java.lang.String>);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void removeFromWhitelist(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String, long);
    method @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String, int, @NonNull String);
    field public static final int EVENT_MMS = 2; // 0x2
+1 −0
Original line number Diff line number Diff line
@@ -2665,6 +2665,7 @@ package android.os {
  public class PowerWhitelistManager {
    method @RequiresPermission("android.permission.DEVICE_POWER") public void addToWhitelist(@NonNull String);
    method @RequiresPermission("android.permission.DEVICE_POWER") public void addToWhitelist(@NonNull java.util.List<java.lang.String>);
    method @RequiresPermission("android.permission.DEVICE_POWER") public void removeFromWhitelist(@NonNull String);
    method @RequiresPermission("android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST") public void whitelistAppTemporarily(@NonNull String, long);
    method @RequiresPermission("android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST") public long whitelistAppTemporarilyForEvent(@NonNull String, int, @NonNull String);
    field public static final int EVENT_MMS = 2; // 0x2
+1 −0
Original line number Diff line number Diff line
@@ -7298,6 +7298,7 @@ package android.os {
  public class PowerWhitelistManager {
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void addToWhitelist(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void addToWhitelist(@NonNull java.util.List<java.lang.String>);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void removeFromWhitelist(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String, long);
    method @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String, int, @NonNull String);
    field public static final int EVENT_MMS = 2; // 0x2