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_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_INNER_APP_QUICK_FIX_H
17 #define FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_INNER_APP_QUICK_FIX_H
18 
19 #include <string>
20 
21 #include "nlohmann/json_fwd.hpp"
22 #include "nocopyable.h"
23 
24 #include "app_quick_fix.h"
25 #include "appqf_info.h"
26 #include "hqf_info.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 enum QuickFixStatus : int32_t {
31     DEFAULT_STATUS = 0,
32     DEPLOY_START,
33     DEPLOY_END,
34     SWITCH_ENABLE_START,
35     SWITCH_DISABLE_START,
36     SWITCH_END,
37     DELETE_START,
38     DELETE_END
39 };
40 
41 struct QuickFixMark {
42     std::string bundleName;
43     int32_t status = QuickFixStatus::DEFAULT_STATUS;
44 };
45 
46 class InnerAppQuickFix {
47 public:
48     InnerAppQuickFix();
49     InnerAppQuickFix(const AppQuickFix &appQuickFix, const QuickFixMark &mark);
50     ~InnerAppQuickFix();
51 
52     void SetAppQuickFix(const AppQuickFix &appQuickFix);
53 
54     AppQuickFix GetAppQuickFix() const;
55 
56     bool AddHqfInfo(const AppQuickFix &newInfo);
57 
58     bool RemoveHqfInfo(const std::string &moduleName);
59 
60     void SwitchQuickFix();
61 
62     void SetQuickFixMark(const QuickFixMark &mark);
63 
64     QuickFixMark GetQuickFixMark() const;
65 
66     std::string ToString() const;
67 
68     void ToJson(nlohmann::json &jsonObject) const;
69 
70     int32_t FromJson(const nlohmann::json &jsonObject);
71 
72 private:
73     AppQuickFix appQuickFix_;
74     QuickFixMark quickFixMark_;
75 };
76 void to_json(nlohmann::json &jsonObject, const QuickFixMark &quickFixMark);
77 void from_json(const nlohmann::json &jsonObject, QuickFixMark &quickFixMark);
78 } // AppExecFwk
79 } // OHOS
80 #endif // FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_INNER_APP_QUICK_FIX_H