1 /*
2 * Copyright (C) 2025 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 #define MLOG_TAG "CustomRestoreNotify"
16
17 #include "medialibrary_custom_restore_notify.h"
18
19 #include "dataobs_mgr_client.h"
20 #include "media_log.h"
21 #include "medialibrary_errno.h"
22
23 namespace OHOS::Media {
24 const std::string CustomRestoreNotify::NOTIFY_URI_PREFIX = "file://media/custom_restore/";
Notify(std::string keyPath,const InnerRestoreResult & restoreResult)25 int32_t CustomRestoreNotify::Notify(std::string keyPath, const InnerRestoreResult &restoreResult)
26 {
27 auto obsMgrClient = AAFwk::DataObsMgrClient::GetInstance();
28 if (obsMgrClient == nullptr) {
29 MEDIA_ERR_LOG("obsMgrClient is nullptr");
30 return E_DATA_OBS_MGR_CLIENT_IS_NULL;
31 }
32 AAFwk::ChangeInfo::VBucket vBucket;
33 vBucket["stage"] = restoreResult.stage;
34 vBucket["errCode"] = restoreResult.errCode;
35 vBucket["progress"] = restoreResult.progress;
36 vBucket["uriType"] = restoreResult.uriType;
37 vBucket["uri"] = restoreResult.uri;
38 vBucket["totalNum"] = restoreResult.totalNum;
39 vBucket["successNum"] = restoreResult.successNum;
40 vBucket["failedNum"] = restoreResult.failedNum;
41 vBucket["sameNum"] = restoreResult.sameNum;
42 vBucket["cancelNum"] = restoreResult.cancelNum;
43 // notify callback
44 Uri customRestoreUri(NOTIFY_URI_PREFIX + keyPath);
45 AAFwk::ChangeInfo changeInfo = {
46 AAFwk::ChangeInfo::ChangeType::INSERT, { customRestoreUri }, nullptr, 0, { vBucket }
47 };
48 int result = obsMgrClient->NotifyChangeExt(changeInfo);
49 MEDIA_DEBUG_LOG("NotifyChangeExt result: %{public}d", result);
50 return result;
51 }
52
53 } // namespace OHOS::Media
54