1eace7efcSopenharmony_ci/*
2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License.
5eace7efcSopenharmony_ci * You may obtain a copy of the License at
6eace7efcSopenharmony_ci *
7eace7efcSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8eace7efcSopenharmony_ci *
9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and
13eace7efcSopenharmony_ci * limitations under the License.
14eace7efcSopenharmony_ci */
15eace7efcSopenharmony_ci
16eace7efcSopenharmony_ci#include "dataobs_mgr_service.h"
17eace7efcSopenharmony_ci
18eace7efcSopenharmony_ci#include <functional>
19eace7efcSopenharmony_ci#include <memory>
20eace7efcSopenharmony_ci#include <string>
21eace7efcSopenharmony_ci#include <unistd.h>
22eace7efcSopenharmony_ci#include "string_ex.h"
23eace7efcSopenharmony_ci
24eace7efcSopenharmony_ci#include "dataobs_mgr_errors.h"
25eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h"
26eace7efcSopenharmony_ci#include "if_system_ability_manager.h"
27eace7efcSopenharmony_ci#include "ipc_skeleton.h"
28eace7efcSopenharmony_ci#include "system_ability_definition.h"
29eace7efcSopenharmony_ci#include "common_utils.h"
30eace7efcSopenharmony_ci#include "securec.h"
31eace7efcSopenharmony_ci
32eace7efcSopenharmony_cinamespace OHOS {
33eace7efcSopenharmony_cinamespace AAFwk {
34eace7efcSopenharmony_ciconst bool REGISTER_RESULT =
35eace7efcSopenharmony_ci    SystemAbility::MakeAndRegisterAbility(DelayedSingleton<DataObsMgrService>::GetInstance().get());
36eace7efcSopenharmony_ci
37eace7efcSopenharmony_ciDataObsMgrService::DataObsMgrService()
38eace7efcSopenharmony_ci    : SystemAbility(DATAOBS_MGR_SERVICE_SA_ID, true),
39eace7efcSopenharmony_ci      state_(DataObsServiceRunningState::STATE_NOT_START)
40eace7efcSopenharmony_ci{
41eace7efcSopenharmony_ci    dataObsMgrInner_ = std::make_shared<DataObsMgrInner>();
42eace7efcSopenharmony_ci    dataObsMgrInnerExt_ = std::make_shared<DataObsMgrInnerExt>();
43eace7efcSopenharmony_ci    dataObsMgrInnerPref_ = std::make_shared<DataObsMgrInnerPref>();
44eace7efcSopenharmony_ci}
45eace7efcSopenharmony_ci
46eace7efcSopenharmony_ciDataObsMgrService::~DataObsMgrService()
47eace7efcSopenharmony_ci{}
48eace7efcSopenharmony_ci
49eace7efcSopenharmony_civoid DataObsMgrService::OnStart()
50eace7efcSopenharmony_ci{
51eace7efcSopenharmony_ci    if (state_ == DataObsServiceRunningState::STATE_RUNNING) {
52eace7efcSopenharmony_ci        TAG_LOGI(AAFwkTag::DBOBSMGR, "dms started");
53eace7efcSopenharmony_ci        return;
54eace7efcSopenharmony_ci    }
55eace7efcSopenharmony_ci    if (!Init()) {
56eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "init failed");
57eace7efcSopenharmony_ci        return;
58eace7efcSopenharmony_ci    }
59eace7efcSopenharmony_ci    state_ = DataObsServiceRunningState::STATE_RUNNING;
60eace7efcSopenharmony_ci    /* Publish service maybe failed, so we need call this function at the last,
61eace7efcSopenharmony_ci     * so it can't affect the TDD test program */
62eace7efcSopenharmony_ci    if (!Publish(DelayedSingleton<DataObsMgrService>::GetInstance().get())) {
63eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "publish init failed");
64eace7efcSopenharmony_ci        return;
65eace7efcSopenharmony_ci    }
66eace7efcSopenharmony_ci
67eace7efcSopenharmony_ci    TAG_LOGI(AAFwkTag::DBOBSMGR, "dms called");
68eace7efcSopenharmony_ci}
69eace7efcSopenharmony_ci
70eace7efcSopenharmony_cibool DataObsMgrService::Init()
71eace7efcSopenharmony_ci{
72eace7efcSopenharmony_ci    handler_ = TaskHandlerWrap::GetFfrtHandler();
73eace7efcSopenharmony_ci    return true;
74eace7efcSopenharmony_ci}
75eace7efcSopenharmony_ci
76eace7efcSopenharmony_civoid DataObsMgrService::OnStop()
77eace7efcSopenharmony_ci{
78eace7efcSopenharmony_ci    TAG_LOGI(AAFwkTag::DBOBSMGR, "stop");
79eace7efcSopenharmony_ci    handler_.reset();
80eace7efcSopenharmony_ci    state_ = DataObsServiceRunningState::STATE_NOT_START;
81eace7efcSopenharmony_ci}
82eace7efcSopenharmony_ci
83eace7efcSopenharmony_ciDataObsServiceRunningState DataObsMgrService::QueryServiceState() const
84eace7efcSopenharmony_ci{
85eace7efcSopenharmony_ci    return state_;
86eace7efcSopenharmony_ci}
87eace7efcSopenharmony_ci
88eace7efcSopenharmony_ciint DataObsMgrService::RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver)
89eace7efcSopenharmony_ci{
90eace7efcSopenharmony_ci    if (dataObserver == nullptr) {
91eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver, uri:%{public}s",
92eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
93eace7efcSopenharmony_ci        return DATA_OBSERVER_IS_NULL;
94eace7efcSopenharmony_ci    }
95eace7efcSopenharmony_ci
96eace7efcSopenharmony_ci    if (dataObsMgrInner_ == nullptr) {
97eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgrInner, uri:%{public}s",
98eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
99eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
100eace7efcSopenharmony_ci    }
101eace7efcSopenharmony_ci
102eace7efcSopenharmony_ci    int status;
103eace7efcSopenharmony_ci    if (const_cast<Uri &>(uri).GetScheme() == SHARE_PREFERENCES) {
104eace7efcSopenharmony_ci        status = dataObsMgrInnerPref_->HandleRegisterObserver(uri, dataObserver);
105eace7efcSopenharmony_ci    } else {
106eace7efcSopenharmony_ci        status = dataObsMgrInner_->HandleRegisterObserver(uri, dataObserver);
107eace7efcSopenharmony_ci    }
108eace7efcSopenharmony_ci
109eace7efcSopenharmony_ci    if (status != NO_ERROR) {
110eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "register failed:%{public}d, uri:%{public}s", status,
111eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
112eace7efcSopenharmony_ci        return status;
113eace7efcSopenharmony_ci    }
114eace7efcSopenharmony_ci    return NO_ERROR;
115eace7efcSopenharmony_ci}
116eace7efcSopenharmony_ci
117eace7efcSopenharmony_ciint DataObsMgrService::UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver)
118eace7efcSopenharmony_ci{
119eace7efcSopenharmony_ci    if (dataObserver == nullptr) {
120eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver, uri:%{public}s",
121eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
122eace7efcSopenharmony_ci        return DATA_OBSERVER_IS_NULL;
123eace7efcSopenharmony_ci    }
124eace7efcSopenharmony_ci
125eace7efcSopenharmony_ci    if (dataObsMgrInner_ == nullptr) {
126eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgrInner, uri:%{public}s",
127eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
128eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
129eace7efcSopenharmony_ci    }
130eace7efcSopenharmony_ci
131eace7efcSopenharmony_ci    int status;
132eace7efcSopenharmony_ci    if (const_cast<Uri &>(uri).GetScheme() == SHARE_PREFERENCES) {
133eace7efcSopenharmony_ci        status = dataObsMgrInnerPref_->HandleUnregisterObserver(uri, dataObserver);
134eace7efcSopenharmony_ci    } else {
135eace7efcSopenharmony_ci        status = dataObsMgrInner_->HandleUnregisterObserver(uri, dataObserver);
136eace7efcSopenharmony_ci    }
137eace7efcSopenharmony_ci
138eace7efcSopenharmony_ci    if (status != NO_ERROR) {
139eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "unregister failed:%{public}d, uri:%{public}s", status,
140eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
141eace7efcSopenharmony_ci        return status;
142eace7efcSopenharmony_ci    }
143eace7efcSopenharmony_ci    return NO_ERROR;
144eace7efcSopenharmony_ci}
145eace7efcSopenharmony_ci
146eace7efcSopenharmony_ciint DataObsMgrService::NotifyChange(const Uri &uri)
147eace7efcSopenharmony_ci{
148eace7efcSopenharmony_ci    if (handler_ == nullptr) {
149eace7efcSopenharmony_ci        TAG_LOGE(
150eace7efcSopenharmony_ci            AAFwkTag::DBOBSMGR, "null handler, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str());
151eace7efcSopenharmony_ci        return DATAOBS_SERVICE_HANDLER_IS_NULL;
152eace7efcSopenharmony_ci    }
153eace7efcSopenharmony_ci
154eace7efcSopenharmony_ci    if (dataObsMgrInner_ == nullptr || dataObsMgrInnerExt_ == nullptr || dataObsMgrInnerPref_ == nullptr) {
155eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgr, uri:%{public}s",
156eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
157eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
158eace7efcSopenharmony_ci    }
159eace7efcSopenharmony_ci
160eace7efcSopenharmony_ci    {
161eace7efcSopenharmony_ci        std::lock_guard<ffrt::mutex> lck(taskCountMutex_);
162eace7efcSopenharmony_ci        if (taskCount_ >= TASK_COUNT_MAX) {
163eace7efcSopenharmony_ci            TAG_LOGE(AAFwkTag::DBOBSMGR, "task num reached limit, uri:%{public}s",
164eace7efcSopenharmony_ci                CommonUtils::Anonymous(uri.ToString()).c_str());
165eace7efcSopenharmony_ci            return DATAOBS_SERVICE_TASK_LIMMIT;
166eace7efcSopenharmony_ci        }
167eace7efcSopenharmony_ci        ++taskCount_;
168eace7efcSopenharmony_ci    }
169eace7efcSopenharmony_ci
170eace7efcSopenharmony_ci    ChangeInfo changeInfo = { ChangeInfo::ChangeType::OTHER, { uri } };
171eace7efcSopenharmony_ci    handler_->SubmitTask([this, uri, changeInfo]() {
172eace7efcSopenharmony_ci        if (const_cast<Uri &>(uri).GetScheme() == SHARE_PREFERENCES) {
173eace7efcSopenharmony_ci            dataObsMgrInnerPref_->HandleNotifyChange(uri);
174eace7efcSopenharmony_ci        } else {
175eace7efcSopenharmony_ci            dataObsMgrInner_->HandleNotifyChange(uri);
176eace7efcSopenharmony_ci            dataObsMgrInnerExt_->HandleNotifyChange(changeInfo);
177eace7efcSopenharmony_ci        }
178eace7efcSopenharmony_ci        std::lock_guard<ffrt::mutex> lck(taskCountMutex_);
179eace7efcSopenharmony_ci        --taskCount_;
180eace7efcSopenharmony_ci    });
181eace7efcSopenharmony_ci
182eace7efcSopenharmony_ci    return NO_ERROR;
183eace7efcSopenharmony_ci}
184eace7efcSopenharmony_ci
185eace7efcSopenharmony_ciStatus DataObsMgrService::RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver,
186eace7efcSopenharmony_ci    bool isDescendants)
187eace7efcSopenharmony_ci{
188eace7efcSopenharmony_ci    if (dataObserver == nullptr) {
189eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver, uri:%{public}s, isDescendants:%{public}d",
190eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str(), isDescendants);
191eace7efcSopenharmony_ci        return DATA_OBSERVER_IS_NULL;
192eace7efcSopenharmony_ci    }
193eace7efcSopenharmony_ci
194eace7efcSopenharmony_ci    if (dataObsMgrInnerExt_ == nullptr) {
195eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgrInner, uri:%{public}s, isDescendants:%{public}d",
196eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str(), isDescendants);
197eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
198eace7efcSopenharmony_ci    }
199eace7efcSopenharmony_ci
200eace7efcSopenharmony_ci    auto innerUri = uri;
201eace7efcSopenharmony_ci    return dataObsMgrInnerExt_->HandleRegisterObserver(innerUri, dataObserver, isDescendants);
202eace7efcSopenharmony_ci}
203eace7efcSopenharmony_ci
204eace7efcSopenharmony_ciStatus DataObsMgrService::UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver)
205eace7efcSopenharmony_ci{
206eace7efcSopenharmony_ci    if (dataObserver == nullptr) {
207eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver, uri:%{public}s",
208eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
209eace7efcSopenharmony_ci        return DATA_OBSERVER_IS_NULL;
210eace7efcSopenharmony_ci    }
211eace7efcSopenharmony_ci
212eace7efcSopenharmony_ci    if (dataObsMgrInnerExt_ == nullptr) {
213eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgrInner, uri:%{public}s",
214eace7efcSopenharmony_ci            CommonUtils::Anonymous(uri.ToString()).c_str());
215eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
216eace7efcSopenharmony_ci    }
217eace7efcSopenharmony_ci
218eace7efcSopenharmony_ci    auto innerUri = uri;
219eace7efcSopenharmony_ci    return dataObsMgrInnerExt_->HandleUnregisterObserver(innerUri, dataObserver);
220eace7efcSopenharmony_ci}
221eace7efcSopenharmony_ci
222eace7efcSopenharmony_ciStatus DataObsMgrService::UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver)
223eace7efcSopenharmony_ci{
224eace7efcSopenharmony_ci    if (dataObserver == nullptr) {
225eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver");
226eace7efcSopenharmony_ci        return DATA_OBSERVER_IS_NULL;
227eace7efcSopenharmony_ci    }
228eace7efcSopenharmony_ci
229eace7efcSopenharmony_ci    if (dataObsMgrInnerExt_ == nullptr) {
230eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObsMgrInner");
231eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
232eace7efcSopenharmony_ci    }
233eace7efcSopenharmony_ci
234eace7efcSopenharmony_ci    return dataObsMgrInnerExt_->HandleUnregisterObserver(dataObserver);
235eace7efcSopenharmony_ci}
236eace7efcSopenharmony_ci
237eace7efcSopenharmony_ciStatus DataObsMgrService::DeepCopyChangeInfo(const ChangeInfo &src, ChangeInfo &dst) const
238eace7efcSopenharmony_ci{
239eace7efcSopenharmony_ci    dst = src;
240eace7efcSopenharmony_ci    if (dst.size_ == 0) {
241eace7efcSopenharmony_ci        return SUCCESS;
242eace7efcSopenharmony_ci    }
243eace7efcSopenharmony_ci    dst.data_ = new (std::nothrow) uint8_t[dst.size_];
244eace7efcSopenharmony_ci    if (dst.data_ == nullptr) {
245eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
246eace7efcSopenharmony_ci    }
247eace7efcSopenharmony_ci
248eace7efcSopenharmony_ci    errno_t ret = memcpy_s(dst.data_, dst.size_, src.data_, src.size_);
249eace7efcSopenharmony_ci    if (ret != EOK) {
250eace7efcSopenharmony_ci        delete [] static_cast<uint8_t *>(dst.data_);
251eace7efcSopenharmony_ci        dst.data_ = nullptr;
252eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
253eace7efcSopenharmony_ci    }
254eace7efcSopenharmony_ci    return SUCCESS;
255eace7efcSopenharmony_ci}
256eace7efcSopenharmony_ci
257eace7efcSopenharmony_ciStatus DataObsMgrService::NotifyChangeExt(const ChangeInfo &changeInfo)
258eace7efcSopenharmony_ci{
259eace7efcSopenharmony_ci    if (handler_ == nullptr) {
260eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "null handler");
261eace7efcSopenharmony_ci        return DATAOBS_SERVICE_HANDLER_IS_NULL;
262eace7efcSopenharmony_ci    }
263eace7efcSopenharmony_ci
264eace7efcSopenharmony_ci    if (dataObsMgrInner_ == nullptr || dataObsMgrInnerExt_ == nullptr) {
265eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "dataObsMgrInner_:%{public}d or null dataObsMgrInnerExt",
266eace7efcSopenharmony_ci            dataObsMgrInner_ == nullptr);
267eace7efcSopenharmony_ci        return DATAOBS_SERVICE_INNER_IS_NULL;
268eace7efcSopenharmony_ci    }
269eace7efcSopenharmony_ci    ChangeInfo changes;
270eace7efcSopenharmony_ci    Status result = DeepCopyChangeInfo(changeInfo, changes);
271eace7efcSopenharmony_ci    if (result != SUCCESS) {
272eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR,
273eace7efcSopenharmony_ci            "copy data failed, changeType:%{public}ud,uris num:%{public}zu, "
274eace7efcSopenharmony_ci            "null data:%{public}d, size:%{public}ud",
275eace7efcSopenharmony_ci            changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_);
276eace7efcSopenharmony_ci        return result;
277eace7efcSopenharmony_ci    }
278eace7efcSopenharmony_ci
279eace7efcSopenharmony_ci    {
280eace7efcSopenharmony_ci        std::lock_guard<ffrt::mutex> lck(taskCountMutex_);
281eace7efcSopenharmony_ci        if (taskCount_ >= TASK_COUNT_MAX) {
282eace7efcSopenharmony_ci            TAG_LOGE(AAFwkTag::DBOBSMGR,
283eace7efcSopenharmony_ci                "task num maxed, changeType:%{public}ud,"
284eace7efcSopenharmony_ci                "uris num:%{public}zu, null data:%{public}d, size:%{public}ud",
285eace7efcSopenharmony_ci                changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_);
286eace7efcSopenharmony_ci            return DATAOBS_SERVICE_TASK_LIMMIT;
287eace7efcSopenharmony_ci        }
288eace7efcSopenharmony_ci        ++taskCount_;
289eace7efcSopenharmony_ci    }
290eace7efcSopenharmony_ci
291eace7efcSopenharmony_ci    handler_->SubmitTask([this, changes]() {
292eace7efcSopenharmony_ci        dataObsMgrInnerExt_->HandleNotifyChange(changes);
293eace7efcSopenharmony_ci        for (auto &uri : changes.uris_) {
294eace7efcSopenharmony_ci            dataObsMgrInner_->HandleNotifyChange(uri);
295eace7efcSopenharmony_ci        }
296eace7efcSopenharmony_ci        delete [] static_cast<uint8_t *>(changes.data_);
297eace7efcSopenharmony_ci        std::lock_guard<ffrt::mutex> lck(taskCountMutex_);
298eace7efcSopenharmony_ci        --taskCount_;
299eace7efcSopenharmony_ci    });
300eace7efcSopenharmony_ci    return SUCCESS;
301eace7efcSopenharmony_ci}
302eace7efcSopenharmony_ci
303eace7efcSopenharmony_ciint DataObsMgrService::Dump(int fd, const std::vector<std::u16string>& args)
304eace7efcSopenharmony_ci{
305eace7efcSopenharmony_ci    std::string result;
306eace7efcSopenharmony_ci    Dump(args, result);
307eace7efcSopenharmony_ci    int ret = dprintf(fd, "%s\n", result.c_str());
308eace7efcSopenharmony_ci    if (ret < 0) {
309eace7efcSopenharmony_ci        TAG_LOGE(AAFwkTag::DBOBSMGR, "dprintf error");
310eace7efcSopenharmony_ci        return DATAOBS_HIDUMP_ERROR;
311eace7efcSopenharmony_ci    }
312eace7efcSopenharmony_ci    return SUCCESS;
313eace7efcSopenharmony_ci}
314eace7efcSopenharmony_ci
315eace7efcSopenharmony_civoid DataObsMgrService::Dump(const std::vector<std::u16string>& args, std::string& result) const
316eace7efcSopenharmony_ci{
317eace7efcSopenharmony_ci    auto size = args.size();
318eace7efcSopenharmony_ci    if (size == 0) {
319eace7efcSopenharmony_ci        ShowHelp(result);
320eace7efcSopenharmony_ci        return;
321eace7efcSopenharmony_ci    }
322eace7efcSopenharmony_ci
323eace7efcSopenharmony_ci    std::string optionKey = Str16ToStr8(args[0]);
324eace7efcSopenharmony_ci    if (optionKey != "-h") {
325eace7efcSopenharmony_ci        result.append("error: unkown option.\n");
326eace7efcSopenharmony_ci    }
327eace7efcSopenharmony_ci    ShowHelp(result);
328eace7efcSopenharmony_ci}
329eace7efcSopenharmony_ci
330eace7efcSopenharmony_civoid DataObsMgrService::ShowHelp(std::string& result) const
331eace7efcSopenharmony_ci{
332eace7efcSopenharmony_ci    result.append("Usage:\n")
333eace7efcSopenharmony_ci        .append("-h                          ")
334eace7efcSopenharmony_ci        .append("help text for the tool\n");
335eace7efcSopenharmony_ci}
336eace7efcSopenharmony_ci}  // namespace AAFwk
337eace7efcSopenharmony_ci}  // namespace OHOS
338