• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "system_process_status_change_stub.h"
17 
18 #include "errors.h"
19 #include "ipc_object_stub.h"
20 #include "ipc_types.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 #include "refbase.h"
24 #include "sam_log.h"
25 
26 namespace OHOS {
SystemProcessStatusChangeStub()27 SystemProcessStatusChangeStub::SystemProcessStatusChangeStub()
28 {
29     memberFuncMap_[ON_SYSTEM_PROCESS_STARTED] =
30         &SystemProcessStatusChangeStub::OnSystemProcessStartedInner;
31     memberFuncMap_[ON_SYSTEM_PROCESS_STOPPED] =
32         &SystemProcessStatusChangeStub::OnSystemProcessStoppedInner;
33 }
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int32_t SystemProcessStatusChangeStub::OnRemoteRequest(uint32_t code,
36     MessageParcel& data, MessageParcel& reply, MessageOption& option)
37 {
38     HILOGI("SystemProcessStatusChangeStub::code:%{public}u, flags:%{public}d", code, option.GetFlags());
39     if (!EnforceInterceToken(data)) {
40         HILOGW("check interface token failed!");
41         return ERR_PERMISSION_DENIED;
42     }
43     auto iter = memberFuncMap_.find(code);
44     if (iter != memberFuncMap_.end()) {
45         auto memberFunc = iter->second;
46         if (memberFunc != nullptr) {
47             return (this->*memberFunc)(data, reply);
48         }
49     }
50     HILOGW("unknown request code!");
51     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52 }
53 
OnSystemProcessStartedInner(MessageParcel & data,MessageParcel & reply)54 int32_t SystemProcessStatusChangeStub::OnSystemProcessStartedInner(MessageParcel& data, MessageParcel& reply)
55 {
56     SystemProcessInfo systemProcessInfo;
57     systemProcessInfo.processName = data.ReadString();
58     if (systemProcessInfo.processName.empty()) {
59         HILOGW("read processName failed!");
60         return ERR_NULL_OBJECT;
61     }
62     systemProcessInfo.pid = data.ReadInt32();
63     OnSystemProcessStarted(systemProcessInfo);
64     return ERR_NONE;
65 }
66 
OnSystemProcessStoppedInner(MessageParcel & data,MessageParcel & reply)67 int32_t SystemProcessStatusChangeStub::OnSystemProcessStoppedInner(MessageParcel& data, MessageParcel& reply)
68 {
69     SystemProcessInfo systemProcessInfo;
70     systemProcessInfo.processName = data.ReadString();
71     if (systemProcessInfo.processName.empty()) {
72         HILOGW("read processName failed!");
73         return ERR_NULL_OBJECT;
74     }
75     systemProcessInfo.pid = data.ReadInt32();
76     OnSystemProcessStopped(systemProcessInfo);
77     return ERR_NONE;
78 }
79 
EnforceInterceToken(MessageParcel & data)80 bool SystemProcessStatusChangeStub::EnforceInterceToken(MessageParcel& data)
81 {
82     std::u16string interfaceToken = data.ReadInterfaceToken();
83     return interfaceToken == GetDescriptor();
84 }
85 }
86