• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.os;
18 
19 import android.annotation.NonNull;
20 import android.annotation.RequiresPermission;
21 import android.annotation.SystemApi;
22 import android.annotation.SystemService;
23 import android.annotation.TestApi;
24 import android.content.Context;
25 
26 /**
27  * Access to the service that keeps track of device idleness and drives low power mode based on
28  * that.
29  *
30  * @hide
31  */
32 @SystemApi
33 @SystemService(Context.DEVICE_IDLE_CONTROLLER)
34 public class DeviceIdleManager {
35     private final Context mContext;
36     private final IDeviceIdleController mService;
37 
38     /**
39      * @hide
40      */
DeviceIdleManager(@onNull Context context, @NonNull IDeviceIdleController service)41     public DeviceIdleManager(@NonNull Context context, @NonNull IDeviceIdleController service) {
42         mContext = context;
43         mService = service;
44     }
45 
getService()46     IDeviceIdleController getService() {
47         return mService;
48     }
49 
50     /**
51      * Ends any active idle session.
52      *
53      * @param reason The reason to end. Used for debugging purposes.
54      */
55     @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
endIdle(@onNull String reason)56     public void endIdle(@NonNull String reason) {
57         try {
58             mService.exitIdle(reason);
59         } catch (RemoteException e) {
60             throw e.rethrowFromSystemServer();
61         }
62     }
63 
64     /**
65      * @return package names the system has white-listed to opt out of power save restrictions,
66      * except for device idle mode.
67      *
68      * @hide Should be migrated to PowerExemptionManager
69      */
70     @TestApi
getSystemPowerWhitelistExceptIdle()71     public @NonNull String[] getSystemPowerWhitelistExceptIdle() {
72         try {
73             return mService.getSystemPowerWhitelistExceptIdle();
74         } catch (RemoteException e) {
75             throw e.rethrowFromSystemServer();
76         }
77     }
78 
79     /**
80      * @return package names the system has white-listed to opt out of power save restrictions for
81      * all modes.
82      *
83      * @hide Should be migrated to PowerExemptionManager
84      */
85     @TestApi
getSystemPowerWhitelist()86     public @NonNull String[] getSystemPowerWhitelist() {
87         try {
88             return mService.getSystemPowerWhitelist();
89         } catch (RemoteException e) {
90             throw e.rethrowFromSystemServer();
91         }
92     }
93 }
94