1 /* 2 * Copyright (C) 2020 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 #ifndef __AACTIVITYMANAGER_H__ 18 #define __AACTIVITYMANAGER_H__ 19 20 #include <sys/cdefs.h> 21 #include <sys/types.h> 22 23 __BEGIN_DECLS 24 25 struct AActivityManager_UidImportanceListener; 26 typedef struct AActivityManager_UidImportanceListener AActivityManager_UidImportanceListener; 27 28 /** 29 * Callback interface when Uid Importance has changed for a uid. 30 * 31 * This callback will be called on an arbitrary thread. Calls to a given listener will be 32 * serialized. 33 * 34 * @param uid the uid for which the importance has changed. 35 * @param uidImportance the new uidImportance for the uid. 36 * @cookie the same cookie when the UidImportanceListener was added. 37 * 38 * Introduced in API 31. 39 */ 40 typedef void (*AActivityManager_onUidImportance)(uid_t uid, int32_t uidImportance, void* cookie); 41 42 /** 43 * ActivityManager Uid Importance constants. 44 * 45 * Introduced in API 31. 46 */ 47 enum { 48 /** 49 * Constant for Uid Importance: This process is running the 50 * foreground UI; that is, it is the thing currently at the top of the screen 51 * that the user is interacting with. 52 */ 53 AACTIVITYMANAGER_IMPORTANCE_FOREGROUND = 100, 54 55 /** 56 * Constant for Uid Importance: This process is running a foreground 57 * service, for example to perform music playback even while the user is 58 * not immediately in the app. This generally indicates that the process 59 * is doing something the user actively cares about. 60 */ 61 AACTIVITYMANAGER_IMPORTANCE_FOREGROUND_SERVICE = 125, 62 63 /** 64 * Constant for Uid Importance: This process is running something 65 * that is actively visible to the user, though not in the immediate 66 * foreground. This may be running a window that is behind the current 67 * foreground (so paused and with its state saved, not interacting with 68 * the user, but visible to them to some degree); it may also be running 69 * other services under the system's control that it inconsiders important. 70 */ 71 AACTIVITYMANAGER_IMPORTANCE_VISIBLE = 200, 72 73 /** 74 * Constant for Uid Importance: This process is not something the user 75 * is directly aware of, but is otherwise perceptible to them to some degree. 76 */ 77 AACTIVITYMANAGER_IMPORTANCE_PERCEPTIBLE = 230, 78 79 /** 80 * Constant for Uid Importance: This process contains services 81 * that should remain running. These are background services apps have 82 * started, not something the user is aware of, so they may be killed by 83 * the system relatively freely (though it is generally desired that they 84 * stay running as long as they want to). 85 */ 86 AACTIVITYMANAGER_IMPORTANCE_SERVICE = 300, 87 88 /** 89 * Constant for Uid Importance: This process is running the foreground 90 * UI, but the device is asleep so it is not visible to the user. Though the 91 * system will try hard to keep its process from being killed, in all other 92 * ways we consider it a kind of cached process, with the limitations that go 93 * along with that state: network access, running background services, etc. 94 */ 95 AACTIVITYMANAGER_IMPORTANCE_TOP_SLEEPING = 325, 96 97 /** 98 * Constant for Uid Importance: This process is running an 99 * application that can not save its state, and thus can't be killed 100 * while in the background. This will be used with apps that have 101 * {@link android.R.attr#cantSaveState} set on their application tag. 102 */ 103 AACTIVITYMANAGER_IMPORTANCE_CANT_SAVE_STATE = 350, 104 105 /** 106 * Constant for Uid Importance: This process process contains 107 * cached code that is expendable, not actively running any app components 108 * we care about. 109 */ 110 AACTIVITYMANAGER_IMPORTANCE_CACHED = 400, 111 112 /** 113 * Constant for Uid Importance: This process does not exist. 114 */ 115 AACTIVITYMANAGER_IMPORTANCE_GONE = 1000, 116 }; 117 118 /** 119 * Adds a UidImportanceListener to the ActivityManager. 120 * 121 * This API requires android.Manifest.permission.PACKAGE_USAGE_STATS permission. 122 * 123 * @param onUidImportance the listener callback that will receive change reports. 124 * 125 * @param importanceCutpoint the level of importance in which the caller is interested 126 * in differences. For example, if AACTIVITYMANAGER_IMPORTANCE_PERCEPTIBLE is used 127 * here, you will receive a call each time a uid's importance transitions between being 128 * <= AACTIVITYMANAGER_IMPORTANCE_PERCEPTIBLE and > AACTIVITYMANAGER_IMPORTANCE_PERCEPTIBLE. 129 * 130 * @param cookie a cookie that will be passed back to the listener callback. 131 * 132 * @return an opaque pointer of AActivityManager_UidImportanceListener, or nullptr 133 * upon failure. Upon success, the returned AActivityManager_UidImportanceListener pointer 134 * must be removed and released through AActivityManager_removeUidImportanceListener. 135 */ 136 AActivityManager_UidImportanceListener* AActivityManager_addUidImportanceListener( 137 AActivityManager_onUidImportance onUidImportance, 138 int32_t importanceCutpoint, 139 void* cookie) __INTRODUCED_IN(31); 140 141 /** 142 * Removes a UidImportanceListener that was added with AActivityManager_addUidImportanceListener. 143 * 144 * When this returns, it's guaranteed the listener callback will no longer be invoked. 145 * 146 * @param listener the UidImportanceListener to be removed. 147 */ 148 void AActivityManager_removeUidImportanceListener( 149 AActivityManager_UidImportanceListener* listener) __INTRODUCED_IN(31); 150 151 /** 152 * Queries if a uid is currently active. 153 * 154 * This API requires android.Manifest.permission.PACKAGE_USAGE_STATS permission. 155 * 156 * @return true if the uid is active, false otherwise. 157 */ 158 bool AActivityManager_isUidActive(uid_t uid) __INTRODUCED_IN(31); 159 160 /** 161 * Queries the current Uid Importance value of a uid. 162 * 163 * This API requires android.Manifest.permission.PACKAGE_USAGE_STATS permission. 164 * 165 * @param uid the uid for which the importance value is queried. 166 * @return the current uid importance value for uid. 167 */ 168 int32_t AActivityManager_getUidImportance(uid_t uid) __INTRODUCED_IN(31); 169 170 __END_DECLS 171 172 #endif // __AACTIVITYMANAGER_H__ 173