blob: 36f72beb6f40e977f67ad74cab943eb1ff76d0c3 [file] [log] [blame]
Andreas Gampe9d016d52018-10-19 18:56:50 -07001/*
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 Gampeb99abdd2018-10-19 19:59:17 -070020#include <string>
Andreas Gampe0fa59af2018-11-16 11:12:11 -080021#include <vector>
Andreas Gampeb99abdd2018-10-19 19:59:17 -070022
23#include <android-base/macros.h>
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010024#include <android-base/result.h>
Andreas Gampeb99abdd2018-10-19 19:59:17 -070025
Jiyong Park5e810232019-04-01 15:24:26 +090026#include "apex_constants.h"
Narayan Kamath5ea57782019-01-03 18:17:05 +000027#include "apex_file.h"
Andreas Gampeb99abdd2018-10-19 19:59:17 -070028
Andreas Gampe9d016d52018-10-19 18:56:50 -070029namespace android {
30namespace apex {
31
Andreas Gampe6aaa2fe2019-03-29 14:13:59 -070032class CheckpointInterface;
33
Mohammad Samiul Islamca852e32019-11-20 13:37:14 +000034android::base::Result<void> resumeRevertIfNeeded();
Andreas Gampe9d016d52018-10-19 18:56:50 -070035
Nikita Ioffe69349442020-02-06 13:17:22 +000036// Keep it for now to make otapreopt_chroot keep happy.
37// TODO(b/137086602): remove this function.
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010038android::base::Result<void> scanPackagesDirAndActivate(
39 const char* apex_package_dir);
Dario Freni7f0da582019-01-06 17:54:13 +000040void scanStagedSessionsDirAndStage();
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010041android::base::Result<void> preinstallPackages(
42 const std::vector<std::string>& paths) WARN_UNUSED;
43android::base::Result<void> postinstallPackages(
44 const std::vector<std::string>& paths) WARN_UNUSED;
Andreas Gampe0e435302018-12-21 15:40:19 -080045
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010046android::base::Result<void> stagePackages(
47 const std::vector<std::string>& tmpPaths) WARN_UNUSED;
48android::base::Result<void> unstagePackages(
49 const std::vector<std::string>& paths) WARN_UNUSED;
Andreas Gamped6c3df82018-11-08 15:34:06 -080050
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010051android::base::Result<std::vector<ApexFile>> submitStagedSession(
Oli Lan123d9d02019-12-02 14:08:24 +000052 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 Islambd6ab0f2019-06-20 15:55:27 +010055android::base::Result<void> markStagedSessionReady(const int session_id)
56 WARN_UNUSED;
57android::base::Result<void> markStagedSessionSuccessful(const int session_id)
58 WARN_UNUSED;
Gavin Corkery92cd7b82020-01-13 12:35:38 +000059android::base::Result<void> revertActiveSessions(
60 const std::string& crashing_native_process);
61android::base::Result<void> revertActiveSessionsAndReboot(
62 const std::string& crashing_native_process);
Dario Freni56231b42019-01-04 11:58:17 +000063
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010064android::base::Result<void> activatePackage(const std::string& full_path)
65 WARN_UNUSED;
66android::base::Result<void> deactivatePackage(const std::string& full_path)
67 WARN_UNUSED;
Andreas Gampeb99abdd2018-10-19 19:59:17 -070068
Narayan Kamath5ea57782019-01-03 18:17:05 +000069std::vector<ApexFile> getActivePackages();
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010070android::base::Result<ApexFile> getActivePackage(
71 const std::string& package_name);
Andreas Gampe0fa59af2018-11-16 11:12:11 -080072
Gavin Corkeryd6ef0302019-03-21 11:52:06 +000073std::vector<ApexFile> getFactoryPackages();
74
Mohammad Samiul Islam4654f772019-11-20 15:19:07 +000075android::base::Result<void> abortStagedSession(const int session_id);
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010076android::base::Result<void> abortActiveSession();
Nikita Ioffe463d4e82019-02-10 18:46:20 +000077
Oli Lan2d59dfa2020-01-14 20:25:09 +000078android::base::Result<ino_t> snapshotCeData(const int user_id,
79 const int rollback_id,
80 const std::string& apex_name);
81android::base::Result<void> restoreCeData(const int user_id,
82 const int rollback_id,
83 const std::string& apex_name);
Oli Lan042fbcf2020-01-17 11:14:16 +000084android::base::Result<void> destroyDeSnapshots(const int rollback_id);
Oli Lan2993ccc2020-03-06 18:06:40 +000085android::base::Result<void> destroyCeSnapshotsNotSpecified(
86 int user_id, const std::vector<int>& retain_rollback_ids);
Oli Lan2d59dfa2020-01-14 20:25:09 +000087
Jiyong Park715e23d2019-02-22 22:14:37 +090088int onBootstrap();
Nikita Ioffedee4b6e2020-04-22 01:01:17 +010089// Small helper function to tell if device is currently booting.
90bool isBooting();
Oli Lan30e598c2020-05-15 17:00:26 +010091// Sets the values of gVoldService and gInFsCheckpointMode.
92void initializeVold(CheckpointInterface* checkpoint_service);
Nikita Ioffedee4b6e2020-04-22 01:01:17 +010093// Initializes in-memory state (e.g. pre-installed data, activated apexes).
94// Must be called first before calling any other boot sequence related function.
95void 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").
99android::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").
103void 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 Lan54da92a2020-02-06 11:40:04 +0000108void onAllPackagesActivated();
Nikita Ioffedee4b6e2020-04-22 01:01:17 +0100109// 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 Park2c7c7282018-11-01 20:02:25 +0900113void onAllPackagesReady();
Nikita Ioffed3570512020-02-19 14:46:13 +0000114void bootCompletedCleanup();
Oli Lana18705f2020-01-18 14:35:46 +0000115int snapshotOrRestoreDeUserData();
Jiyong Park2c7c7282018-11-01 20:02:25 +0900116
Nikita Ioffe0867c792019-11-06 21:43:13 +0000117int unmountAll();
118
Nikita Ioffe78d2bce2020-05-02 01:28:30 +0100119// Optimistically tries to remount as many APEX packages as possible.
120// For more documentation see corresponding binder call in IApexService.aidl.
121android::base::Result<void> remountPackages();
122
Andreas Gampe9d016d52018-10-19 18:56:50 -0700123} // namespace apex
124} // namespace android
125
126#endif // ANDROID_APEXD_APEXD_H_