1 /* 2 ** 3 ** Copyright 2019, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef GATEKEEPERD_INCLUDE_GATEKEEPER_GATEKEEPERRESPONSE_H_ 19 #define GATEKEEPERD_INCLUDE_GATEKEEPER_GATEKEEPERRESPONSE_H_ 20 21 #include <binder/Parcelable.h> 22 23 namespace android { 24 namespace service { 25 namespace gatekeeper { 26 27 enum class ResponseCode : int32_t { 28 ERROR = -1, 29 OK = 0, 30 RETRY = 1, 31 }; 32 33 class GateKeeperResponse : public ::android::Parcelable { 34 GateKeeperResponse(ResponseCode response_code, int32_t timeout = 0, 35 std::vector<uint8_t> payload = {}, bool should_reenroll = false) response_code_(response_code)36 : response_code_(response_code), 37 timeout_(timeout), 38 payload_(std::move(payload)), 39 should_reenroll_(should_reenroll) {} 40 41 public: 42 GateKeeperResponse() = default; 43 GateKeeperResponse(GateKeeperResponse&&) = default; 44 GateKeeperResponse(const GateKeeperResponse&) = default; 45 GateKeeperResponse& operator=(GateKeeperResponse&&) = default; 46 error()47 static GateKeeperResponse error() { return GateKeeperResponse(ResponseCode::ERROR); } retry(int32_t timeout)48 static GateKeeperResponse retry(int32_t timeout) { 49 return GateKeeperResponse(ResponseCode::RETRY, timeout); 50 } 51 static GateKeeperResponse ok(std::vector<uint8_t> payload, bool reenroll = false) { 52 return GateKeeperResponse(ResponseCode::OK, 0, std::move(payload), reenroll); 53 } 54 55 status_t readFromParcel(const Parcel* in) override; 56 status_t writeToParcel(Parcel* out) const override; 57 payload()58 const std::vector<uint8_t>& payload() const { return payload_; } 59 payload(std::vector<uint8_t> payload)60 void payload(std::vector<uint8_t> payload) { payload_ = payload; } 61 response_code()62 ResponseCode response_code() const { return response_code_; } 63 response_code(ResponseCode response_code)64 void response_code(ResponseCode response_code) { response_code_ = response_code; } 65 should_reenroll()66 bool should_reenroll() const { return should_reenroll_; } 67 should_reenroll(bool should_reenroll)68 void should_reenroll(bool should_reenroll) { should_reenroll_ = should_reenroll; } 69 timeout()70 int32_t timeout() const { return timeout_; } 71 timeout(int32_t timeout)72 void timeout(int32_t timeout) { timeout_ = timeout; } 73 74 private: 75 ResponseCode response_code_; 76 int32_t timeout_; 77 std::vector<uint8_t> payload_; 78 bool should_reenroll_; 79 }; 80 81 } // namespace gatekeeper 82 } // namespace service 83 } // namespace android 84 85 #endif // GATEKEEPERD_INCLUDE_GATEKEEPER_GATEKEEPERRESPONSE_H_ 86