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