Home | History | Annotate | Download | only in binder
      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 <utils/Vector.h>
     23 #include <utils/String16.h>
     24 
     25 namespace android {
     26 
     27 // ----------------------------------------------------------------------
     28 
     29 class IServiceManager : public IInterface
     30 {
     31 public:
     32     DECLARE_META_INTERFACE(ServiceManager)
     33     /**
     34      * Must match values in IServiceManager.java
     35      */
     36     /* Allows services to dump sections according to priorities. */
     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     /**
     41      * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the
     42      * same priority as NORMAL priority but the services are not called with dump priority
     43      * arguments.
     44      */
     45     static const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3;
     46     static const int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL |
     47             DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
     48     static const int DUMP_FLAG_PROTO = 1 << 4;
     49 
     50     /**
     51      * Retrieve an existing service, blocking for a few seconds
     52      * if it doesn't yet exist.
     53      */
     54     virtual sp<IBinder>         getService( const String16& name) const = 0;
     55 
     56     /**
     57      * Retrieve an existing service, non-blocking.
     58      */
     59     virtual sp<IBinder>         checkService( const String16& name) const = 0;
     60 
     61     /**
     62      * Register a service.
     63      */
     64     virtual status_t addService(const String16& name, const sp<IBinder>& service,
     65                                 bool allowIsolated = false,
     66                                 int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) = 0;
     67 
     68     /**
     69      * Return list of all existing services.
     70      */
     71     virtual Vector<String16> listServices(int dumpsysFlags = DUMP_FLAG_PRIORITY_ALL) = 0;
     72 
     73     enum {
     74         GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
     75         CHECK_SERVICE_TRANSACTION,
     76         ADD_SERVICE_TRANSACTION,
     77         LIST_SERVICES_TRANSACTION,
     78     };
     79 };
     80 
     81 sp<IServiceManager> defaultServiceManager();
     82 
     83 template<typename INTERFACE>
     84 status_t getService(const String16& name, sp<INTERFACE>* outService)
     85 {
     86     const sp<IServiceManager> sm = defaultServiceManager();
     87     if (sm != NULL) {
     88         *outService = interface_cast<INTERFACE>(sm->getService(name));
     89         if ((*outService) != NULL) return NO_ERROR;
     90     }
     91     return NAME_NOT_FOUND;
     92 }
     93 
     94 bool checkCallingPermission(const String16& permission);
     95 bool checkCallingPermission(const String16& permission,
     96                             int32_t* outPid, int32_t* outUid);
     97 bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
     98 
     99 }; // namespace android
    100 
    101 #endif // ANDROID_ISERVICE_MANAGER_H
    102 
    103