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 
20 #include <string>
21 #include <vector>
22 
23 #include <android-base/macros.h>
24 #include <android-base/result.h>
25 
26 #include "apex_constants.h"
27 #include "apex_file.h"
28 
29 namespace android {
30 namespace apex {
31 
32 class CheckpointInterface;
33 
34 android::base::Result<void> resumeRevertIfNeeded();
35 
36 // Keep it for now to make otapreopt_chroot keep happy.
37 // TODO(b/137086602): remove this function.
38 android::base::Result<void> scanPackagesDirAndActivate(
39     const char* apex_package_dir);
40 void scanStagedSessionsDirAndStage();
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;
45 
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;
50 
51 android::base::Result<std::vector<ApexFile>> submitStagedSession(
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;
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;
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);
63 
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;
68 
69 std::vector<ApexFile> getActivePackages();
70 android::base::Result<ApexFile> getActivePackage(
71     const std::string& package_name);
72 
73 std::vector<ApexFile> getFactoryPackages();
74 
75 android::base::Result<void> abortStagedSession(const int session_id);
76 android::base::Result<void> abortActiveSession();
77 
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);
84 android::base::Result<void> destroyDeSnapshots(const int rollback_id);
85 android::base::Result<void> destroyCeSnapshotsNotSpecified(
86     int user_id, const std::vector<int>& retain_rollback_ids);
87 
88 int onBootstrap();
89 // Small helper function to tell if device is currently booting.
90 bool isBooting();
91 // Sets the values of gVoldService and gInFsCheckpointMode.
92 void initializeVold(CheckpointInterface* checkpoint_service);
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").
108 void onAllPackagesActivated();
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").
113 void onAllPackagesReady();
114 void bootCompletedCleanup();
115 int snapshotOrRestoreDeUserData();
116 
117 int unmountAll();
118 
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 
123 }  // namespace apex
124 }  // namespace android
125 
126 #endif  // ANDROID_APEXD_APEXD_H_
127