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 #ifndef INTERFACES_ACCESSTOKEN_KITS_NAPI_REQUEST_GLOBAL_SWITCHN_ON_SETTING_H 16 #define INTERFACES_ACCESSTOKEN_KITS_NAPI_REQUEST_GLOBAL_SWITCHN_ON_SETTING_H 17 18 #ifdef EVENTHANDLER_ENABLE 19 #include "event_handler.h" 20 #include "event_queue.h" 21 #endif 22 #include "napi_context_common.h" 23 #include "permission_grant_info.h" 24 #include "ui_content.h" 25 #include "ui_extension_context.h" 26 27 namespace OHOS { 28 namespace Security { 29 namespace AccessToken { 30 typedef enum { 31 CAMERA = 0, 32 MICROPHONE = 1, 33 LOCATION = 2, 34 } SwitchType; 35 36 struct RequestGlobalSwitchAsyncContext : public AtManagerAsyncWorkData { RequestGlobalSwitchAsyncContextRequestGlobalSwitchAsyncContext37 explicit RequestGlobalSwitchAsyncContext(napi_env env) : AtManagerAsyncWorkData(env) 38 { 39 this->env = env; 40 } 41 42 AccessTokenID tokenId = 0; 43 int32_t result = RET_SUCCESS; 44 PermissionGrantInfo info; 45 int32_t resultCode = -1; 46 int32_t switchType = -1; 47 napi_value requestResult = nullptr; 48 int32_t errorCode = -1; 49 bool switchStatus = false; 50 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext; 51 std::shared_ptr<AbilityRuntime::UIExtensionContext> uiExtensionContext; 52 bool uiAbilityFlag = false; 53 bool releaseFlag = false; 54 #ifdef EVENTHANDLER_ENABLE 55 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 56 #endif 57 }; 58 59 struct RequestGlobalSwitchAsyncContextHandle { RequestGlobalSwitchAsyncContextHandleRequestGlobalSwitchAsyncContextHandle60 explicit RequestGlobalSwitchAsyncContextHandle( 61 std::shared_ptr<RequestGlobalSwitchAsyncContext>& requestAsyncContext) 62 { 63 asyncContextPtr = requestAsyncContext; 64 } 65 66 std::shared_ptr<RequestGlobalSwitchAsyncContext> asyncContextPtr; 67 }; 68 69 class SwitchOnSettingUICallback { 70 public: 71 explicit SwitchOnSettingUICallback(const std::shared_ptr<RequestGlobalSwitchAsyncContext>& reqContext); 72 ~SwitchOnSettingUICallback(); 73 void SetSessionId(int32_t sessionId); 74 void OnRelease(int32_t releaseCode); 75 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 76 void OnReceive(const OHOS::AAFwk::WantParams& request); 77 void OnError(int32_t code, const std::string& name, const std::string& message); 78 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy); 79 void OnDestroy(); 80 void ReleaseHandler(int32_t code); 81 82 private: 83 int32_t sessionId_ = 0; 84 std::shared_ptr<RequestGlobalSwitchAsyncContext> reqContext_ = nullptr; 85 }; 86 87 struct SwitchOnSettingResultCallback { 88 int32_t jsCode; 89 bool switchStatus; 90 std::shared_ptr<RequestGlobalSwitchAsyncContext> data = nullptr; 91 }; 92 93 class NapiRequestGlobalSwitch { 94 public: 95 static napi_value RequestGlobalSwitch(napi_env env, napi_callback_info info); 96 97 private: 98 static bool ParseRequestGlobalSwitch(const napi_env& env, const napi_callback_info& cbInfo, 99 std::shared_ptr<RequestGlobalSwitchAsyncContext>& asyncContext); 100 static void RequestGlobalSwitchExecute(napi_env env, void* data); 101 static void RequestGlobalSwitchComplete(napi_env env, napi_status status, void* data); 102 }; 103 } // namespace AccessToken 104 } // namespace Security 105 } // namespace OHOS 106 #endif /* INTERFACES_ACCESSTOKEN_KITS_NAPI_REQUEST_GLOBAL_SWITCHN_ON_SETTING_H */ 107