Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_APEXD_APEXD_H_ |
| 18 | #define ANDROID_APEXD_APEXD_H_ |
| 19 | |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 20 | #include <string> |
Andreas Gampe | 0fa59af | 2018-11-16 11:12:11 -0800 | [diff] [blame] | 21 | #include <vector> |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 22 | |
| 23 | #include <android-base/macros.h> |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 24 | #include <android-base/result.h> |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 25 | |
Jiyong Park | 5e81023 | 2019-04-01 15:24:26 +0900 | [diff] [blame] | 26 | #include "apex_constants.h" |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 27 | #include "apex_file.h" |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 28 | |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace apex { |
| 31 | |
Andreas Gampe | 6aaa2fe | 2019-03-29 14:13:59 -0700 | [diff] [blame] | 32 | class CheckpointInterface; |
| 33 | |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 34 | android::base::Result<void> resumeRevertIfNeeded(); |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 35 | |
Nikita Ioffe | 6934944 | 2020-02-06 13:17:22 +0000 | [diff] [blame] | 36 | // Keep it for now to make otapreopt_chroot keep happy. |
| 37 | // TODO(b/137086602): remove this function. |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 38 | android::base::Result<void> scanPackagesDirAndActivate( |
| 39 | const char* apex_package_dir); |
Dario Freni | 7f0da58 | 2019-01-06 17:54:13 +0000 | [diff] [blame] | 40 | void scanStagedSessionsDirAndStage(); |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 41 | android::base::Result<void> preinstallPackages( |
| 42 | const std::vector<std::string>& paths) WARN_UNUSED; |
| 43 | android::base::Result<void> postinstallPackages( |
| 44 | const std::vector<std::string>& paths) WARN_UNUSED; |
Andreas Gampe | 0e43530 | 2018-12-21 15:40:19 -0800 | [diff] [blame] | 45 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 46 | android::base::Result<void> stagePackages( |
| 47 | const std::vector<std::string>& tmpPaths) WARN_UNUSED; |
| 48 | android::base::Result<void> unstagePackages( |
| 49 | const std::vector<std::string>& paths) WARN_UNUSED; |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 50 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 51 | android::base::Result<std::vector<ApexFile>> submitStagedSession( |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 52 | const int session_id, const std::vector<int>& child_session_ids, |
| 53 | const bool has_rollback_enabled, const bool is_rollback, |
| 54 | const int rollback_id) WARN_UNUSED; |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 55 | android::base::Result<void> markStagedSessionReady(const int session_id) |
| 56 | WARN_UNUSED; |
| 57 | android::base::Result<void> markStagedSessionSuccessful(const int session_id) |
| 58 | WARN_UNUSED; |
Gavin Corkery | 92cd7b8 | 2020-01-13 12:35:38 +0000 | [diff] [blame] | 59 | android::base::Result<void> revertActiveSessions( |
| 60 | const std::string& crashing_native_process); |
| 61 | android::base::Result<void> revertActiveSessionsAndReboot( |
| 62 | const std::string& crashing_native_process); |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 63 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 64 | android::base::Result<void> activatePackage(const std::string& full_path) |
| 65 | WARN_UNUSED; |
| 66 | android::base::Result<void> deactivatePackage(const std::string& full_path) |
| 67 | WARN_UNUSED; |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 68 | |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 69 | std::vector<ApexFile> getActivePackages(); |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 70 | android::base::Result<ApexFile> getActivePackage( |
| 71 | const std::string& package_name); |
Andreas Gampe | 0fa59af | 2018-11-16 11:12:11 -0800 | [diff] [blame] | 72 | |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 73 | std::vector<ApexFile> getFactoryPackages(); |
| 74 | |
Mohammad Samiul Islam | 4654f77 | 2019-11-20 15:19:07 +0000 | [diff] [blame] | 75 | android::base::Result<void> abortStagedSession(const int session_id); |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 76 | android::base::Result<void> abortActiveSession(); |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 77 | |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 78 | android::base::Result<ino_t> snapshotCeData(const int user_id, |
| 79 | const int rollback_id, |
| 80 | const std::string& apex_name); |
| 81 | android::base::Result<void> restoreCeData(const int user_id, |
| 82 | const int rollback_id, |
| 83 | const std::string& apex_name); |
Oli Lan | 042fbcf | 2020-01-17 11:14:16 +0000 | [diff] [blame] | 84 | android::base::Result<void> destroyDeSnapshots(const int rollback_id); |
Oli Lan | 2993ccc | 2020-03-06 18:06:40 +0000 | [diff] [blame] | 85 | android::base::Result<void> destroyCeSnapshotsNotSpecified( |
| 86 | int user_id, const std::vector<int>& retain_rollback_ids); |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 87 | |
Jiyong Park | 715e23d | 2019-02-22 22:14:37 +0900 | [diff] [blame] | 88 | int onBootstrap(); |
Nikita Ioffe | dee4b6e | 2020-04-22 01:01:17 +0100 | [diff] [blame] | 89 | // Small helper function to tell if device is currently booting. |
| 90 | bool isBooting(); |
Oli Lan | 30e598c | 2020-05-15 17:00:26 +0100 | [diff] [blame] | 91 | // Sets the values of gVoldService and gInFsCheckpointMode. |
| 92 | void initializeVold(CheckpointInterface* checkpoint_service); |
Nikita Ioffe | dee4b6e | 2020-04-22 01:01:17 +0100 | [diff] [blame] | 93 | // Initializes in-memory state (e.g. pre-installed data, activated apexes). |
| 94 | // Must be called first before calling any other boot sequence related function. |
| 95 | void initialize(CheckpointInterface* checkpoint_service); |
| 96 | // Migrates sessions from /data/apex/session to /metadata/session.i |
| 97 | // Must only be called during boot (i.e apexd.status is not "ready" or |
| 98 | // "activated"). |
| 99 | android::base::Result<void> migrateSessionsDirIfNeeded(); |
| 100 | // Apex activation logic. Scans staged apex sessions and activates apexes. |
| 101 | // Must only be called during boot (i.e apexd.status is not "ready" or |
| 102 | // "activated"). |
| 103 | void onStart(); |
| 104 | // Notifies system that apexes are activated by setting apexd.status property to |
| 105 | // "activated". |
| 106 | // Must only be called during boot (i.e. apexd.status is not "ready" or |
| 107 | // "activated"). |
Oli Lan | 54da92a | 2020-02-06 11:40:04 +0000 | [diff] [blame] | 108 | void onAllPackagesActivated(); |
Nikita Ioffe | dee4b6e | 2020-04-22 01:01:17 +0100 | [diff] [blame] | 109 | // Notifies system that apexes are ready by setting apexd.status property to |
| 110 | // "ready". |
| 111 | // Must only be called during boot (i.e. apexd.status is not "ready" or |
| 112 | // "activated"). |
Jiyong Park | 2c7c728 | 2018-11-01 20:02:25 +0900 | [diff] [blame] | 113 | void onAllPackagesReady(); |
Nikita Ioffe | d357051 | 2020-02-19 14:46:13 +0000 | [diff] [blame] | 114 | void bootCompletedCleanup(); |
Oli Lan | a18705f | 2020-01-18 14:35:46 +0000 | [diff] [blame] | 115 | int snapshotOrRestoreDeUserData(); |
Jiyong Park | 2c7c728 | 2018-11-01 20:02:25 +0900 | [diff] [blame] | 116 | |
Nikita Ioffe | 0867c79 | 2019-11-06 21:43:13 +0000 | [diff] [blame] | 117 | int unmountAll(); |
| 118 | |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 119 | // Optimistically tries to remount as many APEX packages as possible. |
| 120 | // For more documentation see corresponding binder call in IApexService.aidl. |
| 121 | android::base::Result<void> remountPackages(); |
| 122 | |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 123 | } // namespace apex |
| 124 | } // namespace android |
| 125 | |
| 126 | #endif // ANDROID_APEXD_APEXD_H_ |