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_PERMISSION_ON_SETTING_H 16 #define INTERFACES_ACCESSTOKEN_KITS_NAPI_REQUEST_PERMISSION_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 struct RequestPermOnSettingAsyncContext : public AtManagerAsyncWorkData { RequestPermOnSettingAsyncContextRequestPermOnSettingAsyncContext31 explicit RequestPermOnSettingAsyncContext(napi_env env) : AtManagerAsyncWorkData(env) 32 { 33 this->env = env; 34 } 35 36 AccessTokenID tokenId = 0; 37 int32_t result = RET_SUCCESS; 38 PermissionGrantInfo info; 39 int32_t resultCode = -1; 40 41 std::vector<std::string> permissionList; 42 napi_value requestResult = nullptr; 43 int32_t errorCode = -1; 44 std::vector<int32_t> stateList; 45 46 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext; 47 std::shared_ptr<AbilityRuntime::UIExtensionContext> uiExtensionContext; 48 bool uiAbilityFlag = false; 49 bool releaseFlag = false; 50 #ifdef EVENTHANDLER_ENABLE 51 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 52 #endif 53 }; 54 55 struct RequestOnSettingAsyncContextHandle { RequestOnSettingAsyncContextHandleRequestOnSettingAsyncContextHandle56 explicit RequestOnSettingAsyncContextHandle(std::shared_ptr<RequestPermOnSettingAsyncContext>& requestAsyncContext) 57 { 58 asyncContextPtr = requestAsyncContext; 59 } 60 61 std::shared_ptr<RequestPermOnSettingAsyncContext> asyncContextPtr; 62 }; 63 64 class PermissonOnSettingUICallback { 65 public: 66 explicit PermissonOnSettingUICallback(const std::shared_ptr<RequestPermOnSettingAsyncContext>& reqContext); 67 ~PermissonOnSettingUICallback(); 68 void SetSessionId(int32_t sessionId); 69 void OnRelease(int32_t releaseCode); 70 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 71 void OnReceive(const OHOS::AAFwk::WantParams& request); 72 void OnError(int32_t code, const std::string& name, const std::string& message); 73 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy); 74 void OnDestroy(); 75 void ReleaseHandler(int32_t code); 76 77 private: 78 int32_t sessionId_ = 0; 79 std::shared_ptr<RequestPermOnSettingAsyncContext> reqContext_ = nullptr; 80 }; 81 82 struct PermissonOnSettingResultCallback { 83 int32_t jsCode; 84 std::vector<int32_t> stateList; 85 std::shared_ptr<RequestPermOnSettingAsyncContext> data = nullptr; 86 }; 87 88 class NapiRequestPermissionOnSetting { 89 public: 90 static napi_value RequestPermissionOnSetting(napi_env env, napi_callback_info info); 91 92 private: 93 static bool ParseRequestPermissionOnSetting(const napi_env& env, const napi_callback_info& cbInfo, 94 std::shared_ptr<RequestPermOnSettingAsyncContext>& asyncContext); 95 static void RequestPermissionOnSettingExecute(napi_env env, void* data); 96 static void RequestPermissionOnSettingComplete(napi_env env, napi_status status, void* data); 97 }; 98 } // namespace AccessToken 99 } // namespace Security 100 } // namespace OHOS 101 #endif /* INTERFACES_ACCESSTOKEN_KITS_NAPI_REQUEST_PERMISSION_ON_SETTING_H */ 102