• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "runcount_notify_stub.h"
17 
18 #include <cstdint>
19 #include <memory>
20 #include <thread>
21 
22 #include "base/request/request/interfaces/inner_kits/running_count/include/running_task_count.h"
23 #include "download_server_ipc_interface_code.h"
24 #include "log.h"
25 #include "parcel_helper.h"
26 #include "request_running_task_count.h"
27 #include "string_ex.h"
28 
29 namespace OHOS::Request {
CallBack(const Notify & notify)30 void RunCountNotifyStub::CallBack(const Notify &notify)
31 {
32 }
33 
Done(const TaskInfo & taskInfo)34 void RunCountNotifyStub::Done(const TaskInfo &taskInfo)
35 {
36 }
37 
GetInstance()38 sptr<RunCountNotifyStub> RunCountNotifyStub::GetInstance()
39 {
40     static sptr<RunCountNotifyStub> instance(new RunCountNotifyStub());
41     return instance;
42 }
43 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)44 int32_t RunCountNotifyStub::OnRemoteRequest(
45     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
46 {
47     auto descriptorToken = data.ReadInterfaceToken();
48     if (descriptorToken != GetDescriptor()) {
49         REQUEST_HILOGE("Remote descriptor not the same as local descriptor.");
50         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51     }
52 
53     if (code == static_cast<uint32_t>(RequestNotifyInterfaceCode::REQUEST_NOTIFY_RUNCOUNT)) {
54         OnCallBack(data);
55         return ERR_NONE;
56     } else {
57         REQUEST_HILOGE("Other interface code received, check needed.");
58         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59     }
60 }
61 
OnCallBack(MessageParcel & data)62 void RunCountNotifyStub::OnCallBack(MessageParcel &data)
63 {
64     REQUEST_HILOGD("Receive callback");
65     int runCount = data.ReadInt64();
66     REQUEST_HILOGD("RunCount num %{public}d", runCount);
67 
68     FwkRunningTaskCountManager::GetInstance()->SetCount(runCount);
69     FwkRunningTaskCountManager::GetInstance()->NotifyAllObservers();
70 }
71 
72 } // namespace OHOS::Request
73