IServiceManager.h revision 6a40853e06f5274d84b0fc66e349a36510d1497f
1/*
2 * Copyright (C) 2005 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//
18#ifndef ANDROID_ISERVICE_MANAGER_H
19#define ANDROID_ISERVICE_MANAGER_H
20
21#include <binder/IInterface.h>
22#include <binder/IPermissionController.h>
23#include <utils/Vector.h>
24#include <utils/String16.h>
25
26namespace android {
27
28// ----------------------------------------------------------------------
29
30class IServiceManager : public IInterface
31{
32public:
33    DECLARE_META_INTERFACE(ServiceManager)
34    /*
35     * Must match values in IServiceManager.java
36     */
37    static const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0;
38    static const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1;
39    static const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2;
40    static const int DUMP_FLAG_PRIORITY_ALL =
41            DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL;
42    static const int DUMP_FLAG_PROTO = 1 << 3;
43
44    /**
45     * Retrieve an existing service, blocking for a few seconds
46     * if it doesn't yet exist.
47     */
48    virtual sp<IBinder>         getService( const String16& name) const = 0;
49
50    /**
51     * Retrieve an existing service, non-blocking.
52     */
53    virtual sp<IBinder>         checkService( const String16& name) const = 0;
54
55    /**
56     * Register a service.
57     */
58    virtual status_t addService(const String16& name, const sp<IBinder>& service,
59                                bool allowIsolated = false,
60                                int dumpsysFlags = DUMP_FLAG_PRIORITY_NORMAL) = 0;
61
62    /**
63     * Return list of all existing services.
64     */
65    virtual Vector<String16> listServices(int dumpsysFlags = DUMP_FLAG_PRIORITY_ALL) = 0;
66
67    enum {
68        GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
69        CHECK_SERVICE_TRANSACTION,
70        ADD_SERVICE_TRANSACTION,
71        LIST_SERVICES_TRANSACTION,
72    };
73};
74
75sp<IServiceManager> defaultServiceManager();
76
77template<typename INTERFACE>
78status_t getService(const String16& name, sp<INTERFACE>* outService)
79{
80    const sp<IServiceManager> sm = defaultServiceManager();
81    if (sm != NULL) {
82        *outService = interface_cast<INTERFACE>(sm->getService(name));
83        if ((*outService) != NULL) return NO_ERROR;
84    }
85    return NAME_NOT_FOUND;
86}
87
88bool checkCallingPermission(const String16& permission);
89bool checkCallingPermission(const String16& permission,
90                            int32_t* outPid, int32_t* outUid);
91bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
92
93}; // namespace android
94
95#endif // ANDROID_ISERVICE_MANAGER_H
96
97