1 /* 2 * Copyright (C) 2019 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 com.android.server; 18 19 import android.annotation.Nullable; 20 import android.os.PowerExemptionManager; 21 import android.os.PowerExemptionManager.ReasonCode; 22 import android.os.PowerExemptionManager.TempAllowListType; 23 24 import com.android.server.deviceidle.IDeviceIdleConstraint; 25 26 public interface DeviceIdleInternal { onConstraintStateChanged(IDeviceIdleConstraint constraint, boolean active)27 void onConstraintStateChanged(IDeviceIdleConstraint constraint, boolean active); 28 registerDeviceIdleConstraint(IDeviceIdleConstraint constraint, String name, @IDeviceIdleConstraint.MinimumState int minState)29 void registerDeviceIdleConstraint(IDeviceIdleConstraint constraint, String name, 30 @IDeviceIdleConstraint.MinimumState int minState); 31 unregisterDeviceIdleConstraint(IDeviceIdleConstraint constraint)32 void unregisterDeviceIdleConstraint(IDeviceIdleConstraint constraint); 33 exitIdle(String reason)34 void exitIdle(String reason); 35 36 /** 37 * Same as {@link #addPowerSaveTempWhitelistApp(int, String, long, int, boolean, int, String)} 38 * with {@link PowerExemptionManager#TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED}. 39 */ addPowerSaveTempWhitelistApp(int callingUid, String packageName, long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason)40 void addPowerSaveTempWhitelistApp(int callingUid, String packageName, 41 long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, 42 @Nullable String reason); 43 44 /** 45 * Put a package in the temp-allowlist. 46 */ addPowerSaveTempWhitelistApp(int callingUid, String packageName, long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason)47 void addPowerSaveTempWhitelistApp(int callingUid, String packageName, 48 long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync, 49 @ReasonCode int reasonCode, @Nullable String reason); 50 51 /** 52 * Called by ActivityManagerService to directly add UID to DeviceIdleController's temp 53 * allowlist. 54 * @param uid 55 * @param duration duration in milliseconds 56 * @param type temp allowlist type defined at {@link TempAllowListType} 57 * @param sync 58 * @param reasonCode one of {@link ReasonCode} 59 * @param reason 60 * @param callingUid UID of app who added this temp-allowlist. 61 */ addPowerSaveTempWhitelistAppDirect(int uid, long duration, @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, @Nullable String reason, int callingUid)62 void addPowerSaveTempWhitelistAppDirect(int uid, long duration, 63 @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, 64 @Nullable String reason, int callingUid); 65 66 // duration in milliseconds getNotificationAllowlistDuration()67 long getNotificationAllowlistDuration(); 68 setJobsActive(boolean active)69 void setJobsActive(boolean active); 70 71 // Up-call from alarm manager. setAlarmsActive(boolean active)72 void setAlarmsActive(boolean active); 73 isAppOnWhitelist(int appid)74 boolean isAppOnWhitelist(int appid); 75 getPowerSaveWhitelistUserAppIds()76 int[] getPowerSaveWhitelistUserAppIds(); 77 getPowerSaveTempWhitelistAppIds()78 int[] getPowerSaveTempWhitelistAppIds(); 79 80 /** 81 * Listener to be notified when DeviceIdleController determines that the device has moved or is 82 * stationary. 83 */ 84 interface StationaryListener { onDeviceStationaryChanged(boolean isStationary)85 void onDeviceStationaryChanged(boolean isStationary); 86 } 87 88 /** 89 * Registers a listener that will be notified when the system has detected that the device is 90 * stationary or in motion. 91 */ registerStationaryListener(StationaryListener listener)92 void registerStationaryListener(StationaryListener listener); 93 94 /** 95 * Unregisters a registered stationary listener from being notified when the system has detected 96 * that the device is stationary or in motion. 97 */ unregisterStationaryListener(StationaryListener listener)98 void unregisterStationaryListener(StationaryListener listener); 99 100 /** 101 * Apply some restrictions on temp allowlist type based on the reasonCode. 102 * @param reasonCode temp allowlist reason code. 103 * @param defaultType default temp allowlist type if reasonCode can not decide a type. 104 * @return temp allowlist type based on the reasonCode. 105 */ getTempAllowListType(@easonCode int reasonCode, @TempAllowListType int defaultType)106 @TempAllowListType int getTempAllowListType(@ReasonCode int reasonCode, 107 @TempAllowListType int defaultType); 108 } 109