• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GLOBAL_SWITCH_ON_SETTING_H
17 #define OHOS_ABILITY_ACCESS_REQUEST_GLOBAL_SWITCH_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 "ffi_remote_data.h"
27 #include "permission_grant_info.h"
28 #include "ui_content.h"
29 #include "ui_extension_context.h"
30 
31 namespace OHOS {
32 namespace CJSystemapi {
33 
34 struct RequestGlobalSwitchAsyncContext {
35     OHOS::Security::AccessToken::AccessTokenID tokenId = 0;
36     int32_t switchType = -1;
37     int32_t errorCode = -1;
38     bool switchStatus = false;
39     OHOS::Security::AccessToken::PermissionGrantInfo info;
40     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext;
41     std::shared_ptr<AbilityRuntime::UIExtensionContext> uiExtensionContext;
42     bool uiAbilityFlag = false;
43     bool releaseFlag = false;
44     std::function<void(RetDataBool)> callbackRef = nullptr;
45 };
46 
47 struct RequestGlobalSwitchAsyncContextHandle {
RequestGlobalSwitchAsyncContextHandleRequestGlobalSwitchAsyncContextHandle48     explicit RequestGlobalSwitchAsyncContextHandle(
49         std::shared_ptr<RequestGlobalSwitchAsyncContext>& requestAsyncContext)
50     {
51         asyncContextPtr = requestAsyncContext;
52     }
53 
54     std::shared_ptr<RequestGlobalSwitchAsyncContext> asyncContextPtr;
55 };
56 
57 class SwitchOnSettingUICallback {
58 public:
59     explicit SwitchOnSettingUICallback(const std::shared_ptr<RequestGlobalSwitchAsyncContext>& reqContext);
60     ~SwitchOnSettingUICallback();
61     void SetSessionId(int32_t sessionId);
62     void OnRelease(int32_t releaseCode);
63     void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result);
64     void OnReceive(const OHOS::AAFwk::WantParams& request);
65     void OnError(int32_t code, const std::string& name, const std::string& message);
66     void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy);
67     void OnDestroy();
68     void ReleaseHandler(int32_t code);
69 
70 private:
71     int32_t sessionId_ = 0;
72     std::shared_ptr<RequestGlobalSwitchAsyncContext> reqContext_ = nullptr;
73 };
74 
75 class FfiRequestGlobalSwitchOnSetting {
76 public:
77     static void RequestGlobalSwitch(OHOS::AbilityRuntime::Context* context, int32_t switchType,
78         const std::function<void(RetDataBool)>& callbackRef);
79 private:
80     static bool ParseRequestGlobalSwitch(OHOS::AbilityRuntime::Context* context,
81         const std::shared_ptr<RequestGlobalSwitchAsyncContext>& asyncContext);
82 };
83 }
84 }
85 
86 #endif