blob: 7b6b703f9f11407dc88508891a9d1094fd4f417c [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
Andreas Gampef35e1792019-04-01 15:58:03 -070020#include "apex_constants.h"
Martijn Coenencabc92f2019-01-11 10:50:35 +010021#include "status_or.h"
22
23#include "session_state.pb.h"
24
Nikita Ioffe463d4e82019-02-10 18:46:20 +000025#include <optional>
26
Martijn Coenencabc92f2019-01-11 10:50:35 +010027namespace android {
28namespace apex {
29
Martijn Coenenc11b68b2019-01-15 11:28:11 +010030static const std::string kApexSessionsDir =
Nikita Ioffea8453da2019-01-30 21:29:13 +000031 std::string(kApexDataDir) + "/sessions";
Martijn Coenenc11b68b2019-01-15 11:28:11 +010032
Martijn Coenen610909b2019-01-18 13:49:38 +010033class ApexSession {
34 public:
35 static StatusOr<ApexSession> CreateSession(int session_id);
36 static StatusOr<ApexSession> GetSession(int session_id);
37 static std::vector<ApexSession> GetSessions();
38 static std::vector<ApexSession> GetSessionsInState(
39 ::apex::proto::SessionState::State state);
Nikita Ioffe463d4e82019-02-10 18:46:20 +000040 static StatusOr<std::optional<ApexSession>> GetActiveSession();
Martijn Coenen610909b2019-01-18 13:49:38 +010041 ApexSession() = delete;
42
Dario Freni6dd4dd62019-01-18 12:45:44 +000043 const google::protobuf::RepeatedField<int> GetChildSessionIds() const;
Martijn Coenen610909b2019-01-18 13:49:38 +010044 ::apex::proto::SessionState::State GetState() const;
45 int GetId() const;
Gavin Corkerya41373a2019-09-26 12:53:45 +010046 std::string GetBuildFingerprint() const;
Nikita Ioffe463d4e82019-02-10 18:46:20 +000047 bool IsFinalized() const;
Martijn Coenen610909b2019-01-18 13:49:38 +010048
Dario Freni6dd4dd62019-01-18 12:45:44 +000049 void SetChildSessionIds(const std::vector<int>& child_session_ids);
Gavin Corkerya41373a2019-09-26 12:53:45 +010050 void SetBuildFingerprint(const std::string& fingerprint);
Nikita Ioffea0c0ccb2019-02-12 22:00:41 +000051 Status UpdateStateAndCommit(const ::apex::proto::SessionState::State& state);
Martijn Coenen610909b2019-01-18 13:49:38 +010052
Nikita Ioffe463d4e82019-02-10 18:46:20 +000053 Status DeleteSession() const;
Nikita Ioffe53c3dcd2019-02-08 17:39:00 +000054
Martijn Coenen610909b2019-01-18 13:49:38 +010055 private:
Martijn Coenend32d1cb2019-02-13 12:43:57 +010056 ApexSession(const ::apex::proto::SessionState& state);
Martijn Coenen610909b2019-01-18 13:49:38 +010057 ::apex::proto::SessionState state_;
Martijn Coenend32d1cb2019-02-13 12:43:57 +010058
59 static StatusOr<ApexSession> GetSessionFromFile(const std::string& path);
Martijn Coenen610909b2019-01-18 13:49:38 +010060};
Martijn Coenencabc92f2019-01-11 10:50:35 +010061
Nikita Ioffea0c0ccb2019-02-12 22:00:41 +000062std::ostream& operator<<(std::ostream& out, const ApexSession& session);
63
Martijn Coenencabc92f2019-01-11 10:50:35 +010064} // namespace apex
65} // namespace android
66
67#endif // ANDROID_APEXD_APEXD_SESSION_H