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