• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H
17 #define NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "singleton.h"
23 #include "bundle_mgr_interface.h"
24 #include "remote_death_recipient.h"
25 
26 namespace OHOS::Notification {
27 class ReminderBundleManagerHelper : public DelayedRefSingleton<ReminderBundleManagerHelper> {
28 public:
29     ReminderBundleManagerHelper();
30     ~ReminderBundleManagerHelper();
31 
32     /**
33      * @brief Obtains the bundle name base on the specified uid.
34      *
35      * @param uid Indicates the specified uid.
36      * @return Returns the bundle name.
37      */
38     std::string GetBundleNameByUid(const int32_t uid);
39 
40     /**
41      * @brief Obtains the default uid.
42      *
43      * @param bundle Indicates the bundle name.
44      * @param userId Indicates the user id.
45      * @return Returns the uid.
46      */
47     int32_t GetDefaultUidByBundleName(const std::string& bundle, const int32_t userId);
48 
49     /**
50      * @brief Obtains bundle info by bundle name.
51      *
52      * @param bundleName Indicates the bundle name.
53      * @param flag Indicates the bundle flag.
54      * @param userId Indicates the user id.
55      * @param bundleInfo Indicates the bundle info.
56      * @return Returns the check result.
57      */
58     bool GetBundleInfo(const std::string& bundleName, const AppExecFwk::BundleFlag flag,
59         const int32_t userId, AppExecFwk::BundleInfo& bundleInfo);
60 
61     /**
62      * @brief Obtains the app index by uid.
63      *
64      * @param uid Indicates uid.
65      * @return Returns the query result if succeed, retrun 0(main index) otherwise.
66      */
67     int32_t GetAppIndexByUid(const int32_t uid);
68 
69 private:
70     void Connect();
71     void Disconnect();
72     void OnRemoteDied(const wptr<IRemoteObject>& object);
73 
74 private:
75     std::mutex mutex_;  // for bundleMgr_
76     sptr<AppExecFwk::IBundleMgr> bundleMgr_ {nullptr};
77     sptr<RemoteDeathRecipient> deathRecipient_ {nullptr};
78 };
79 }  // namespace OHOS::Notification
80 #endif  // NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H
81