blob: 830971b1e679750cc87b29e6af9aab8160c1356a [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
Steven Morelandc7a871e2020-11-10 21:56:57 +000017#pragma once
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000018
Jiyong Park47f876b2018-04-17 13:56:46 +090019#ifndef __ANDROID_VNDK__
20
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000021#include <binder/IActivityManager.h>
Chong Zhanga7215d22020-11-10 12:11:15 -080022#include <android/app/ProcessStateEnum.h>
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000023
24#include <utils/threads.h>
25
26// ---------------------------------------------------------------------------
27namespace android {
28
Chong Zhanga7215d22020-11-10 12:11:15 -080029#define DECLARE_PROCESS_STATE(name) \
30 PROCESS_STATE_##name = (int32_t) app::ProcessStateEnum::name
31
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000032class ActivityManager
33{
34public:
35
36 enum {
Eric Laurent05595892018-10-18 14:56:24 -070037 // Flag for registerUidObserver: report uid state changed
38 UID_OBSERVER_PROCSTATE = 1<<0,
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000039 // 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 };
46
Chong Zhanga7215d22020-11-10 12:11:15 -080047 // PROCESS_STATE_* must come from frameworks/base/core/java/android/app/ProcessStateEnum.aidl.
48 // This is to make sure that Java side uses the same values as native.
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000049 enum {
Chong Zhanga7215d22020-11-10 12:11:15 -080050 DECLARE_PROCESS_STATE(UNKNOWN),
51 DECLARE_PROCESS_STATE(PERSISTENT),
52 DECLARE_PROCESS_STATE(PERSISTENT_UI),
53 DECLARE_PROCESS_STATE(TOP),
54 DECLARE_PROCESS_STATE(BOUND_TOP),
55 DECLARE_PROCESS_STATE(FOREGROUND_SERVICE),
56 DECLARE_PROCESS_STATE(BOUND_FOREGROUND_SERVICE),
57 DECLARE_PROCESS_STATE(IMPORTANT_FOREGROUND),
58 DECLARE_PROCESS_STATE(IMPORTANT_BACKGROUND),
59 DECLARE_PROCESS_STATE(TRANSIENT_BACKGROUND),
60 DECLARE_PROCESS_STATE(BACKUP),
61 DECLARE_PROCESS_STATE(SERVICE),
62 DECLARE_PROCESS_STATE(RECEIVER),
63 DECLARE_PROCESS_STATE(TOP_SLEEPING),
64 DECLARE_PROCESS_STATE(HEAVY_WEIGHT),
65 DECLARE_PROCESS_STATE(HOME),
66 DECLARE_PROCESS_STATE(LAST_ACTIVITY),
67 DECLARE_PROCESS_STATE(CACHED_ACTIVITY),
68 DECLARE_PROCESS_STATE(CACHED_ACTIVITY_CLIENT),
69 DECLARE_PROCESS_STATE(CACHED_RECENT),
70 DECLARE_PROCESS_STATE(CACHED_EMPTY),
71 DECLARE_PROCESS_STATE(NONEXISTENT),
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000072 };
73
74 ActivityManager();
75
76 int openContentUri(const String16& stringUri);
Chong Zhang15765342020-11-17 14:44:20 -080077 status_t registerUidObserver(const sp<IUidObserver>& observer,
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000078 const int32_t event,
79 const int32_t cutpoint,
80 const String16& callingPackage);
Chong Zhang15765342020-11-17 14:44:20 -080081 status_t unregisterUidObserver(const sp<IUidObserver>& observer);
Svet Ganovfa851802018-03-27 17:17:46 -070082 bool isUidActive(const uid_t uid, const String16& callingPackage);
Eric Laurent05595892018-10-18 14:56:24 -070083 int getUidProcessState(const uid_t uid, const String16& callingPackage);
Chong Zhangb632bd52020-11-02 11:01:48 -080084 status_t checkPermission(const String16& permission, const pid_t pid, const uid_t uid, int32_t* outResult);
Rick Yiu68e261a2020-08-28 05:10:55 +000085
Chong Zhangb632bd52020-11-02 11:01:48 -080086 status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient);
Eino-Ville Talvalaae8b20d2018-03-20 11:05:23 -070087 status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient);
88
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000089private:
90 Mutex mLock;
91 sp<IActivityManager> mService;
92 sp<IActivityManager> getService();
93};
94
95
Steven Moreland6511af52019-09-26 16:05:45 -070096} // namespace android
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000097// ---------------------------------------------------------------------------
Jiyong Park47f876b2018-04-17 13:56:46 +090098#else // __ANDROID_VNDK__
99#error "This header is not visible to vendors"
100#endif // __ANDROID_VNDK__