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 OHOS_ABILITY_ACCESS_REQUEST_PERMISSION_ON_SETTING_H 17 #define OHOS_ABILITY_ACCESS_REQUEST_PERMISSION_ON_SETTING_H 18 19 #include <cstdint> 20 #include <cstdio> 21 #include <cstring> 22 23 #include "accesstoken_kit.h" 24 #include "cj_common_ffi.h" 25 #include "cj_lambda.h" 26 #include "permission_grant_info.h" 27 #include "ui_content.h" 28 #include "ui_extension_context.h" 29 30 namespace OHOS { 31 namespace CJSystemapi { 32 33 struct RequestPermOnSettingAsyncContext { 34 OHOS::Security::AccessToken::AccessTokenID tokenId = 0; 35 OHOS::Security::AccessToken::PermissionGrantInfo info; 36 int32_t errorCode = -1; 37 std::vector<std::string> permissionList; 38 std::vector<int32_t> stateList; 39 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext; 40 std::shared_ptr<AbilityRuntime::UIExtensionContext> uiExtensionContext; 41 bool uiAbilityFlag = false; 42 bool releaseFlag = false; 43 std::function<void(RetDataCArrI32)> callbackRef = nullptr; 44 }; 45 46 struct RequestOnSettingAsyncContextHandle { RequestOnSettingAsyncContextHandleRequestOnSettingAsyncContextHandle47 explicit RequestOnSettingAsyncContextHandle(std::shared_ptr<RequestPermOnSettingAsyncContext>& requestAsyncContext) 48 { 49 asyncContextPtr = requestAsyncContext; 50 } 51 52 std::shared_ptr<RequestPermOnSettingAsyncContext> asyncContextPtr; 53 }; 54 55 class PermissonOnSettingUICallback { 56 public: 57 explicit PermissonOnSettingUICallback(const std::shared_ptr<RequestPermOnSettingAsyncContext>& reqContext); 58 ~PermissonOnSettingUICallback(); 59 void SetSessionId(int32_t sessionId); 60 void OnRelease(int32_t releaseCode); 61 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 62 void OnReceive(const OHOS::AAFwk::WantParams& request); 63 void OnError(int32_t code, const std::string& name, const std::string& message); 64 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy); 65 void OnDestroy(); 66 void ReleaseHandler(int32_t code); 67 68 private: 69 int32_t sessionId_ = 0; 70 std::shared_ptr<RequestPermOnSettingAsyncContext> reqContext_ = nullptr; 71 }; 72 73 class FfiRequestPermissionOnSetting { 74 public: 75 static void RequestPermissionOnSetting(OHOS::AbilityRuntime::Context* context, CArrString cPermissionList, 76 const std::function<void(RetDataCArrI32)>& callbackRef); 77 private: 78 static bool ParseRequestPermissionOnSetting(OHOS::AbilityRuntime::Context* context, CArrString cPermissionList, 79 const std::shared_ptr<RequestPermOnSettingAsyncContext>& asyncContext); 80 }; 81 } 82 } 83 84 #endif