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_INTERFACE_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_STATUS_CALLBACK_INTERFACE_H
18 
19 #include "iremote_broker.h"
20 #include "bundle_constants.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 enum class InstallType { INSTALL_CALLBACK, UNINSTALL_CALLBACK };
25 
26 class IBundleStatusCallback : public IRemoteBroker {
27 public:
28     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.BundleStatusCallback");
29     /**
30      * @brief Called when the installation, update, or uninstallation state of an application changes.
31      * @param installType Indicates the installation, update, or uninstallation state.
32      *                    The value <b>0</b> indicates that the application is being installed or updated,
33      *                    and <b>1</b> indicates that the application is being uninstalled.
34      * @param resultCode Indicates the status code returned for the application installation, update, or uninstallation
35      *                   result.
36      * @param resultMessage Indicates the result message returned with the status code.
37      * @param bundleName Indicates the name of the bundle whose state has changed.
38      */
39     virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg,
40         const std::string &bundleName) = 0;
41     /**
42      * @brief Called when a new application package has been installed on the device.
43      * @param bundleName Indicates the name of the bundle whose state has been installed.
44      * @param userId Indicates the id of the bundle whose state has been installed.
45      */
46     virtual void OnBundleAdded(const std::string &bundleName, const int userId) = 0;
47 
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)
49     {
50         OnBundleAdded(bundleName, userId);
51     }
52 
53     /**
54      * @brief Called when a new application package has been Updated on the device.
55      * @param bundleName Indicates the name of the bundle whose state has been Updated.
56      * @param userId Indicates the id of the bundle whose state has been Updated.
57      */
58     virtual void OnBundleUpdated(const std::string &bundleName, const int userId) = 0;
59 
OnBundleUpdated(const std::string & bundleName,const int userId,const int32_t appIndex)60     virtual void OnBundleUpdated(const std::string &bundleName, const int userId, const int32_t appIndex)
61     {
62         OnBundleUpdated(bundleName, userId);
63     }
64 
65     /**
66      * @brief Called when a new application package has been Removed on the device.
67      * @param bundleName Indicates the name of the bundle whose state has been Removed.
68      * @param userId Indicates the id of the bundle whose state has been Removed.
69      */
70     virtual void OnBundleRemoved(const std::string &bundleName, const int userId) = 0;
71 
OnBundleRemoved(const std::string & bundleName,const int userId,const int32_t appIndex)72     virtual void OnBundleRemoved(const std::string &bundleName, const int userId, const int32_t appIndex)
73     {
74         OnBundleRemoved(bundleName, userId);
75     }
76 
GetBundleName()77     std::string GetBundleName()
78     {
79         return bundleName_;
80     }
81 
SetBundleName(const std::string & bundleName)82     void SetBundleName(const std::string &bundleName)
83     {
84         bundleName_ = bundleName;
85     }
86 
GetUserId()87     int32_t GetUserId()
88     {
89         return userId_;
90     }
91 
SetUserId(const int32_t userId)92     void SetUserId(const int32_t userId)
93     {
94         userId_ = userId;
95     }
96 
97 private:
98     std::string bundleName_;
99     int32_t userId_ = Constants::UNSPECIFIED_USERID;
100 };
101 }  // namespace AppExecFwk
102 }  // namespace OHOS
103 
104 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_STATUS_CALLBACK_INTERFACE_H
105