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