• 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 OHOS_ABILITY_ABILITY_RECOVERY_H
17 #define OHOS_ABILITY_ABILITY_RECOVERY_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "ability.h"
23 #include "ability_info.h"
24 #include "application_info.h"
25 #include "event_handler.h"
26 #include "iremote_object.h"
27 #include "parcel.h"
28 #include "recovery_param.h"
29 #include "want.h"
30 #include "want_params.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class AbilityRecovery {
35 public:
36     AbilityRecovery();
37     virtual ~AbilityRecovery();
38     void EnableAbilityRecovery(uint16_t restartFlag, uint16_t saveFlag, uint16_t saveMode);
39     bool InitAbilityInfo(const std::shared_ptr<Ability> ability,
40         const std::shared_ptr<AbilityInfo>& abilityInfo, const sptr<IRemoteObject>& token);
41     bool ScheduleSaveAbilityState(StateReason reason);
42     bool ScheduleRecoverAbility(StateReason reason, const Want *want = nullptr);
43     bool ScheduleRestoreAbilityState(StateReason reason, const Want &want);
44     bool CallOnRestoreAbilityState(StateReason reason);
45     bool PersistState();
46     bool IsOnForeground();
47     bool IsSameAbility(uintptr_t ability);
48     void SetJsAbility(uintptr_t ability);
49     std::string GetSavedPageStack(StateReason reason);
50     uint16_t GetRestartFlag() const;
51     uint16_t GetSaveOccasionFlag() const;
52     uint16_t GetSaveModeFlag() const;
53     int32_t missionId_ = -1;
54 
GetToken()55     wptr<IRemoteObject> GetToken() const
56     {
57         return token_;
58     }
59 private:
60     bool SaveAbilityState();
61     bool SerializeDataToFile(int32_t savedStateId, AAFwk::WantParams& params);
62     bool ReadSerializeDataFromFile(int32_t savedStateId, AAFwk::WantParams& params);
63     bool LoadSavedState(StateReason reason);
64     bool IsSaveAbilityState(StateReason reason);
65 
66     bool isEnable_;
67     uint16_t restartFlag_;
68     uint16_t saveOccasion_;
69     uint16_t saveMode_;
70     std::weak_ptr<AppExecFwk::Ability> ability_;
71     std::weak_ptr<AppExecFwk::AbilityInfo> abilityInfo_;
72     uintptr_t jsAbilityPtr_;
73     wptr<IRemoteObject> token_;
74     std::string pageStack_;
75     WantParams params_;
76     bool hasTryLoad_ = false;
77     bool hasLoaded_ = false;
78     std::mutex lock_;
79 };
80 }  // namespace AbilityRuntime
81 }  // namespace OHOS
82 #endif // OHOS_ABILITY_ABILITY_RECOVERY_H