1 /* 2 * Copyright (c) 2023-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 FOUNDATION_ABILITY_ABILITY_RUNTIME_TEST_UNITTEST_EXTENSION_CONTROL_INTERCEPTOR_TEST_MOCK_STATUS_SINGLETON_H 17 #define FOUNDATION_ABILITY_ABILITY_RUNTIME_TEST_UNITTEST_EXTENSION_CONTROL_INTERCEPTOR_TEST_MOCK_STATUS_SINGLETON_H 18 19 #include <string> 20 #include <mutex> 21 #include <memory> 22 23 namespace OHOS { 24 namespace AAFwk { 25 26 /** 27 * @class StatusSingleton 28 * Singleton class that holds static member variables representing the status of extension configuration 29 * for testing purposes. 30 */ 31 class StatusSingleton { 32 public: 33 /** 34 * Get the singleton instance. 35 * 36 * @return The singleton instance of StatusSingleton. 37 */ GetInstance()38 static StatusSingleton& GetInstance() 39 { 40 static StatusSingleton instance; 41 return instance; 42 } 43 44 // Delete copy constructor and assignment operator 45 StatusSingleton(const StatusSingleton&) = delete; 46 StatusSingleton& operator=(const StatusSingleton&) = delete; 47 48 // Static member variables corresponding to the boolean functions in mock_extension_config.cpp 49 bool isExtensionStartThirdPartyAppEnable_; 50 bool isExtensionStartServiceEnable_; 51 bool isExtensionStartThirdPartyAppEnableNew_; 52 bool isExtensionStartServiceEnableNew_; 53 bool isExtensionStartDefaultEnable_; 54 bool isExtensionNetworkEnable_; 55 bool isExtensionSAEnable_; 56 bool isExtensionAbilityAccessEnable_; 57 bool checkExtensionUriValid_; 58 bool findTargetUriInList_; 59 bool readFileInfoJson_; 60 bool hasAbilityAccess_; 61 bool hasThridPartyAppAccessFlag_; 62 bool hasServiceAccessFlag_; 63 bool hasDefaultAccessFlag_; SetExtensionStartThirdPartyAppEnable(bool value)64 void SetExtensionStartThirdPartyAppEnable(bool value) 65 { 66 isExtensionStartThirdPartyAppEnable_ = value; 67 } 68 SetExtensionStartServiceEnable(bool value)69 void SetExtensionStartServiceEnable(bool value) 70 { 71 isExtensionStartServiceEnable_ = value; 72 } 73 SetExtensionStartThirdPartyAppEnableNew(bool value)74 void SetExtensionStartThirdPartyAppEnableNew(bool value) 75 { 76 isExtensionStartThirdPartyAppEnableNew_ = value; 77 } 78 SetExtensionStartServiceEnableNew(bool value)79 void SetExtensionStartServiceEnableNew(bool value) 80 { 81 isExtensionStartServiceEnableNew_ = value; 82 } 83 SetExtensionStartDefaultEnable(bool value)84 void SetExtensionStartDefaultEnable(bool value) 85 { 86 isExtensionStartDefaultEnable_ = value; 87 } 88 SetExtensionNetworkEnable(bool value)89 void SetExtensionNetworkEnable(bool value) 90 { 91 isExtensionNetworkEnable_ = value; 92 } 93 SetExtensionSAEnable(bool value)94 void SetExtensionSAEnable(bool value) 95 { 96 isExtensionSAEnable_ = value; 97 } 98 SetExtensionAbilityAccessEnable(bool value)99 void SetExtensionAbilityAccessEnable(bool value) 100 { 101 isExtensionAbilityAccessEnable_ = value; 102 } 103 SetCheckExtensionUriValid(bool value)104 void SetCheckExtensionUriValid(bool value) 105 { 106 checkExtensionUriValid_ = value; 107 } 108 SetFindTargetUriInList(bool value)109 void SetFindTargetUriInList(bool value) 110 { 111 findTargetUriInList_ = value; 112 } 113 SetReadFileInfoJson(bool value)114 void SetReadFileInfoJson(bool value) 115 { 116 readFileInfoJson_ = value; 117 } 118 SetHasAbilityAccess(bool value)119 void SetHasAbilityAccess(bool value) 120 { 121 hasAbilityAccess_ = value; 122 } 123 SetHasThridPartyAppAccessFlag(bool value)124 void SetHasThridPartyAppAccessFlag(bool value) 125 { 126 hasThridPartyAppAccessFlag_ = value; 127 } 128 SetHasServiceAccessFlag(bool value)129 void SetHasServiceAccessFlag(bool value) 130 { 131 hasServiceAccessFlag_ = value; 132 } 133 SetHasDefaultAccessFlag(bool value)134 void SetHasDefaultAccessFlag(bool value) 135 { 136 hasDefaultAccessFlag_ = value; 137 } 138 139 // Reset all static members to default values Reset()140 void Reset() 141 { 142 isExtensionStartThirdPartyAppEnable_ = false; 143 isExtensionStartServiceEnable_ = false; 144 isExtensionStartThirdPartyAppEnableNew_ = false; 145 isExtensionStartServiceEnableNew_ = false; 146 isExtensionStartDefaultEnable_ = false; 147 isExtensionNetworkEnable_ = false; 148 isExtensionSAEnable_ = false; 149 isExtensionAbilityAccessEnable_ = false; 150 checkExtensionUriValid_ = false; 151 findTargetUriInList_ = false; 152 readFileInfoJson_ = false; 153 hasAbilityAccess_ = false; 154 hasThridPartyAppAccessFlag_ = false; 155 hasServiceAccessFlag_ = false; 156 hasDefaultAccessFlag_ = false; 157 } 158 159 private: 160 // Private constructor to ensure singleton pattern StatusSingleton()161 StatusSingleton() 162 { 163 Reset(); 164 } 165 }; 166 } // namespace AAFwk 167 } // namespace OHOS 168 169 #endif // FOUNDATION_ABILITY_ABILITY_RUNTIME_TEST_UNITTEST_EXTENSION_CONTROL_INTERCEPTOR_TEST_MOCK_STATUS_SINGLETON_H