• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "form_manager_access_proxy.h"
17 #include "accesstoken_common_log.h"
18 
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 namespace {
23 static constexpr int32_t ERROR = -1;
24 }
25 
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)26 int32_t FormManagerAccessProxy::RegisterAddObserver(
27     const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option;
32     if (!data.WriteInterfaceToken(GetDescriptor())) {
33         LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed.");
34         return ERROR;
35     }
36     if (!data.WriteString(bundleName)) {
37         LOGE(ATM_DOMAIN, ATM_TAG, "Write bundleName failed.");
38         return ERROR;
39     }
40     if (!data.WriteRemoteObject(callerToken)) {
41         LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed.");
42         return ERROR;
43     }
44     sptr<IRemoteObject> remote = Remote();
45     if (remote == nullptr) {
46         LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null.");
47         return ERROR;
48     }
49     int32_t error = remote->SendRequest(
50         static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER), data, reply, option);
51     if (error != ERR_NONE) {
52         LOGE(ATM_DOMAIN, ATM_TAG, "RegisterAddObserver failed, error: %{public}d", error);
53         return ERROR;
54     }
55     return reply.ReadInt32();
56 }
57 
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)58 int32_t FormManagerAccessProxy::RegisterRemoveObserver(
59     const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
60 {
61     MessageParcel data;
62     MessageParcel reply;
63     MessageOption option;
64     if (!data.WriteInterfaceToken(GetDescriptor())) {
65         LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed.");
66         return ERROR;
67     }
68     if (!data.WriteString(bundleName)) {
69         LOGE(ATM_DOMAIN, ATM_TAG, "Write bundleName failed.");
70         return ERROR;
71     }
72     if (!data.WriteRemoteObject(callerToken)) {
73         LOGE(ATM_DOMAIN, ATM_TAG, "Write callerToken failed.");
74         return ERROR;
75     }
76     sptr<IRemoteObject> remote = Remote();
77     if (remote == nullptr) {
78         LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null.");
79         return ERROR;
80     }
81     int32_t error = remote->SendRequest(
82         static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER), data, reply, option);
83     if (error != ERR_NONE) {
84         LOGE(ATM_DOMAIN, ATM_TAG, "UnregisterAddObserver failed, error: %d", error);
85         return error;
86     }
87     return reply.ReadInt32();
88 }
89 
HasFormVisible(const uint32_t tokenId)90 bool FormManagerAccessProxy::HasFormVisible(const uint32_t tokenId)
91 {
92     MessageParcel data;
93     MessageParcel reply;
94     MessageOption option;
95     if (!data.WriteInterfaceToken(GetDescriptor())) {
96         LOGE(ATM_DOMAIN, ATM_TAG, "WriteInterfaceToken failed.");
97         return false;
98     }
99     if (!data.WriteUint32(tokenId)) {
100         LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write tokenId.");
101         return false;
102     }
103 
104     sptr<IRemoteObject> remote = Remote();
105     if (remote == nullptr) {
106         LOGE(ATM_DOMAIN, ATM_TAG, "Remote service is null.");
107         return false;
108     }
109     int32_t error = remote->SendRequest(
110         static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_HAS_FORM_VISIBLE_WITH_TOKENID), data, reply, option);
111     if (error != ERR_NONE) {
112         LOGE(ATM_DOMAIN, ATM_TAG, "Get form visibility failed, error: %{public}d", error);
113         return false;
114     }
115     return reply.ReadBool();
116 }
117 } // namespace AccessToken
118 } // namespace Security
119 } // namespace OHOS
120