summaryrefslogtreecommitdiff
path: root/libs/binder/include_activitymanager/binder/ActivityManager.h
blob: b772b802274237e6f23efcbc3bb2b547f4e984a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#ifndef __ANDROID_VNDK__

#include <binder/IActivityManager.h>
#include <android/app/ProcessStateEnum.h>

#include <utils/threads.h>

// ---------------------------------------------------------------------------
namespace android {

#define DECLARE_PROCESS_STATE(name) \
    PROCESS_STATE_##name = (int32_t) app::ProcessStateEnum::name

class ActivityManager
{
public:

    enum {
        // Flag for registerUidObserver: report uid state changed
        UID_OBSERVER_PROCSTATE = 1<<0,
        // Flag for registerUidObserver: report uid gone
        UID_OBSERVER_GONE = 1<<1,
        // Flag for registerUidObserver: report uid has become idle
        UID_OBSERVER_IDLE = 1<<2,
        // Flag for registerUidObserver: report uid has become active
        UID_OBSERVER_ACTIVE = 1<<3,
        // Flag for registerUidObserver: report uid cached state has changed
        UID_OBSERVER_CACHED = 1<<4,
        // Flag for registerUidObserver: report uid capability has changed
        UID_OBSERVER_CAPABILITY = 1<<5,
    };

    // PROCESS_STATE_* must come from frameworks/base/core/java/android/app/ProcessStateEnum.aidl.
    // This is to make sure that Java side uses the same values as native.
    enum {
        DECLARE_PROCESS_STATE(UNKNOWN),
        DECLARE_PROCESS_STATE(PERSISTENT),
        DECLARE_PROCESS_STATE(PERSISTENT_UI),
        DECLARE_PROCESS_STATE(TOP),
        DECLARE_PROCESS_STATE(BOUND_TOP),
        DECLARE_PROCESS_STATE(FOREGROUND_SERVICE),
        DECLARE_PROCESS_STATE(BOUND_FOREGROUND_SERVICE),
        DECLARE_PROCESS_STATE(IMPORTANT_FOREGROUND),
        DECLARE_PROCESS_STATE(IMPORTANT_BACKGROUND),
        DECLARE_PROCESS_STATE(TRANSIENT_BACKGROUND),
        DECLARE_PROCESS_STATE(BACKUP),
        DECLARE_PROCESS_STATE(SERVICE),
        DECLARE_PROCESS_STATE(RECEIVER),
        DECLARE_PROCESS_STATE(TOP_SLEEPING),
        DECLARE_PROCESS_STATE(HEAVY_WEIGHT),
        DECLARE_PROCESS_STATE(HOME),
        DECLARE_PROCESS_STATE(LAST_ACTIVITY),
        DECLARE_PROCESS_STATE(CACHED_ACTIVITY),
        DECLARE_PROCESS_STATE(CACHED_ACTIVITY_CLIENT),
        DECLARE_PROCESS_STATE(CACHED_RECENT),
        DECLARE_PROCESS_STATE(CACHED_EMPTY),
        DECLARE_PROCESS_STATE(NONEXISTENT),
    };

    ActivityManager();

    int openContentUri(const String16& stringUri);
    status_t registerUidObserver(const sp<IUidObserver>& observer,
                             const int32_t event,
                             const int32_t cutpoint,
                             const String16& callingPackage);
    status_t unregisterUidObserver(const sp<IUidObserver>& observer);
    bool isUidActive(const uid_t uid, const String16& callingPackage);
    int getUidProcessState(const uid_t uid, const String16& callingPackage);
    status_t checkPermission(const String16& permission, const pid_t pid, const uid_t uid, int32_t* outResult);

    status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient);
    status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient);

private:
    Mutex mLock;
    sp<IActivityManager> mService;
    sp<IActivityManager> getService();
};


} // namespace android
// ---------------------------------------------------------------------------
#else // __ANDROID_VNDK__
#error "This header is not visible to vendors"
#endif // __ANDROID_VNDK__