Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2012 Mozilla Foundation |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | #ifndef GONKPERMISSION_H |
michael@0 | 17 | #define GONKPERMISSION_H |
michael@0 | 18 | |
michael@0 | 19 | #include <binder/BinderService.h> |
michael@0 | 20 | #include "nsString.h" |
michael@0 | 21 | #include "nsTArray.h" |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | class PermissionGrant |
michael@0 | 25 | { |
michael@0 | 26 | public: |
michael@0 | 27 | PermissionGrant(const char* perm, int32_t p) : mPid(p) |
michael@0 | 28 | { |
michael@0 | 29 | mPermission.Assign(perm); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | PermissionGrant(const nsACString& permission, int32_t pid) : mPid(pid), |
michael@0 | 33 | mPermission(permission) |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | bool operator==(const PermissionGrant& other) const |
michael@0 | 38 | { |
michael@0 | 39 | return (mPid == other.pid() && mPermission.Equals(other.permission())); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | int32_t pid() const |
michael@0 | 43 | { |
michael@0 | 44 | return mPid; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | const nsACString& permission() const |
michael@0 | 48 | { |
michael@0 | 49 | return mPermission; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | private: |
michael@0 | 53 | int32_t mPid; |
michael@0 | 54 | nsCString mPermission; |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | class PermissionGrant; |
michael@0 | 58 | |
michael@0 | 59 | class GonkPermissionService : |
michael@0 | 60 | public android::BinderService<GonkPermissionService>, |
michael@0 | 61 | public android::BnPermissionController |
michael@0 | 62 | { |
michael@0 | 63 | public: |
michael@0 | 64 | virtual ~GonkPermissionService() {} |
michael@0 | 65 | static GonkPermissionService* GetInstance(); |
michael@0 | 66 | static const char *getServiceName() { |
michael@0 | 67 | return "permission"; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | static void instantiate(); |
michael@0 | 71 | |
michael@0 | 72 | virtual android::status_t dump(int fd, const android::Vector<android::String16>& args) { |
michael@0 | 73 | return android::NO_ERROR; |
michael@0 | 74 | } |
michael@0 | 75 | virtual bool checkPermission(const android::String16& permission, int32_t pid, |
michael@0 | 76 | int32_t uid); |
michael@0 | 77 | |
michael@0 | 78 | void addGrantInfo(const char* permission, int32_t pid); |
michael@0 | 79 | private: |
michael@0 | 80 | GonkPermissionService(): android::BnPermissionController() {} |
michael@0 | 81 | nsTArray<PermissionGrant> mGrantArray; |
michael@0 | 82 | }; |
michael@0 | 83 | } // namespace mozilla |
michael@0 | 84 | #endif // GONKPERMISSION_H |