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 "dslm_service.h"
17
18 #include <thread>
19
20 #include "iremote_object.h"
21 #include "singleton.h"
22 #include "utils_log.h"
23
24 #include "device_security_defines.h"
25 #include "dslm_hidumper.h"
26 #include "dslm_ipc_process.h"
27 #include "dslm_rpc_process.h"
28
29 namespace OHOS {
30 namespace Security {
31 namespace DeviceSecurityLevel {
32 REGISTER_SYSTEM_ABILITY_BY_ID(DslmService, DEVICE_SECURITY_LEVEL_MANAGER_SA_ID, true);
33
DslmService(int32_t saId,bool runOnCreate)34 DslmService::DslmService(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate)
35 {
36 SECURITY_LOG_INFO("object initialization");
37 }
38
OnStart()39 void DslmService::OnStart()
40 {
41 SECURITY_LOG_INFO("start");
42
43 std::thread thread([this]() {
44 if (InitService() == SUCCESS) {
45 SECURITY_LOG_INFO("init service success");
46 }
47 if (!Publish(this)) {
48 SECURITY_LOG_ERROR("publish service failed");
49 }
50 });
51 thread.detach();
52 }
53
OnStop()54 void DslmService::OnStop()
55 {
56 UnInitService();
57 SECURITY_LOG_INFO("stop service");
58 }
59
Dump(int fd,const std::vector<std::u16string> & args)60 int32_t DslmService::Dump(int fd, const std::vector<std::u16string> &args)
61 {
62 DslmDumper(fd);
63 return 0;
64 }
65
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)66 int32_t DslmService::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
67 {
68 do {
69 if (IDeviceSecurityLevel::GetDescriptor() != data.ReadInterfaceToken()) {
70 SECURITY_LOG_ERROR("local descriptor is not equal remote");
71 break;
72 }
73 switch (code) {
74 case CMD_GET_DEVICE_SECURITY_LEVEL:
75 return ProcessGetDeviceSecurityLevel(data, reply);
76 default:
77 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
78 }
79 } while (false);
80
81 return ERR_REQUEST_CODE_ERR;
82 }
83
ProcessGetDeviceSecurityLevel(MessageParcel & data,MessageParcel & reply)84 int32_t DslmService::ProcessGetDeviceSecurityLevel(MessageParcel &data, MessageParcel &reply)
85 {
86 return Singleton<DslmIpcProcess>::GetInstance().DslmProcessGetDeviceSecurityLevel(data, reply);
87 }
88 } // namespace DeviceSecurityLevel
89 } // namespace Security
90 } // namespace OHOS
91