1 /* 2 * Copyright (c) 2024 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 ACCESSTOKEN_CONFIG_POLICY_LOADER_H 17 #define ACCESSTOKEN_CONFIG_POLICY_LOADER_H 18 19 #include <string> 20 #include <vector> 21 22 namespace OHOS { 23 namespace Security { 24 namespace AccessToken { 25 const static std::string CONFIG_POLICY_LIBPATH = "libaccesstoken_config_policy.z.so"; 26 struct AccessTokenServiceConfig final { 27 std::string grantBundleName; 28 std::string grantAbilityName; 29 std::string grantServiceAbilityName; 30 std::string permStateAbilityName; 31 std::string globalSwitchAbilityName; 32 int32_t cancleTime; 33 }; 34 35 struct PrivacyServiceConfig final { 36 int32_t sizeMaxImum; 37 int32_t agingTime; 38 std::string globalDialogBundleName; 39 std::string globalDialogAbilityName; 40 }; 41 42 struct TokenSyncServiceConfig final { 43 int32_t sendRequestRepeatTimes; 44 }; 45 46 struct AccessTokenConfigValue { 47 AccessTokenServiceConfig atConfig; 48 PrivacyServiceConfig pConfig; 49 TokenSyncServiceConfig tsConfig; 50 }; 51 52 enum ServiceType { 53 ACCESSTOKEN_SERVICE = 0, 54 PRIVACY_SERVICE, 55 TOKENSYNC_SERVICE, 56 }; 57 58 class ConfigPolicyLoaderInterface { 59 public: ConfigPolicyLoaderInterface()60 ConfigPolicyLoaderInterface() {} ~ConfigPolicyLoaderInterface()61 virtual ~ConfigPolicyLoaderInterface() {} 62 virtual bool GetConfigValue(const ServiceType& type, AccessTokenConfigValue& config); 63 }; 64 65 class ConfigPolicLoader final: public ConfigPolicyLoaderInterface { 66 bool GetConfigValue(const ServiceType& type, AccessTokenConfigValue& config); 67 private: 68 #ifdef CUSTOMIZATION_CONFIG_POLICY_ENABLE 69 void GetConfigFilePathList(std::vector<std::string>& pathList); 70 bool GetConfigValueFromFile(const ServiceType& type, const std::string& fileContent, 71 AccessTokenConfigValue& config); 72 #endif // CUSTOMIZATION_CONFIG_POLICY_ENABLE 73 }; 74 75 #ifdef __cplusplus 76 extern "C" { 77 #endif 78 void* Create(); 79 void Destroy(void* loaderPtr); 80 #ifdef __cplusplus 81 } 82 #endif 83 } // namespace AccessToken 84 } // namespace Security 85 } // namespace OHOS 86 #endif // ACCESSTOKEN_CONFIG_POLICY_LOADER_H