blob: e0cea91cb69df6ffbaaa158c2273e5087ccdbd9e [file] [log] [blame]
Martijn Coenencabc92f2019-01-11 10:50:35 +01001/*
2 * Copyright (C) 2019 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_SESSION_H_
18#define ANDROID_APEXD_APEXD_SESSION_H_
19
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010020#include <android-base/result.h>
21
Andreas Gampef35e1792019-04-01 15:58:03 -070022#include "apex_constants.h"
Martijn Coenencabc92f2019-01-11 10:50:35 +010023
24#include "session_state.pb.h"
25
Nikita Ioffe463d4e82019-02-10 18:46:20 +000026#include <optional>
27
Martijn Coenencabc92f2019-01-11 10:50:35 +010028namespace android {
29namespace apex {
30
Gavin Corkery879fe9b2020-01-29 19:13:50 +000031static const std::string kApexSessionsDir = "/metadata/apex/sessions";
Martijn Coenenc11b68b2019-01-15 11:28:11 +010032
Martijn Coenen610909b2019-01-18 13:49:38 +010033class ApexSession {
34 public:
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010035 static android::base::Result<ApexSession> CreateSession(int session_id);
36 static android::base::Result<ApexSession> GetSession(int session_id);
Martijn Coenen610909b2019-01-18 13:49:38 +010037 static std::vector<ApexSession> GetSessions();
38 static std::vector<ApexSession> GetSessionsInState(
39 ::apex::proto::SessionState::State state);
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010040 static android::base::Result<std::optional<ApexSession>> GetActiveSession();
Mohammad Samiul Islam2401ae12019-11-20 17:12:31 +000041 static std::vector<ApexSession> GetActiveSessions();
Martijn Coenen610909b2019-01-18 13:49:38 +010042 ApexSession() = delete;
43
Dario Freni6dd4dd62019-01-18 12:45:44 +000044 const google::protobuf::RepeatedField<int> GetChildSessionIds() const;
Martijn Coenen610909b2019-01-18 13:49:38 +010045 ::apex::proto::SessionState::State GetState() const;
46 int GetId() const;
Gavin Corkery778cace2019-09-26 12:53:45 +010047 std::string GetBuildFingerprint() const;
Gavin Corkery92cd7b82020-01-13 12:35:38 +000048 std::string GetCrashingNativeProcess() const;
Nikita Ioffe463d4e82019-02-10 18:46:20 +000049 bool IsFinalized() const;
Oli Lan123d9d02019-12-02 14:08:24 +000050 bool HasRollbackEnabled() const;
51 bool IsRollback() const;
52 int GetRollbackId() const;
Oli Lana18705f2020-01-18 14:35:46 +000053 const google::protobuf::RepeatedPtrField<std::string> GetApexNames() const;
Martijn Coenen610909b2019-01-18 13:49:38 +010054
Dario Freni6dd4dd62019-01-18 12:45:44 +000055 void SetChildSessionIds(const std::vector<int>& child_session_ids);
Gavin Corkery778cace2019-09-26 12:53:45 +010056 void SetBuildFingerprint(const std::string& fingerprint);
Oli Lan123d9d02019-12-02 14:08:24 +000057 void SetHasRollbackEnabled(const bool enabled);
58 void SetIsRollback(const bool is_rollback);
59 void SetRollbackId(const int rollback_id);
Gavin Corkery92cd7b82020-01-13 12:35:38 +000060 void SetCrashingNativeProcess(const std::string& crashing_process);
Oli Lana18705f2020-01-18 14:35:46 +000061 void AddApexName(const std::string& apex_name);
Oli Lan123d9d02019-12-02 14:08:24 +000062
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010063 android::base::Result<void> UpdateStateAndCommit(
64 const ::apex::proto::SessionState::State& state);
Martijn Coenen610909b2019-01-18 13:49:38 +010065
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010066 android::base::Result<void> DeleteSession() const;
Nikita Ioffe53c3dcd2019-02-08 17:39:00 +000067
Martijn Coenen610909b2019-01-18 13:49:38 +010068 private:
Colin Cross7868c942019-08-13 15:31:00 -070069 ApexSession(::apex::proto::SessionState state);
Martijn Coenen610909b2019-01-18 13:49:38 +010070 ::apex::proto::SessionState state_;
Martijn Coenend32d1cb2019-02-13 12:43:57 +010071
Mohammad Samiul Islambd6ab0f2019-06-20 15:55:27 +010072 static android::base::Result<ApexSession> GetSessionFromFile(
73 const std::string& path);
Martijn Coenen610909b2019-01-18 13:49:38 +010074};
Martijn Coenencabc92f2019-01-11 10:50:35 +010075
Nikita Ioffea0c0ccb2019-02-12 22:00:41 +000076std::ostream& operator<<(std::ostream& out, const ApexSession& session);
77
Martijn Coenencabc92f2019-01-11 10:50:35 +010078} // namespace apex
79} // namespace android
80
81#endif // ANDROID_APEXD_APEXD_SESSION_H