• 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PERMISSIONS_CHANGED_MONITOR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PERMISSIONS_CHANGED_MONITOR_H
18 #include <future>
19 #include "bundle_mgr_host.h"
20 #include "bundle_data_mgr.h"
21 #include "common_event_manager.h"
22 #include "common_event_support.h"
23 #include "common_event_subscriber.h"
24 #include "common_event_subscribe_info.h"
25 #include "bundle_util.h"
26 
27 #include "bundle_data_mgr.h"
28 #include "json_serializer.h"
29 #include "app_log_wrapper.h"
30 
31 
32 #include "bundle_parser.h"
33 #include "installd_client.h"
34 #include "bundle_permission_mgr.h"
35 
36 namespace OHOS {
37 namespace AppExecFwk {
38 class BundlePermissionsChangedMonitor : public EventFwk::CommonEventSubscriber {
39 public:
BundlePermissionsChangedMonitor(const std::shared_ptr<BundleDataMgr> & dataMgr,const EventFwk::CommonEventSubscribeInfo & sp)40     BundlePermissionsChangedMonitor(const std::shared_ptr<BundleDataMgr> &dataMgr,
41                 const EventFwk::CommonEventSubscribeInfo& sp):CommonEventSubscriber(sp)
42     {
43         dataMgr_ = dataMgr;
44     }
~BundlePermissionsChangedMonitor()45     ~BundlePermissionsChangedMonitor()
46     {
47         if (!dataMgr_) {
48             dataMgr_.reset();
49         }
50     }
OnReceiveEvent(const EventFwk::CommonEventData & data)51     void OnReceiveEvent(const EventFwk::CommonEventData &data)
52     {
53         OHOS::AAFwk::Want want = data.GetWant();
54         std::string action = want.GetAction();
55         int32_t uid = data.GetCode();
56         if ((dataMgr_ != nullptr) && (uid >= 0)) {
57             dataMgr_->NotifyPermissionsChanged(uid);
58         }
59     }
60 private:
61     std::shared_ptr<BundleDataMgr> dataMgr_;
62 };
63 }  // namespace AppExecFwk
64 }  // namespace OHOS
65 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MONITOR_H