blob: e3b7cb9b4bb3f93fb1db7eda5ddac1309a95560f [file] [log] [blame]
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +00001/*
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 Park47f876b2018-04-17 13:56:46 +090020#ifndef __ANDROID_VNDK__
21
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000022#include <binder/IActivityManager.h>
Chong Zhanga7215d22020-11-10 12:11:15 -080023#include <android/app/ProcessStateEnum.h>
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000024
25#include <utils/threads.h>
26
27// ---------------------------------------------------------------------------
28namespace android {
29
Chong Zhanga7215d22020-11-10 12:11:15 -080030#define DECLARE_PROCESS_STATE(name) \
31 PROCESS_STATE_##name = (int32_t) app::ProcessStateEnum::name
32
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000033class ActivityManager
34{
35public:
36
37 enum {
Eric Laurent05595892018-10-18 14:56:24 -070038 // Flag for registerUidObserver: report uid state changed
39 UID_OBSERVER_PROCSTATE = 1<<0,
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000040 // 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 Zhanga7215d22020-11-10 12:11:15 -080048 // 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 Mahendran4d85b8c2017-11-02 14:43:38 +000050 enum {
Chong Zhanga7215d22020-11-10 12:11:15 -080051 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 Mahendran4d85b8c2017-11-02 14:43:38 +000073 };
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 Ganovfa851802018-03-27 17:17:46 -070083 bool isUidActive(const uid_t uid, const String16& callingPackage);
Eric Laurent05595892018-10-18 14:56:24 -070084 int getUidProcessState(const uid_t uid, const String16& callingPackage);
Chong Zhangb632bd52020-11-02 11:01:48 -080085 status_t checkPermission(const String16& permission, const pid_t pid, const uid_t uid, int32_t* outResult);
Rick Yiu68e261a2020-08-28 05:10:55 +000086
Chong Zhangb632bd52020-11-02 11:01:48 -080087 status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient);
Eino-Ville Talvalaae8b20d2018-03-20 11:05:23 -070088 status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient);
89
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000090private:
91 Mutex mLock;
92 sp<IActivityManager> mService;
93 sp<IActivityManager> getService();
94};
95
96
Steven Moreland6511af52019-09-26 16:05:45 -070097} // namespace android
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000098// ---------------------------------------------------------------------------
Jiyong Park47f876b2018-04-17 13:56:46 +090099#else // __ANDROID_VNDK__
100#error "This header is not visible to vendors"
101#endif // __ANDROID_VNDK__
102
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +0000103#endif // ANDROID_ACTIVITY_MANAGER_H