1 /*
2 * Copyright (c) 2021 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 "volume/notification.h"
17
18 #include "common_event_data.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 #include "int_wrapper.h"
22 #include "storage_service_log.h"
23 #include "string_wrapper.h"
24 #include "volume_core.h"
25 #include "want.h"
26 #include "want_params.h"
27
28 namespace OHOS {
29 namespace StorageManager {
Notification()30 Notification::Notification() {}
~Notification()31 Notification::~Notification() {}
32
NotifyVolumeChange(int32_t notifyCode,std::string id,std::string diskId,std::string fsUuid,std::string path)33 void Notification::NotifyVolumeChange(int32_t notifyCode, std::string id, std::string diskId,
34 std::string fsUuid, std::string path)
35 {
36 AAFwk::Want want;
37 AAFwk::WantParams wantParams;
38 wantParams.SetParam("id", AAFwk::String::Box(id));
39 wantParams.SetParam("diskId", AAFwk::String::Box(diskId));
40 switch (notifyCode) {
41 case VOLUME_REMOVED:
42 LOGI("notifycode: VOLUME_REMOVED");
43 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_REMOVED);
44 break;
45 case VOLUME_UNMOUNTED:
46 LOGI("notifycode: VOLUME_UNMOUNTED");
47 wantParams.SetParam("volumeState", AAFwk::Integer::Box(UNMOUNTED));
48 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED);
49 break;
50 case VOLUME_MOUNTED:
51 LOGI("notifycode: VOLUME_MOUNTED");
52 wantParams.SetParam("volumeState", AAFwk::Integer::Box(MOUNTED));
53 wantParams.SetParam("fsUuid", AAFwk::String::Box(fsUuid));
54 wantParams.SetParam("path", AAFwk::String::Box(path));
55 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_MOUNTED);
56 break;
57 case VOLUME_BAD_REMOVAL:
58 LOGI("notifycode: VOLUME_BAD_REMOVAL");
59 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_BAD_REMOVAL);
60 break;
61 case VOLUME_EJECT:
62 LOGI("notifycode: VOLUME_EJECT");
63 wantParams.SetParam("volumeState", AAFwk::Integer::Box(EJECTING));
64 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT);
65 break;
66 default: {
67 break;
68 }
69 }
70 want.SetParams(wantParams);
71 EventFwk::CommonEventData commonData { want };
72 EventFwk::CommonEventManager::PublishCommonEvent(commonData);
73 }
74 }
75 } // namespace OHOS
76