1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/GonkPermission.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* 1.5 + * Copyright (C) 2012 Mozilla Foundation 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 +#ifndef GONKPERMISSION_H 1.20 +#define GONKPERMISSION_H 1.21 + 1.22 +#include <binder/BinderService.h> 1.23 +#include "nsString.h" 1.24 +#include "nsTArray.h" 1.25 + 1.26 +namespace mozilla { 1.27 +class PermissionGrant 1.28 +{ 1.29 +public: 1.30 + PermissionGrant(const char* perm, int32_t p) : mPid(p) 1.31 + { 1.32 + mPermission.Assign(perm); 1.33 + } 1.34 + 1.35 + PermissionGrant(const nsACString& permission, int32_t pid) : mPid(pid), 1.36 + mPermission(permission) 1.37 + { 1.38 + } 1.39 + 1.40 + bool operator==(const PermissionGrant& other) const 1.41 + { 1.42 + return (mPid == other.pid() && mPermission.Equals(other.permission())); 1.43 + } 1.44 + 1.45 + int32_t pid() const 1.46 + { 1.47 + return mPid; 1.48 + } 1.49 + 1.50 + const nsACString& permission() const 1.51 + { 1.52 + return mPermission; 1.53 + } 1.54 + 1.55 +private: 1.56 + int32_t mPid; 1.57 + nsCString mPermission; 1.58 +}; 1.59 + 1.60 +class PermissionGrant; 1.61 + 1.62 +class GonkPermissionService : 1.63 + public android::BinderService<GonkPermissionService>, 1.64 + public android::BnPermissionController 1.65 +{ 1.66 +public: 1.67 + virtual ~GonkPermissionService() {} 1.68 + static GonkPermissionService* GetInstance(); 1.69 + static const char *getServiceName() { 1.70 + return "permission"; 1.71 + } 1.72 + 1.73 + static void instantiate(); 1.74 + 1.75 + virtual android::status_t dump(int fd, const android::Vector<android::String16>& args) { 1.76 + return android::NO_ERROR; 1.77 + } 1.78 + virtual bool checkPermission(const android::String16& permission, int32_t pid, 1.79 + int32_t uid); 1.80 + 1.81 + void addGrantInfo(const char* permission, int32_t pid); 1.82 +private: 1.83 + GonkPermissionService(): android::BnPermissionController() {} 1.84 + nsTArray<PermissionGrant> mGrantArray; 1.85 +}; 1.86 +} // namespace mozilla 1.87 +#endif // GONKPERMISSION_H