1 /*
2  * Copyright (c) 2021 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_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_STATUS_CALLBACK_PROXY_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_STATUS_CALLBACK_PROXY_H
18 
19 #include <unordered_map>
20 
21 #include "bundle_status_callback_interface.h"
22 #include "iremote_proxy.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class BundleStatusCallbackProxy : public IRemoteProxy<IBundleStatusCallback> {
27 public:
28     explicit BundleStatusCallbackProxy(const sptr<IRemoteObject> &object);
29     virtual ~BundleStatusCallbackProxy() override;
30     /**
31      * @brief Called when the installation, update, or uninstallation state of an application changes from proxy side.
32      * @param installType Indicates the installation, update, or uninstallation state.
33      *                    The value <b>0</b> indicates that the application is being installed or updated,
34      *                    and <b>1</b> indicates that the application is being uninstalled.
35      * @param resultCode Indicates the status code returned for the application installation, update, or uninstallation
36      *                   result.
37      * @param resultMessage Indicates the result message returned with the status code.
38      * @param bundleName Indicates the name of the bundle whose state has changed.
39      */
40     virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg,
41         const std::string &bundleName) override;
42     /**
43      * @brief Called when a new application package has been installed on the device.
44      * @param bundleName Indicates the name of the bundle whose state has been installed.
45      * @param userId Indicates the id of the bundle whose state has been installed.
46      */
OnBundleAdded(const std::string & bundleName,const int userId)47     virtual void OnBundleAdded(const std::string &bundleName, const int userId) override {};
OnBundleAdded(const std::string & bundleName,const int userId,const int32_t appIndex)48     virtual void OnBundleAdded(const std::string &bundleName, const int userId, const int32_t appIndex) override {};
49     /**
50      * @brief Called when a new application package has been Updated on the device.
51      * @param bundleName Indicates the name of the bundle whose state has been Updated.
52      * @param userId Indicates the id of the bundle whose state has been Updated.
53      */
OnBundleUpdated(const std::string & bundleName,const int userId)54     virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override {};
OnBundleUpdated(const std::string & bundleName,const int userId,const int32_t appIndex)55     virtual void OnBundleUpdated(const std::string &bundleName, const int userId, const int32_t appIndex) override {};
56     /**
57      * @brief Called when a new application package has been Removed on the device.
58      * @param bundleName Indicates the name of the bundle whose state has been Removed.
59      * @param userId Indicates the id of the bundle whose state has been Removed.
60      */
OnBundleRemoved(const std::string & bundleName,const int userId)61     virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override {};
OnBundleRemoved(const std::string & bundleName,const int userId,const int32_t appIndex)62     virtual void OnBundleRemoved(const std::string &bundleName, const int userId, const int32_t appIndex) override {};
63 
64 private:
65     void InitResultMap();
66 
67     std::unordered_map<int32_t, std::string> resultMap_;
68     static inline BrokerDelegator<BundleStatusCallbackProxy> delegator_;
69 };
70 }  // namespace AppExecFwk
71 }  // namespace OHOS
72 
73 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_STATUS_CALLBACK_PROXY_H
74