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 "cm_advsecmode_check.h" 17 18 #include <string.h> 19 20 #include "parameter.h" 21 #include "sysparam_errno.h" 22 23 #include "cm_log.h" 24 25 #define ADVSECMODE_PARAM_SIZE 32 26 27 static const char g_advSecModePropKey[] = "ohos.boot.advsecmode.state"; 28 static const char g_advSecModePropTrue[] = "1"; 29 CheckAdvSecMode(bool * isAdvSecMode)30int32_t CheckAdvSecMode(bool *isAdvSecMode) 31 { 32 if (isAdvSecMode == NULL) { 33 CM_LOG_E("invalid input param"); 34 return CMR_ERROR_INVALID_ARGUMENT; 35 } 36 37 *isAdvSecMode = false; 38 char param[ADVSECMODE_PARAM_SIZE] = { 0 }; 39 uint32_t paramSize = sizeof(param); 40 int ret = GetParameter(g_advSecModePropKey, NULL, param, paramSize); 41 if (ret < 0) { 42 if (ret == SYSPARAM_NOT_FOUND) { 43 CM_LOG_D("advsecmode param is no found"); 44 return CM_SUCCESS; 45 } 46 CM_LOG_E("Failed to get advsecmode param"); 47 return CMR_ERROR_GET_ADVSECMODE_PARAM_FAIL; 48 } 49 50 if (strcmp(param, g_advSecModePropTrue) == 0) { 51 *isAdvSecMode = true; 52 } 53 return CM_SUCCESS; 54 }