1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PERMISSION_VALIDATOR_H 17 #define PERMISSION_VALIDATOR_H 18 #include <set> 19 #include <string> 20 #include "types.h" 21 #include "visibility.h" 22 23 namespace OHOS { 24 namespace DistributedKv { 25 // Compare function for kvStoreTupleMap_. 26 struct KvStoreTupleCmp { operatorKvStoreTupleCmp27 bool operator()(const KvStoreTuple &lKey, const KvStoreTuple &rKey) const 28 { 29 if (lKey.userId != rKey.userId) { 30 return lKey.userId < rKey.userId; 31 } 32 if (lKey.appId != rKey.appId) { 33 return lKey.appId < rKey.appId; 34 } 35 if (lKey.storeId != rKey.storeId) { 36 return lKey.storeId < rKey.storeId; 37 } 38 39 return false; 40 } 41 }; 42 43 class PermissionValidator { 44 public: 45 // check whether the client process have enough privilege to share data with the other devices. 46 // uid: client process uid 47 KVSTORE_API static bool CheckSyncPermission(const std::string &userId, const std::string &appId, 48 std::int32_t uid = 0); 49 50 KVSTORE_API static bool RegisterPermissionChanged( 51 const KvStoreTuple &kvStoreTuple, const AppThreadInfo &appThreadInfo); 52 53 KVSTORE_API static void UnregisterPermissionChanged(const KvStoreTuple &kvStoreTuple); 54 55 KVSTORE_API static void UpdateKvStoreTupleMap(const KvStoreTuple &srcKvStoreTuple, 56 const KvStoreTuple &dstKvStoreTuple); 57 58 // Check whether the bundle name is in the system service list. 59 KVSTORE_API static bool IsSystemService(const std::string &bundleName); 60 61 // Check whether the app with this bundle name is auto launch enabled. 62 KVSTORE_API static bool IsAutoLaunchEnabled(const std::string &bundleName); 63 64 private: 65 static std::set<std::string> systemServiceList_; // the full list for system services. 66 static std::set<std::string> autoLaunchEnableList_; // the list for auto launch enabled app. 67 }; 68 } // namespace DistributedKv 69 } // namespace OHOS 70 #endif // PERMISSION_VALIDATOR_H 71