• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "system_ability_load_callback_stub.h"
17 
18 #include "ipc_skeleton.h"
19 #include "sam_log.h"
20 #include "system_ability_definition.h"
21 
22 namespace OHOS {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int32_t SystemAbilityLoadCallbackStub::OnRemoteRequest(uint32_t code,
24     MessageParcel& data, MessageParcel& reply, MessageOption& option)
25 {
26     HILOGI("SystemAbilityLoadCallbackStub::OnRemoteRequest, code = %{public}d", code);
27     if (!EnforceInterceToken(data)) {
28         HILOGW("SystemAbilityLoadCallbackStub::OnRemoteRequest check interface token failed!");
29         return ERR_PERMISSION_DENIED;
30     }
31     switch (code) {
32         case ON_LOAD_SYSTEM_ABILITY_SUCCESS:
33             return OnLoadSystemAbilitySuccessInner(data, reply);
34         case ON_LOAD_SYSTEM_ABILITY_FAIL:
35             return OnLoadSystemAbilityFailInner(data, reply);
36         default:
37             HILOGW("SystemAbilityLoadCallbackStub::OnRemoteRequest unknown request code!");
38             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
39     }
40 }
41 
OnLoadSystemAbilitySuccessInner(MessageParcel & data,MessageParcel & reply)42 int32_t SystemAbilityLoadCallbackStub::OnLoadSystemAbilitySuccessInner(MessageParcel& data, MessageParcel& reply)
43 {
44     int32_t systemAbilityId = data.ReadInt32();
45     if (!CheckInputSystemAbilityId(systemAbilityId)) {
46         HILOGW("OnLoadSystemAbilitySuccessInner invalid systemAbilityId:%{public}d !", systemAbilityId);
47         return ERR_INVALID_VALUE;
48     }
49     sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
50     OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject);
51     return ERR_NONE;
52 }
53 
OnLoadSystemAbilityFailInner(MessageParcel & data,MessageParcel & reply)54 int32_t SystemAbilityLoadCallbackStub::OnLoadSystemAbilityFailInner(MessageParcel& data, MessageParcel& reply)
55 {
56     int32_t systemAbilityId = data.ReadInt32();
57     if (!CheckInputSystemAbilityId(systemAbilityId)) {
58         HILOGW("OnLoadSystemAbilityFailInner invalid systemAbilityId:%{public}d !", systemAbilityId);
59         return ERR_INVALID_VALUE;
60     }
61     OnLoadSystemAbilityFail(systemAbilityId);
62     return ERR_NONE;
63 }
64 
CheckInputSystemAbilityId(int32_t systemAbilityId)65 bool SystemAbilityLoadCallbackStub::CheckInputSystemAbilityId(int32_t systemAbilityId)
66 {
67     return (systemAbilityId >= FIRST_SYS_ABILITY_ID) && (systemAbilityId <= LAST_SYS_ABILITY_ID);
68 }
69 
EnforceInterceToken(MessageParcel & data)70 bool SystemAbilityLoadCallbackStub::EnforceInterceToken(MessageParcel& data)
71 {
72     std::u16string interfaceToken = data.ReadInterfaceToken();
73     return interfaceToken == GetDescriptor();
74 }
75 }
76