• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #define HUKS_DISABLE_LOG_AT_FILE_TO_REDUCE_ROM_SIZE
16 
17 #include "hks_client_service_common.h"
18 
19 #include <stdatomic.h>
20 #include <stddef.h>
21 
22 #include "hks_log.h"
23 #include "hks_param.h"
24 #include "hks_template.h"
25 #include "hks_type_enum.h"
26 
27 static volatile atomic_bool g_isScreenOn = false;
28 
AppendToNewParamSet(const struct HksParamSet * paramSet,struct HksParamSet ** outParamSet)29 int32_t AppendToNewParamSet(const struct HksParamSet *paramSet, struct HksParamSet **outParamSet)
30 {
31     HKS_IF_NULL_LOGI_RETURN(outParamSet, HKS_ERROR_NULL_POINTER, "outParamSet is null")
32     int32_t ret;
33     struct HksParamSet *newParamSet = NULL;
34 
35     do {
36         ret = HksCheckParamSet(paramSet, paramSet->paramSetSize);
37         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "check paramSet failed")
38 
39         ret = HksFreshParamSet((struct HksParamSet *)paramSet, false);
40         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "append fresh paramset failed")
41 
42         ret = HksInitParamSet(&newParamSet);
43         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "append init operation param set failed")
44 
45         ret = HksAddParams(newParamSet, paramSet->params, paramSet->paramsCnt);
46         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "append params failed")
47 
48         *outParamSet = newParamSet;
49         return ret;
50     } while (0);
51 
52     HksFreeParamSet(&newParamSet);
53     return ret;
54 }
55 
BuildFrontUserIdParamSet(const struct HksParamSet * paramSet,struct HksParamSet ** outParamSet,int frontUserId)56 int32_t BuildFrontUserIdParamSet(const struct HksParamSet *paramSet, struct HksParamSet **outParamSet, int frontUserId)
57 {
58     HKS_IF_NULL_LOGE_RETURN(outParamSet, HKS_ERROR_NULL_POINTER, "outParamSet is null ptr")
59     struct HksParamSet *newParamSet = NULL;
60     int32_t ret;
61     do {
62         ret = (paramSet != NULL) ? AppendToNewParamSet(paramSet, &newParamSet) : HksInitParamSet(&newParamSet);
63         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "init param set failed")
64 
65         struct HksParam frontUserIdParam;
66         frontUserIdParam.tag = HKS_TAG_FRONT_USER_ID;
67         frontUserIdParam.int32Param = frontUserId;
68         ret = HksAddParams(newParamSet, &frontUserIdParam, 1);
69         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "add frontUserIdParam fail!");
70 
71         ret = HksBuildParamSet(&newParamSet);
72         HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "build append info failed")
73         *outParamSet = newParamSet;
74     } while (0);
75     if (ret != HKS_SUCCESS) {
76         HksFreeParamSet(&newParamSet);
77         *outParamSet = NULL;
78     }
79     return ret;
80 }
81 
HksSetScreenState(bool state)82 void HksSetScreenState(bool state)
83 {
84     atomic_store(&g_isScreenOn, state);
85 }
86 
HksGetScreenState(void)87 bool HksGetScreenState(void)
88 {
89     return atomic_load(&g_isScreenOn);
90 }
91