1 /* 2 * Copyright (C) 2009 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 BINDER_PERMISSION_H 18 #define BINDER_PERMISSION_H 19 20 #include <stdint.h> 21 #include <unistd.h> 22 23 #include <utils/SortedVector.h> 24 #include <utils/String16.h> 25 #include <utils/threads.h> 26 27 namespace android { 28 // --------------------------------------------------------------------------- 29 30 /* 31 * Permission caches the result of the permission check for the given 32 * permission name and the provided uid/pid. It also handles a few 33 * known cases efficiently (caller is in the same process or is root). 34 * The package manager does something similar but lives in dalvik world 35 * and is therefore extremely slow to access. 36 */ 37 38 class Permission 39 { 40 public: 41 Permission(char const* name); 42 Permission(const String16& name); 43 Permission(const Permission& rhs); 44 virtual ~Permission(); 45 46 bool operator < (const Permission& rhs) const; 47 48 // checks the current binder call's caller has access to this permission 49 bool checkCalling() const; 50 51 // checks the specified pid/uid has access to this permission 52 bool check(pid_t pid, uid_t uid) const; 53 54 protected: 55 virtual bool doCheckPermission(pid_t pid, uid_t uid) const; 56 57 private: 58 Permission& operator = (const Permission& rhs) const; 59 const String16 mPermissionName; 60 mutable SortedVector<uid_t> mGranted; 61 const pid_t mPid; 62 mutable Mutex mLock; 63 }; 64 65 // --------------------------------------------------------------------------- 66 }; // namespace android 67 68 #endif /* BINDER_PERMISSION_H */ 69