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 "media_analysis_callback_stub.h"
17
18 #include "media_log.h"
19 #include "media_file_utils.h"
20 #include "medialibrary_common_utils.h"
21 #include "medialibrary_errno.h"
22 #include "medialibrary_notify.h"
23 #include "photo_album_column.h"
24
25 namespace OHOS {
26 namespace Media {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int MediaAnalysisCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
28 MessageOption &option)
29 {
30 int errCode = ERR_UNKNOWN_TRANSACTION;
31
32 CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
33 std::string albumId = data.ReadString();
34 switch (code) {
35 case static_cast<uint32_t>(MediaAnalysisCallbackInterfaceCode::PORTRAIT_COVER_SELECTION_COMPLETED_CALLBACK):
36 errCode = MediaAnalysisCallbackStub::PortraitCoverSelectionCompleted(albumId);
37 break;
38 default:
39 MEDIA_ERR_LOG("MediaAnalysisCallbackStub request code %{public}u not handled", code);
40 errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
41 break;
42 }
43
44 return errCode;
45 }
46
PortraitCoverSelectionCompleted(const std::string albumId)47 int32_t MediaAnalysisCallbackStub::PortraitCoverSelectionCompleted(const std::string albumId)
48 {
49 MEDIA_INFO_LOG("PortraitCoverSelectionCompleted callback start, albumId: %{public}s", albumId.c_str());
50
51 if (albumId.empty()) {
52 MEDIA_ERR_LOG("PortraitCoverSelectionCompleted callback error, albumId is empty");
53 return ERR_INVALID_DATA;
54 }
55
56 auto watch = MediaLibraryNotify::GetInstance();
57 if (watch == nullptr) {
58 MEDIA_ERR_LOG("PortraitCoverSelectionCompleted Can not get MediaLibraryNotify Instance");
59 return ERR_NULL_OBJECT;
60 }
61
62 if (!MediaLibraryCommonUtils::CanConvertStrToInt32(albumId)) {
63 MEDIA_ERR_LOG("PortraitCoverSelectionCompleted Can not convert albumId to Int");
64 return ERR_INVALID_DATA;
65 }
66
67 int32_t ret =
68 watch->Notify(MediaFileUtils::GetUriByExtrConditions(PhotoAlbumColumns::ANALYSIS_ALBUM_URI_PREFIX, albumId),
69 NotifyType::NOTIFY_UPDATE, std::stoi(albumId));
70 if (ret != E_OK) {
71 MEDIA_ERR_LOG("PortraitCoverSelectionCompleted Notify error: %{public}d", ret);
72 return ret;
73 }
74
75 MEDIA_INFO_LOG("PortraitCoverSelectionCompleted callback end, albumId: %{public}s", albumId.c_str());
76 return ERR_NONE;
77 }
78 } // namespace Media
79 } // namespace OHOS