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 "continuous_task_change_callback.h"
17 #include "access_token.h"
18 #include "accesstoken_common_log.h"
19 #include "access_token_error.h"
20
21
22 namespace OHOS {
23 namespace Security {
24 namespace AccessToken {
25
BackgroundTaskSubscriberStub()26 BackgroundTaskSubscriberStub::BackgroundTaskSubscriberStub()
27 {
28 LOGI(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub Instance create.");
29 }
30
~BackgroundTaskSubscriberStub()31 BackgroundTaskSubscriberStub::~BackgroundTaskSubscriberStub()
32 {
33 LOGI(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub Instance destroy.");
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t BackgroundTaskSubscriberStub::OnRemoteRequest(
37 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 if (data.ReadInterfaceToken() != GetDescriptor()) {
40 LOGI(ATM_DOMAIN, ATM_TAG, "BackgroundTaskSubscriberStub: ReadInterfaceToken failed.");
41 return ERROR_IPC_REQUEST_FAIL;
42 }
43 switch (static_cast<IBackgroundTaskSubscriber::Message>(code)) {
44 case IBackgroundTaskSubscriber::Message::ON_CONTINUOUS_TASK_START: {
45 HandleOnContinuousTaskStart(data, reply);
46 return NO_ERROR;
47 }
48 case IBackgroundTaskSubscriber::Message::ON_CONTINUOUS_TASK_STOP: {
49 HandleOnContinuousTaskStop(data, reply);
50 return NO_ERROR;
51 }
52 default: {
53 LOGD(ATM_DOMAIN, ATM_TAG, "Default case code: %{public}d.", code);
54 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55 }
56 }
57 return NO_ERROR;
58 }
59
HandleOnContinuousTaskStart(MessageParcel & data,MessageParcel & reply)60 void BackgroundTaskSubscriberStub::HandleOnContinuousTaskStart(MessageParcel &data, MessageParcel &reply)
61 {
62 std::shared_ptr<ContinuousTaskCallbackInfo> continuousTaskCallbackInfo(
63 data.ReadParcelable<ContinuousTaskCallbackInfo>());
64 if (continuousTaskCallbackInfo == nullptr) {
65 LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed.");
66 return;
67 }
68 OnContinuousTaskStart(continuousTaskCallbackInfo);
69 }
70
HandleOnContinuousTaskStop(MessageParcel & data,MessageParcel & reply)71 void BackgroundTaskSubscriberStub::HandleOnContinuousTaskStop(MessageParcel &data, MessageParcel &reply)
72 {
73 std::shared_ptr<ContinuousTaskCallbackInfo> continuousTaskCallbackInfo(
74 data.ReadParcelable<ContinuousTaskCallbackInfo>());
75 if (continuousTaskCallbackInfo == nullptr) {
76 LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed.");
77 return;
78 }
79 OnContinuousTaskStop(continuousTaskCallbackInfo);
80 }
81 } // namespace AccessToken
82 } // namespace Security
83 } // namespace OHOS
84