• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(VolumeState notifyCode,std::shared_ptr<VolumeExternal> volume)33 void Notification::NotifyVolumeChange(VolumeState notifyCode, std::shared_ptr<VolumeExternal> volume)
34 {
35     AAFwk::Want want;
36     AAFwk::WantParams wantParams;
37     wantParams.SetParam("id", AAFwk::String::Box(volume->GetId()));
38     wantParams.SetParam("diskId", AAFwk::String::Box(volume->GetDiskId()));
39     wantParams.SetParam("fsUuid", AAFwk::String::Box(volume->GetUuid()));
40     switch (notifyCode) {
41         case VolumeState::REMOVED:
42             LOGI("notifycode: VOLUME_REMOVED");
43             want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_REMOVED);
44             break;
45         case VolumeState::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 VolumeState::MOUNTED:
51             LOGI("notifycode: VOLUME_MOUNTED");
52             wantParams.SetParam("volumeState", AAFwk::Integer::Box(MOUNTED));
53             wantParams.SetParam("path", AAFwk::String::Box(volume->GetPath()));
54             wantParams.SetParam("fsType", AAFwk::Integer::Box(volume->GetFsType()));
55             want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_MOUNTED);
56             break;
57         case VolumeState::BAD_REMOVAL:
58             LOGI("notifycode: VOLUME_BAD_REMOVAL");
59             want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_BAD_REMOVAL);
60             break;
61         case VolumeState::EJECTING:
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