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

Commit 891e56d3 authored by Kweku Adams's avatar Kweku Adams
Browse files

Move add-to-whitelist APIs.

Move addToPowerSaveWhitelist to PowerWhitelistManager and rename the
method.

Bug: 138239060
Bug: 140141678
Bug: 144864180
Test: atest PowerWhitelistTest
Change-Id: I7ae16c48e2eb3a5aa66e7e44dfca05b942e65741
parent 4b219792
Loading
Loading
Loading
Loading
+0 −18
Original line number Original line Diff line number Diff line
@@ -17,13 +17,10 @@
package android.os;
package android.os;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.content.Context;
import android.content.Context;


import java.util.List;

/**
/**
 * Access to the service that keeps track of device idleness and drives low power mode based on
 * Access to the service that keeps track of device idleness and drives low power mode based on
 * that.
 * that.
@@ -74,21 +71,6 @@ public class DeviceIdleManager {
        }
        }
    }
    }


    /**
     * Add the specified packages to the power save whitelist.
     *
     * @return the number of packages that were successfully added to the whitelist
     */
    @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
    public int addPowerSaveWhitelistApps(@NonNull List<String> packageNames) {
        try {
            return mService.addPowerSaveWhitelistApps(packageNames);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return 0;
        }
    }

    /**
    /**
     * Return whether a given package is in the power-save whitelist or not.
     * Return whether a given package is in the power-save whitelist or not.
     * @hide
     * @hide
+27 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,8 @@ import android.content.Context;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.List;


/**
/**
 * Interface to access and modify the power save whitelist.
 * Interface to access and modify the power save whitelist.
@@ -77,6 +79,31 @@ public class PowerWhitelistManager {
        mService = context.getSystemService(DeviceIdleManager.class).getService();
        mService = context.getSystemService(DeviceIdleManager.class).getService();
    }
    }


    /**
     * Add the specified package to the power save whitelist.
     *
     * @return true if the package was successfully added to the whitelist
     */
    @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
    public boolean addToWhitelist(@NonNull String packageName) {
        return addToWhitelist(Collections.singletonList(packageName)) == 1;
    }

    /**
     * Add the specified packages to the power save whitelist.
     *
     * @return the number of packages that were successfully added to the whitelist
     */
    @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
    public int addToWhitelist(@NonNull List<String> packageNames) {
        try {
            return mService.addPowerSaveWhitelistApps(packageNames);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return 0;
        }
    }

    /**
    /**
     * Add an app to the temporary whitelist for a short amount of time.
     * Add an app to the temporary whitelist for a short amount of time.
     *
     *
+2 −0
Original line number Original line Diff line number Diff line
@@ -6256,6 +6256,8 @@ package android.os {
  }
  }
  public class PowerWhitelistManager {
  public class PowerWhitelistManager {
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public boolean addToWhitelist(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public int addToWhitelist(@NonNull java.util.List<java.lang.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 void whitelistAppTemporarily(@NonNull String, long);
    method @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String, int, @NonNull String);
    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
    field public static final int EVENT_MMS = 2; // 0x2
+2 −1
Original line number Original line Diff line number Diff line
@@ -1794,7 +1794,6 @@ package android.os {
  }
  }


  public class DeviceIdleManager {
  public class DeviceIdleManager {
    method @RequiresPermission("android.permission.DEVICE_POWER") public int addPowerSaveWhitelistApps(@NonNull java.util.List<java.lang.String>);
    method @NonNull public String[] getSystemPowerWhitelist();
    method @NonNull public String[] getSystemPowerWhitelist();
    method @NonNull public String[] getSystemPowerWhitelistExceptIdle();
    method @NonNull public String[] getSystemPowerWhitelistExceptIdle();
  }
  }
@@ -2043,6 +2042,8 @@ package android.os {
  }
  }


  public class PowerWhitelistManager {
  public class PowerWhitelistManager {
    method @RequiresPermission("android.permission.DEVICE_POWER") public boolean addToWhitelist(@NonNull String);
    method @RequiresPermission("android.permission.DEVICE_POWER") public int addToWhitelist(@NonNull java.util.List<java.lang.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 void whitelistAppTemporarily(@NonNull String, long);
    method @RequiresPermission("android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST") public long whitelistAppTemporarilyForEvent(@NonNull String, int, @NonNull String);
    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
    field public static final int EVENT_MMS = 2; // 0x2