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

Commit af575b9f authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Temporarily whitelist an app for network during doze

API to allow an app to be whitelisted for network and wakelock
access for a short period. So even if the device is in idle
mode, such apps can be given a chance to download the payload
related to a high priority cloud-to-device message.

This API is meant for system apps only.

A new permission CHANGE_DEVICE_IDLE_TEMP_WHITELIST is required
to make this call.

Bug: 21525864
Change-Id: Id7a761a664f21af5d7ff55aa56e8df98d15511ca
parent 242b9c4e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ package android {
    field public static final java.lang.String CAPTURE_VIDEO_OUTPUT = "android.permission.CAPTURE_VIDEO_OUTPUT";
    field public static final java.lang.String CHANGE_COMPONENT_ENABLED_STATE = "android.permission.CHANGE_COMPONENT_ENABLED_STATE";
    field public static final java.lang.String CHANGE_CONFIGURATION = "android.permission.CHANGE_CONFIGURATION";
    field public static final java.lang.String CHANGE_DEVICE_IDLE_TEMP_WHITELIST = "android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST";
    field public static final java.lang.String CHANGE_NETWORK_STATE = "android.permission.CHANGE_NETWORK_STATE";
    field public static final java.lang.String CHANGE_WIFI_MULTICAST_STATE = "android.permission.CHANGE_WIFI_MULTICAST_STATE";
    field public static final java.lang.String CHANGE_WIFI_STATE = "android.permission.CHANGE_WIFI_STATE";
@@ -6331,6 +6332,7 @@ package android.app.usage {
    method public java.util.List<android.app.usage.ConfigurationStats> queryConfigurations(int, long, long);
    method public android.app.usage.UsageEvents queryEvents(long, long);
    method public java.util.List<android.app.usage.UsageStats> queryUsageStats(int, long, long);
    method public void whitelistAppTemporarily(java.lang.String, long, android.os.UserHandle);
    field public static final int INTERVAL_BEST = 4; // 0x4
    field public static final int INTERVAL_DAILY = 0; // 0x0
    field public static final int INTERVAL_MONTHLY = 2; // 0x2
+1 −0
Original line number Diff line number Diff line
@@ -32,4 +32,5 @@ interface IUsageStatsManager {
    UsageEvents queryEvents(long beginTime, long endTime, String callingPackage);
    void setAppInactive(String packageName, boolean inactive, int userId);
    boolean isAppInactive(String packageName, int userId);
    void whitelistAppTemporarily(String packageName, long duration, int userId);
}
+22 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app.usage;

import android.annotation.SystemApi;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.os.RemoteException;
@@ -245,4 +246,25 @@ public final class UsageStatsManager {
            // fall through
        }
    }

    /**
     * {@hide}
     * Temporarily whitelist the specified app for a short duration. This is to allow an app
     * receiving a high priority message to be able to access the network and acquire wakelocks
     * even if the device is in power-save mode or the app is currently considered inactive.
     * The caller must hold the CHANGE_DEVICE_IDLE_TEMP_WHITELIST permission.
     * @param packageName The package name of the app to whitelist.
     * @param duration Duration to whitelist the app for, in milliseconds. It is recommended that
     * this be limited to 10s of seconds. Requested duration will be clamped to a few minutes.
     * @param user The user for whom the package should be whitelisted. Passing in a user that is
     * not the same as the caller's process will require the INTERACT_ACROSS_USERS permission.
     * @see #isAppInactive(String)
     */
    @SystemApi
    public void whitelistAppTemporarily(String packageName, long duration, UserHandle user) {
        try {
            mService.whitelistAppTemporarily(packageName, duration, user.getIdentifier());
        } catch (RemoteException re) {
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.os;

import android.os.UserHandle;

/** @hide */
interface IDeviceIdleController {
    void addPowerSaveWhitelistApp(String name);
@@ -23,5 +25,7 @@ interface IDeviceIdleController {
    String[] getSystemPowerWhitelist();
    String[] getFullPowerWhitelist();
    int[] getAppIdWhitelist();
    int[] getAppIdTempWhitelist();
    boolean isPowerSaveWhitelistApp(String name);
    void addPowerSaveTempWhitelistApp(String name, long duration, int userId);
}
+8 −0
Original line number Diff line number Diff line
@@ -927,6 +927,14 @@ public final class PowerManager {
    public static final String ACTION_POWER_SAVE_WHITELIST_CHANGED
            = "android.os.action.POWER_SAVE_WHITELIST_CHANGED";

    /**
     * @hide Intent that is broadcast when the set of temporarily whitelisted apps has changed.
     * This broadcast is only sent to registered receivers.
     */
    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED
            = "android.os.action.POWER_SAVE_TEMP_WHITELIST_CHANGED";

    /**
     * Intent that is broadcast when the state of {@link #isPowerSaveMode()} is about to change.
     * This broadcast is only sent to registered receivers.
Loading