12dc7c57fSopenharmony_ci/*
22dc7c57fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
32dc7c57fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
42dc7c57fSopenharmony_ci * you may not use this file except in compliance with the License.
52dc7c57fSopenharmony_ci * You may obtain a copy of the License at
62dc7c57fSopenharmony_ci *
72dc7c57fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
82dc7c57fSopenharmony_ci *
92dc7c57fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
102dc7c57fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
112dc7c57fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122dc7c57fSopenharmony_ci * See the License for the specific language governing permissions and
132dc7c57fSopenharmony_ci * limitations under the License.
142dc7c57fSopenharmony_ci */
152dc7c57fSopenharmony_ci
162dc7c57fSopenharmony_ci#ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H
172dc7c57fSopenharmony_ci#define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H
182dc7c57fSopenharmony_ci
192dc7c57fSopenharmony_ci#include <string>
202dc7c57fSopenharmony_ci#include <vector>
212dc7c57fSopenharmony_ci
222dc7c57fSopenharmony_ci#include "bms_death_recipient.h"
232dc7c57fSopenharmony_ci#include "bundle_mgr_interface.h"
242dc7c57fSopenharmony_ci#include "extension_ability_info.h"
252dc7c57fSopenharmony_ci#include "iremote_object.h"
262dc7c57fSopenharmony_ci#include "refbase.h"
272dc7c57fSopenharmony_ci#include "singleton.h"
282dc7c57fSopenharmony_ci#include "want.h"
292dc7c57fSopenharmony_ci
302dc7c57fSopenharmony_cinamespace OHOS {
312dc7c57fSopenharmony_cinamespace EventFwk {
322dc7c57fSopenharmony_ci
332dc7c57fSopenharmony_ciclass BundleManagerHelper : public DelayedSingleton<BundleManagerHelper> {
342dc7c57fSopenharmony_cipublic:
352dc7c57fSopenharmony_ci    using IBundleMgr = OHOS::AppExecFwk::IBundleMgr;
362dc7c57fSopenharmony_ci
372dc7c57fSopenharmony_ci    BundleManagerHelper();
382dc7c57fSopenharmony_ci
392dc7c57fSopenharmony_ci    virtual ~BundleManagerHelper();
402dc7c57fSopenharmony_ci
412dc7c57fSopenharmony_ci    /**
422dc7c57fSopenharmony_ci     * Checks whether it is system application.
432dc7c57fSopenharmony_ci     *
442dc7c57fSopenharmony_ci     * @param uid Indicates the uid of the application.
452dc7c57fSopenharmony_ci     * @return Returns true if successful; false otherwise.
462dc7c57fSopenharmony_ci     */
472dc7c57fSopenharmony_ci    bool CheckIsSystemAppByUid(const uid_t uid);
482dc7c57fSopenharmony_ci
492dc7c57fSopenharmony_ci    bool CheckIsSystemAppByBundleName(const std::string &bundleName, const int32_t &userId);
502dc7c57fSopenharmony_ci
512dc7c57fSopenharmony_ci    /**
522dc7c57fSopenharmony_ci     * Gets bundle name.
532dc7c57fSopenharmony_ci     *
542dc7c57fSopenharmony_ci     * @param uid Indicates the uid of the application.
552dc7c57fSopenharmony_ci     * @return Returns the bundle name.
562dc7c57fSopenharmony_ci     */
572dc7c57fSopenharmony_ci    std::string GetBundleName(const uid_t uid);
582dc7c57fSopenharmony_ci
592dc7c57fSopenharmony_ci    /**
602dc7c57fSopenharmony_ci     * Queries extension information.
612dc7c57fSopenharmony_ci     *
622dc7c57fSopenharmony_ci     * @param extensionInfo Indicates the extension information.
632dc7c57fSopenharmony_ci     * @return Returns true if successful; false otherwise.
642dc7c57fSopenharmony_ci     */
652dc7c57fSopenharmony_ci    bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfo);
662dc7c57fSopenharmony_ci
672dc7c57fSopenharmony_ci    /**
682dc7c57fSopenharmony_ci     * Queries extension information by user.
692dc7c57fSopenharmony_ci     *
702dc7c57fSopenharmony_ci     * @param extensionInfos Indicates the extension information.
712dc7c57fSopenharmony_ci     * @param userId Indicates the ID of user.
722dc7c57fSopenharmony_ci     * @return Returns true if successful; false otherwise.
732dc7c57fSopenharmony_ci     */
742dc7c57fSopenharmony_ci    bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos,
752dc7c57fSopenharmony_ci        const int32_t &userId);
762dc7c57fSopenharmony_ci
772dc7c57fSopenharmony_ci    /**
782dc7c57fSopenharmony_ci     * Gets res config file.
792dc7c57fSopenharmony_ci     *
802dc7c57fSopenharmony_ci     * @param extension Indicates the extension information.
812dc7c57fSopenharmony_ci     * @param profileInfos Indicates the profile information.
822dc7c57fSopenharmony_ci     * @return Returns true if successful; false otherwise.
832dc7c57fSopenharmony_ci     */
842dc7c57fSopenharmony_ci    bool GetResConfigFile(const AppExecFwk::ExtensionAbilityInfo &extension,
852dc7c57fSopenharmony_ci        std::vector<std::string> &profileInfos);
862dc7c57fSopenharmony_ci
872dc7c57fSopenharmony_ci    /**
882dc7c57fSopenharmony_ci     * Clears bundle manager helper.
892dc7c57fSopenharmony_ci     *
902dc7c57fSopenharmony_ci     */
912dc7c57fSopenharmony_ci    void ClearBundleManagerHelper();
922dc7c57fSopenharmony_ci
932dc7c57fSopenharmony_ci    /**
942dc7c57fSopenharmony_ci     * @brief Obtains information about all installed applications of current user.
952dc7c57fSopenharmony_ci     * @param flag Indicates the flag used to specify information contained
962dc7c57fSopenharmony_ci     *             in the ApplicationInfo objects that will be returned.
972dc7c57fSopenharmony_ci     * @param appInfos Indicates all of the obtained ApplicationInfo objects.
982dc7c57fSopenharmony_ci     * @return Returns true if the application is successfully obtained; returns false otherwise.
992dc7c57fSopenharmony_ci     */
1002dc7c57fSopenharmony_ci    bool GetApplicationInfos(const AppExecFwk::ApplicationFlag &flag,
1012dc7c57fSopenharmony_ci        std::vector<AppExecFwk::ApplicationInfo> &appInfos);
1022dc7c57fSopenharmony_ci
1032dc7c57fSopenharmony_ciprivate:
1042dc7c57fSopenharmony_ci    bool GetBundleMgrProxy();
1052dc7c57fSopenharmony_ci    bool GetBundleMgrProxyAsync();
1062dc7c57fSopenharmony_ci    bool GetBundleMgrProxyInner(bool isAsync);
1072dc7c57fSopenharmony_ci
1082dc7c57fSopenharmony_ciprivate:
1092dc7c57fSopenharmony_ci    sptr<IBundleMgr> sptrBundleMgr_;
1102dc7c57fSopenharmony_ci    std::mutex mutex_;
1112dc7c57fSopenharmony_ci    sptr<BMSDeathRecipient> bmsDeath_;
1122dc7c57fSopenharmony_ci};
1132dc7c57fSopenharmony_ci}  // namespace EventFwk
1142dc7c57fSopenharmony_ci}  // namespace OHOS
1152dc7c57fSopenharmony_ci
1162dc7c57fSopenharmony_ci#endif  // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H