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 #pragma once 18 19 #ifndef __ANDROID_VNDK__ 20 21 #include <binder/IActivityManager.h> 22 #include <android/app/ProcessStateEnum.h> 23 24 #include <utils/threads.h> 25 26 // --------------------------------------------------------------------------- 27 namespace android { 28 29 #define DECLARE_PROCESS_STATE(name) \ 30 PROCESS_STATE_##name = (int32_t) app::ProcessStateEnum::name 31 32 class ActivityManager 33 { 34 public: 35 36 enum { 37 // Flag for registerUidObserver: report uid state changed 38 UID_OBSERVER_PROCSTATE = 1<<0, 39 // Flag for registerUidObserver: report uid gone 40 UID_OBSERVER_GONE = 1<<1, 41 // Flag for registerUidObserver: report uid has become idle 42 UID_OBSERVER_IDLE = 1<<2, 43 // Flag for registerUidObserver: report uid has become active 44 UID_OBSERVER_ACTIVE = 1<<3, 45 // Flag for registerUidObserver: report uid cached state has changed 46 UID_OBSERVER_CACHED = 1<<4, 47 // Flag for registerUidObserver: report uid capability has changed 48 UID_OBSERVER_CAPABILITY = 1<<5, 49 }; 50 51 // PROCESS_STATE_* must come from frameworks/base/core/java/android/app/ProcessStateEnum.aidl. 52 // This is to make sure that Java side uses the same values as native. 53 enum { 54 DECLARE_PROCESS_STATE(UNKNOWN), 55 DECLARE_PROCESS_STATE(PERSISTENT), 56 DECLARE_PROCESS_STATE(PERSISTENT_UI), 57 DECLARE_PROCESS_STATE(TOP), 58 DECLARE_PROCESS_STATE(BOUND_TOP), 59 DECLARE_PROCESS_STATE(FOREGROUND_SERVICE), 60 DECLARE_PROCESS_STATE(BOUND_FOREGROUND_SERVICE), 61 DECLARE_PROCESS_STATE(IMPORTANT_FOREGROUND), 62 DECLARE_PROCESS_STATE(IMPORTANT_BACKGROUND), 63 DECLARE_PROCESS_STATE(TRANSIENT_BACKGROUND), 64 DECLARE_PROCESS_STATE(BACKUP), 65 DECLARE_PROCESS_STATE(SERVICE), 66 DECLARE_PROCESS_STATE(RECEIVER), 67 DECLARE_PROCESS_STATE(TOP_SLEEPING), 68 DECLARE_PROCESS_STATE(HEAVY_WEIGHT), 69 DECLARE_PROCESS_STATE(HOME), 70 DECLARE_PROCESS_STATE(LAST_ACTIVITY), 71 DECLARE_PROCESS_STATE(CACHED_ACTIVITY), 72 DECLARE_PROCESS_STATE(CACHED_ACTIVITY_CLIENT), 73 DECLARE_PROCESS_STATE(CACHED_RECENT), 74 DECLARE_PROCESS_STATE(CACHED_EMPTY), 75 DECLARE_PROCESS_STATE(NONEXISTENT), 76 }; 77 78 ActivityManager(); 79 80 int openContentUri(const String16& stringUri); 81 status_t registerUidObserver(const sp<IUidObserver>& observer, 82 const int32_t event, 83 const int32_t cutpoint, 84 const String16& callingPackage); 85 status_t unregisterUidObserver(const sp<IUidObserver>& observer); 86 bool isUidActive(const uid_t uid, const String16& callingPackage); 87 int getUidProcessState(const uid_t uid, const String16& callingPackage); 88 status_t checkPermission(const String16& permission, const pid_t pid, const uid_t uid, int32_t* outResult); 89 90 status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); 91 status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient); 92 93 private: 94 Mutex mLock; 95 sp<IActivityManager> mService; 96 sp<IActivityManager> getService(); 97 }; 98 99 100 } // namespace android 101 // --------------------------------------------------------------------------- 102 #else // __ANDROID_VNDK__ 103 #error "This header is not visible to vendors" 104 #endif // __ANDROID_VNDK__ 105