1 /*
2  * Copyright (c) 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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BUNDLE_MANAGER_HELPER_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BUNDLE_MANAGER_HELPER_H
18 
19 #include "bundle_mgr_interface.h"
20 #include "ipc_skeleton.h"
21 #include "iremote_object.h"
22 #include "resource_manager.h"
23 #include "singleton.h"
24 
25 #include "remote_death_recipient.h"
26 
27 namespace OHOS {
28 namespace BackgroundTaskMgr {
29 using OHOS::AppExecFwk::Constants::UNSPECIFIED_USERID;
30 class BundleManagerHelper : public DelayedSingleton<BundleManagerHelper> {
31 public:
32     std::string GetClientBundleName(int32_t uid);
33     bool CheckPermission(const std::string &permission);
34     bool IsSystemApp(uint64_t fullTokenId);
35     bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag,
36         AppExecFwk::BundleInfo &bundleInfo, int32_t userId = UNSPECIFIED_USERID);
37     bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag,
38         const int userId, AppExecFwk::ApplicationInfo &appInfo);
39     bool QueryAbilityInfo(const AAFwk::Want &want, int32_t flags, int32_t userId,
40         AppExecFwk::AbilityInfo &abilityInfo);
41 
42 private:
43     bool Connect();
44     void Disconnect();
45     void OnRemoteDied(const wptr<IRemoteObject> &object);
46 
47 private:
48     sptr<AppExecFwk::IBundleMgr> bundleMgr_ = nullptr;
49     std::mutex connectionMutex_;
50     sptr<RemoteDeathRecipient> bundleMgrDeathRecipient_ = nullptr;
51 
52     DECLARE_DELAYED_SINGLETON(BundleManagerHelper)
53 };
54 }  // namespace BackgroundTaskMgr
55 }  // namespace OHOS
56 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BUNDLE_MANAGER_HELPER_H