• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_APPEXECFWK_KITS_APPKIT_NATIVE_BUNDLE_INCLUDE_BUNDLE_MGR_PROXY_NATIVE_H
17 #define FOUNDATION_APPEXECFWK_KITS_APPKIT_NATIVE_BUNDLE_INCLUDE_BUNDLE_MGR_PROXY_NATIVE_H
18 
19 #include <string>
20 
21 #include "application_info.h"
22 #include "iremote_broker.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class BundleMgrProxyNative {
28 public:
29     BundleMgrProxyNative() = default;
30     virtual ~BundleMgrProxyNative() = default;
31     /**
32      * @brief Obtains the bundle name of a specified application based on the given UID through the proxy object.
33      * @param uid Indicates the uid.
34      * @param bundleName Indicates the obtained bundle name.
35      * @return Returns true if the bundle name is successfully obtained; returns false otherwise.
36      */
37     bool GetBundleNameForUid(const int uid, std::string &bundleName);
38     /**
39      * @brief Obtains the ApplicationInfo based on a given bundle name through the proxy object.
40      * @param appName Indicates the application bundle name to be queried.
41      * @param flag Indicates the flag used to specify information contained
42      *             in the ApplicationInfo object that will be returned.
43      * @param userId Indicates the user ID.
44      * @param appInfo Indicates the obtained ApplicationInfo object.
45      * @return Returns true if the application is successfully obtained; returns false otherwise.
46      */
47     bool GetApplicationInfo(
48         const std::string &appName, ApplicationFlag flags, int32_t userId, ApplicationInfo &appInfo);
49 
50     enum {
51         GET_APPLICATION_INFO = 0,
52         GET_BUNDLE_NAME_FOR_UID = 7,
53     };
54 private:
55     sptr<IRemoteObject> GetBmsProxy();
56     template <typename T>
57     bool GetParcelableInfo(uint32_t code, MessageParcel &data, T &parcelableInfo);
58     bool SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply);
59 };
60 }  // namespace AppExecFwk
61 }  // namespace OHOS
62 #endif  // FOUNDATION_APPEXECFWK_KITS_APPKIT_NATIVE_BUNDLE_INCLUDE_BUNDLE_MGR_PROXY_NATIVE_H