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 #include "feature_stub_impl.h"
16 
17 #include "bootstrap.h"
18 #include "ipc_skeleton.h"
19 namespace OHOS::DistributedData {
FeatureStubImpl(std::shared_ptr<FeatureSystem::Feature> feature)20 FeatureStubImpl::FeatureStubImpl(std::shared_ptr<FeatureSystem::Feature> feature)
21     : featureImpl_(std::move(feature))
22 {
23 }
24 
~FeatureStubImpl()25 FeatureStubImpl::~FeatureStubImpl()
26 {
27     featureImpl_ = nullptr;
28 }
29 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int FeatureStubImpl::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32     if (featureImpl_ == nullptr) {
33         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
34     }
35     return featureImpl_->OnRemoteRequest(code, data, reply);
36 }
37 
OnInitialize(std::shared_ptr<ExecutorPool> executor)38 int32_t FeatureStubImpl::OnInitialize(std::shared_ptr<ExecutorPool> executor)
39 {
40     if (featureImpl_ == nullptr) {
41         return -1;
42     }
43     featureImpl_->OnBind({ Bootstrap::GetInstance().GetProcessLabel(),
44         static_cast<uint32_t>(IPCSkeleton::GetSelfTokenID()), std::move(executor)});
45     return featureImpl_->OnInitialize();
46 }
47 
OnAppExit(pid_t uid,pid_t pid,uint32_t tokenId,const std::string & bundleName)48 int32_t FeatureStubImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName)
49 {
50     if (featureImpl_ == nullptr) {
51         return -1;
52     }
53     return featureImpl_->OnAppExit(uid, pid, tokenId, bundleName);
54 }
55 
OnAppUninstall(const std::string & bundleName,int32_t user,int32_t index)56 int32_t FeatureStubImpl::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index)
57 {
58     if (featureImpl_ == nullptr) {
59         return -1;
60     }
61     return featureImpl_->OnAppUninstall(bundleName, user, index);
62 }
63 
OnAppUpdate(const std::string & bundleName,int32_t user,int32_t index)64 int32_t FeatureStubImpl::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index)
65 {
66     if (featureImpl_ == nullptr) {
67         return -1;
68     }
69     return featureImpl_->OnAppUpdate(bundleName, user, index);
70 }
71 
OnAppInstall(const std::string & bundleName,int32_t user,int32_t index)72 int32_t FeatureStubImpl::OnAppInstall(const std::string &bundleName, int32_t user, int32_t index)
73 {
74     if (featureImpl_ == nullptr) {
75         return -1;
76     }
77     return featureImpl_->OnAppInstall(bundleName, user, index);
78 }
79 
ResolveAutoLaunch(const std::string & identifier,DistributedDB::AutoLaunchParam & param)80 int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam &param)
81 {
82     if (featureImpl_ == nullptr) {
83         return -1;
84     }
85     return featureImpl_->ResolveAutoLaunch(identifier, param);
86 }
87 
OnUserChange(uint32_t code,const std::string & user,const std::string & account)88 int32_t FeatureStubImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account)
89 {
90     if (featureImpl_ == nullptr) {
91         return -1;
92     }
93     return featureImpl_->OnUserChange(code, user, account);
94 }
95 
Online(const std::string & device)96 int32_t FeatureStubImpl::Online(const std::string &device)
97 {
98     if (featureImpl_ == nullptr) {
99         return -1;
100     }
101     return featureImpl_->Online(device);
102 }
103 
Offline(const std::string & device)104 int32_t FeatureStubImpl::Offline(const std::string &device)
105 {
106     if (featureImpl_ == nullptr) {
107         return -1;
108     }
109     return featureImpl_->Offline(device);
110 }
111 
OnReady(const std::string & device)112 int32_t FeatureStubImpl::OnReady(const std::string &device)
113 {
114     if (featureImpl_ == nullptr) {
115         return -1;
116     }
117     return featureImpl_->OnReady(device);
118 }
119 
OnSessionReady(const std::string & device)120 int32_t FeatureStubImpl::OnSessionReady(const std::string &device)
121 {
122     if (featureImpl_ == nullptr) {
123         return -1;
124     }
125     return featureImpl_->OnSessionReady(device);
126 }
127 
OnScreenUnlocked(int32_t user)128 int32_t FeatureStubImpl::OnScreenUnlocked(int32_t user)
129 {
130     if (featureImpl_ == nullptr) {
131         return -1;
132     }
133     return featureImpl_->OnScreenUnlocked(user);
134 }
135 }
136