1 /*
2  * Copyright (c) 2024-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 "camera_napi_security_utils.h"
17 
18 #include "camera_error_code.h"
19 #include "camera_log.h"
20 #include "camera_security_utils.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace CameraNapiSecurity {
CheckSystemApp(napi_env env,bool enableThrowError)25 bool CheckSystemApp(napi_env env, bool enableThrowError)
26 {
27     int32_t errorCode = CameraErrorCode::NO_SYSTEM_APP_PERMISSION;
28     bool isSystemApp = CameraSecurity::CheckSystemApp();
29     if (!isSystemApp) {
30         if (enableThrowError) {
31             std::string errorMessage = "System api can be invoked only by system applications";
32             if (napi_throw_error(env, std::to_string(errorCode).c_str(), errorMessage.c_str()) != napi_ok) {
33                 MEDIA_ERR_LOG("failed to throw err, code=%{public}d, msg=%{public}s.", errorCode, errorMessage.c_str());
34             }
35         }
36         return false;
37     }
38     return true;
39 }
40 } // namespace CameraNapiSecurity
41 } // namespace CameraStandard
42 } // namespace OHOS
43