• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_BUNDLE_MANAGER_HELPER_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_BUNDLE_MANAGER_HELPER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "bundle_mgr_interface.h"
24 #include "ipc_skeleton.h"
25 #include "iremote_object.h"
26 #include "notification_bundle_option.h"
27 #include "refbase.h"
28 #include "remote_death_recipient.h"
29 #include "singleton.h"
30 
31 namespace OHOS {
32 namespace Notification {
33 class BundleManagerHelper : public DelayedSingleton<BundleManagerHelper> {
34 public:
35     /**
36      * @brief Obtains the bundle name base on the specified uid.
37      *
38      * @param uid Indicates the specified uid.
39      * @return Returns the bundle name.
40      */
41     std::string GetBundleNameByUid(int32_t uid);
42 
43     /**
44      * @brief Check whether the caller is a system application base on the specified uid.
45      *
46      * @param uid Indicates the specified uid.
47      * @return Returns the check result.
48      */
49     bool IsSystemApp(int32_t uid);
50 
51     /**
52      * @brief Check API compatibility.
53      *
54      * @param bundleOption Indicates the bundle option.
55      * @return Returns the check result.
56      */
57     bool CheckApiCompatibility(const sptr<NotificationBundleOption> &bundleOption);
58 
59     /**
60      * @brief Obtains the default uid.
61      *
62      * @param bundle Indicates the bundle name.
63      * @param userId Indicates the user id.
64      * @return Returns the uid.
65      */
66     int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId);
67 
68     /**
69      * @brief Obtains the bundle info.
70      *
71      * @param bundle Indicates the bundle name.
72      * @param userId Indicates the user id.
73      * @param bundleInfo Indicates the bundle info.
74      * @return Returns the uid.
75      */
76     bool GetBundleInfoByBundleName(const std::string bundle, const int32_t userId, AppExecFwk::BundleInfo &bundleInfo);
77 
78 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
79     /**
80      * @brief Check whether the specified bundle has the distributed notification supported.
81      *
82      * @param bundleName Indicates the bundle name.
83      * @param userId Indicates the user id.
84      * @return Returns the check result.
85      */
86     bool GetDistributedNotificationEnabled(const std::string &bundleName, const int32_t userId);
87 #endif
88 
89 private:
90     void Connect();
91     void Disconnect();
92 
93     void OnRemoteDied(const wptr<IRemoteObject> &object);
94 
95 private:
96     sptr<AppExecFwk::IBundleMgr> bundleMgr_ = nullptr;
97     std::mutex connectionMutex_;
98     sptr<RemoteDeathRecipient> deathRecipient_ = nullptr;
99 
100     DECLARE_DELAYED_SINGLETON(BundleManagerHelper)
101 };
102 }  // namespace Notification
103 }  // namespace OHOS
104 
105 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_BUNDLE_MANAGER_HELPER_H