blob: 0568beb34e084ddf385594276857a3cea2302656 [file] [log] [blame]
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.os;
18
19import android.annotation.NonNull;
Kweku Adamsc2400c82019-10-09 15:56:04 -070020import android.annotation.RequiresPermission;
Philip P. Moltmannf80809f2018-04-04 11:20:44 -070021import android.annotation.SystemService;
22import android.annotation.TestApi;
23import android.content.Context;
24
Kweku Adamsc2400c82019-10-09 15:56:04 -070025import java.util.List;
26
Philip P. Moltmannf80809f2018-04-04 11:20:44 -070027/**
28 * Access to the service that keeps track of device idleness and drives low power mode based on
29 * that.
30 *
31 * @hide
32 */
33@TestApi
34@SystemService(Context.DEVICE_IDLE_CONTROLLER)
35public class DeviceIdleManager {
36 private final Context mContext;
37 private final IDeviceIdleController mService;
38
39 /**
40 * @hide
41 */
42 public DeviceIdleManager(@NonNull Context context, @NonNull IDeviceIdleController service) {
43 mContext = context;
44 mService = service;
45 }
46
47 /**
48 * @return package names the system has white-listed to opt out of power save restrictions,
49 * except for device idle mode.
50 */
51 public @NonNull String[] getSystemPowerWhitelistExceptIdle() {
52 try {
53 return mService.getSystemPowerWhitelistExceptIdle();
54 } catch (RemoteException e) {
55 e.rethrowFromSystemServer();
56 return new String[0];
57 }
58 }
59
60 /**
61 * @return package names the system has white-listed to opt out of power save restrictions for
62 * all modes.
63 */
64 public @NonNull String[] getSystemPowerWhitelist() {
65 try {
66 return mService.getSystemPowerWhitelist();
67 } catch (RemoteException e) {
68 e.rethrowFromSystemServer();
69 return new String[0];
70 }
71 }
Kweku Adamsc2400c82019-10-09 15:56:04 -070072
73 /**
74 * Add the specified packages to the power save whitelist.
75 *
76 * @return the number of packages that were successfully added to the whitelist
77 */
78 @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
79 public int addPowerSaveWhitelistApps(@NonNull List<String> packageNames) {
80 try {
81 return mService.addPowerSaveWhitelistApps(packageNames);
82 } catch (RemoteException e) {
83 e.rethrowFromSystemServer();
84 return 0;
85 }
86 }
Makoto Onuki152742f2019-10-31 17:22:26 -070087
88 /**
89 * Return whether a given package is in the power-save whitelist or not.
90 * @hide
91 */
92 public boolean isApplicationWhitelisted(@NonNull String packageName) {
93 try {
94 return mService.isPowerSaveWhitelistApp(packageName);
95 } catch (RemoteException e) {
96 e.rethrowFromSystemServer();
97 return false;
98 }
99 }
Philip P. Moltmannf80809f2018-04-04 11:20:44 -0700100}