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 #include "power_manager_proxy.h"
17 #include "accesstoken_log.h"
18 
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PowerMgrProxy"};
24 }
25 
IsScreenOn()26 bool PowerMgrProxy::IsScreenOn()
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option;
31     if (!data.WriteInterfaceToken(GetDescriptor())) {
32         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
33         return false;
34     }
35     bool needPrintLog = true;
36     if (!data.WriteBool(needPrintLog)) {
37         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteBool failed");
38         return false;
39     }
40     sptr<IRemoteObject> remote = Remote();
41     if (remote == nullptr) {
42         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
43         return false;
44     }
45     int32_t error = remote->SendRequest(static_cast<uint32_t>(IPowerMgr::Message::IS_SCREEN_ON), data, reply, option);
46     if (error != ERR_NONE) {
47         ACCESSTOKEN_LOG_ERROR(LABEL, "IsScreenOn failed, error: %{public}d", error);
48         return false;
49     }
50     return reply.ReadBool();
51 }
52 } // namespace AccessToken
53 } // namespace Security
54 } // namespace OHOS
55