1 /*
2  * Copyright (c) 2024 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_RUNTIME_APP_EXIT_REASON_HELPER
17 #define OHOS_ABILITY_RUNTIME_APP_EXIT_REASON_HELPER
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "bundle_info.h"
23 #include "exit_reason.h"
24 #include "sub_managers_helper.h"
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class AppExitReasonHelper {
29 public:
30     explicit AppExitReasonHelper(std::shared_ptr<SubManagersHelper> subManagersHelper);
31     ~AppExitReasonHelper() = default;
32 
33     int32_t RecordAppExitReason(const ExitReason &exitReason);
34     int32_t RecordAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex,
35         const ExitReason &exitReason);
36     int32_t RecordProcessExtensionExitReason(
37         const int32_t pid, const std::string &bundleName, const ExitReason &exitReason);
38     int32_t RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason);
39 
40 private:
41     int32_t RecordProcessExitReason(const int32_t pid, const std::string bundleName, const int32_t uid,
42         const uint32_t accessTokenId, const ExitReason &exitReason);
43     void GetActiveAbilityList(int32_t uid, std::vector<std::string> &abilityLists, const int32_t pid);
44     void GetActiveAbilityListFromUIAbilityManager(int32_t uid, std::vector<std::string> &abilityLists,
45         const int32_t pid);
46     bool IsExitReasonValid(const ExitReason &exitReason);
47 
48     std::shared_ptr<SubManagersHelper> subManagersHelper_;
49 };
50 }  // namespace AAFwk
51 }  // namespace OHOS
52 #endif  // OHOS_ABILITY_RUNTIME_APP_EXIT_REASON_HELPER
53