Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 1 | /* |
| 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 Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 20 | #include <android-base/result.h> |
| 21 | |
Andreas Gampe | f35e179 | 2019-04-01 15:58:03 -0700 | [diff] [blame] | 22 | #include "apex_constants.h" |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 23 | |
| 24 | #include "session_state.pb.h" |
| 25 | |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 26 | #include <optional> |
| 27 | |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace apex { |
| 30 | |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 31 | static const std::string kApexSessionsDir = "/metadata/apex/sessions"; |
Martijn Coenen | c11b68b | 2019-01-15 11:28:11 +0100 | [diff] [blame] | 32 | |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 33 | class ApexSession { |
| 34 | public: |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 35 | static android::base::Result<ApexSession> CreateSession(int session_id); |
| 36 | static android::base::Result<ApexSession> GetSession(int session_id); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 37 | static std::vector<ApexSession> GetSessions(); |
| 38 | static std::vector<ApexSession> GetSessionsInState( |
| 39 | ::apex::proto::SessionState::State state); |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 40 | static android::base::Result<std::optional<ApexSession>> GetActiveSession(); |
Mohammad Samiul Islam | 2401ae1 | 2019-11-20 17:12:31 +0000 | [diff] [blame] | 41 | static std::vector<ApexSession> GetActiveSessions(); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 42 | ApexSession() = delete; |
| 43 | |
Dario Freni | 6dd4dd6 | 2019-01-18 12:45:44 +0000 | [diff] [blame] | 44 | const google::protobuf::RepeatedField<int> GetChildSessionIds() const; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 45 | ::apex::proto::SessionState::State GetState() const; |
| 46 | int GetId() const; |
Gavin Corkery | 778cace | 2019-09-26 12:53:45 +0100 | [diff] [blame] | 47 | std::string GetBuildFingerprint() const; |
Gavin Corkery | 92cd7b8 | 2020-01-13 12:35:38 +0000 | [diff] [blame] | 48 | std::string GetCrashingNativeProcess() const; |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 49 | bool IsFinalized() const; |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 50 | bool HasRollbackEnabled() const; |
| 51 | bool IsRollback() const; |
| 52 | int GetRollbackId() const; |
Oli Lan | a18705f | 2020-01-18 14:35:46 +0000 | [diff] [blame] | 53 | const google::protobuf::RepeatedPtrField<std::string> GetApexNames() const; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 54 | |
Dario Freni | 6dd4dd6 | 2019-01-18 12:45:44 +0000 | [diff] [blame] | 55 | void SetChildSessionIds(const std::vector<int>& child_session_ids); |
Gavin Corkery | 778cace | 2019-09-26 12:53:45 +0100 | [diff] [blame] | 56 | void SetBuildFingerprint(const std::string& fingerprint); |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 57 | void SetHasRollbackEnabled(const bool enabled); |
| 58 | void SetIsRollback(const bool is_rollback); |
| 59 | void SetRollbackId(const int rollback_id); |
Gavin Corkery | 92cd7b8 | 2020-01-13 12:35:38 +0000 | [diff] [blame] | 60 | void SetCrashingNativeProcess(const std::string& crashing_process); |
Oli Lan | a18705f | 2020-01-18 14:35:46 +0000 | [diff] [blame] | 61 | void AddApexName(const std::string& apex_name); |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 62 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 63 | android::base::Result<void> UpdateStateAndCommit( |
| 64 | const ::apex::proto::SessionState::State& state); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 65 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 66 | android::base::Result<void> DeleteSession() const; |
Nikita Ioffe | 53c3dcd | 2019-02-08 17:39:00 +0000 | [diff] [blame] | 67 | |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 68 | private: |
Colin Cross | 7868c94 | 2019-08-13 15:31:00 -0700 | [diff] [blame] | 69 | ApexSession(::apex::proto::SessionState state); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 70 | ::apex::proto::SessionState state_; |
Martijn Coenen | d32d1cb | 2019-02-13 12:43:57 +0100 | [diff] [blame] | 71 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 72 | static android::base::Result<ApexSession> GetSessionFromFile( |
| 73 | const std::string& path); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 74 | }; |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 75 | |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 76 | std::ostream& operator<<(std::ostream& out, const ApexSession& session); |
| 77 | |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 78 | } // namespace apex |
| 79 | } // namespace android |
| 80 | |
| 81 | #endif // ANDROID_APEXD_APEXD_SESSION_H |