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