| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 ANDROID_ACTIVITY_MANAGER_H |
| 18 | #define ANDROID_ACTIVITY_MANAGER_H |
| 19 | |
| Jiyong Park | 47f876b | 2018-04-17 13:56:46 +0900 | [diff] [blame] | 20 | #ifndef __ANDROID_VNDK__ |
| 21 | |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 22 | #include <binder/IActivityManager.h> |
| Chong Zhang | a7215d2 | 2020-11-10 12:11:15 -0800 | [diff] [blame^] | 23 | #include <android/app/ProcessStateEnum.h> |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 24 | |
| 25 | #include <utils/threads.h> |
| 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | namespace android { |
| 29 | |
| Chong Zhang | a7215d2 | 2020-11-10 12:11:15 -0800 | [diff] [blame^] | 30 | #define DECLARE_PROCESS_STATE(name) \ |
| 31 | PROCESS_STATE_##name = (int32_t) app::ProcessStateEnum::name |
| 32 | |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 33 | class ActivityManager |
| 34 | { |
| 35 | public: |
| 36 | |
| 37 | enum { |
| Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 38 | // Flag for registerUidObserver: report uid state changed |
| 39 | UID_OBSERVER_PROCSTATE = 1<<0, |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 40 | // Flag for registerUidObserver: report uid gone |
| 41 | UID_OBSERVER_GONE = 1<<1, |
| 42 | // Flag for registerUidObserver: report uid has become idle |
| 43 | UID_OBSERVER_IDLE = 1<<2, |
| 44 | // Flag for registerUidObserver: report uid has become active |
| 45 | UID_OBSERVER_ACTIVE = 1<<3 |
| 46 | }; |
| 47 | |
| Chong Zhang | a7215d2 | 2020-11-10 12:11:15 -0800 | [diff] [blame^] | 48 | // PROCESS_STATE_* must come from frameworks/base/core/java/android/app/ProcessStateEnum.aidl. |
| 49 | // This is to make sure that Java side uses the same values as native. |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 50 | enum { |
| Chong Zhang | a7215d2 | 2020-11-10 12:11:15 -0800 | [diff] [blame^] | 51 | DECLARE_PROCESS_STATE(UNKNOWN), |
| 52 | DECLARE_PROCESS_STATE(PERSISTENT), |
| 53 | DECLARE_PROCESS_STATE(PERSISTENT_UI), |
| 54 | DECLARE_PROCESS_STATE(TOP), |
| 55 | DECLARE_PROCESS_STATE(BOUND_TOP), |
| 56 | DECLARE_PROCESS_STATE(FOREGROUND_SERVICE), |
| 57 | DECLARE_PROCESS_STATE(BOUND_FOREGROUND_SERVICE), |
| 58 | DECLARE_PROCESS_STATE(IMPORTANT_FOREGROUND), |
| 59 | DECLARE_PROCESS_STATE(IMPORTANT_BACKGROUND), |
| 60 | DECLARE_PROCESS_STATE(TRANSIENT_BACKGROUND), |
| 61 | DECLARE_PROCESS_STATE(BACKUP), |
| 62 | DECLARE_PROCESS_STATE(SERVICE), |
| 63 | DECLARE_PROCESS_STATE(RECEIVER), |
| 64 | DECLARE_PROCESS_STATE(TOP_SLEEPING), |
| 65 | DECLARE_PROCESS_STATE(HEAVY_WEIGHT), |
| 66 | DECLARE_PROCESS_STATE(HOME), |
| 67 | DECLARE_PROCESS_STATE(LAST_ACTIVITY), |
| 68 | DECLARE_PROCESS_STATE(CACHED_ACTIVITY), |
| 69 | DECLARE_PROCESS_STATE(CACHED_ACTIVITY_CLIENT), |
| 70 | DECLARE_PROCESS_STATE(CACHED_RECENT), |
| 71 | DECLARE_PROCESS_STATE(CACHED_EMPTY), |
| 72 | DECLARE_PROCESS_STATE(NONEXISTENT), |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | ActivityManager(); |
| 76 | |
| 77 | int openContentUri(const String16& stringUri); |
| 78 | void registerUidObserver(const sp<IUidObserver>& observer, |
| 79 | const int32_t event, |
| 80 | const int32_t cutpoint, |
| 81 | const String16& callingPackage); |
| 82 | void unregisterUidObserver(const sp<IUidObserver>& observer); |
| Svet Ganov | fa85180 | 2018-03-27 17:17:46 -0700 | [diff] [blame] | 83 | bool isUidActive(const uid_t uid, const String16& callingPackage); |
| Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 84 | int getUidProcessState(const uid_t uid, const String16& callingPackage); |
| Chong Zhang | b632bd5 | 2020-11-02 11:01:48 -0800 | [diff] [blame] | 85 | status_t checkPermission(const String16& permission, const pid_t pid, const uid_t uid, int32_t* outResult); |
| Rick Yiu | 68e261a | 2020-08-28 05:10:55 +0000 | [diff] [blame] | 86 | |
| Chong Zhang | b632bd5 | 2020-11-02 11:01:48 -0800 | [diff] [blame] | 87 | status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); |
| Eino-Ville Talvala | ae8b20d | 2018-03-20 11:05:23 -0700 | [diff] [blame] | 88 | status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient); |
| 89 | |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 90 | private: |
| 91 | Mutex mLock; |
| 92 | sp<IActivityManager> mService; |
| 93 | sp<IActivityManager> getService(); |
| 94 | }; |
| 95 | |
| 96 | |
| Steven Moreland | 6511af5 | 2019-09-26 16:05:45 -0700 | [diff] [blame] | 97 | } // namespace android |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 98 | // --------------------------------------------------------------------------- |
| Jiyong Park | 47f876b | 2018-04-17 13:56:46 +0900 | [diff] [blame] | 99 | #else // __ANDROID_VNDK__ |
| 100 | #error "This header is not visible to vendors" |
| 101 | #endif // __ANDROID_VNDK__ |
| 102 | |
| Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 103 | #endif // ANDROID_ACTIVITY_MANAGER_H |