1 // Copyright (C) 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #if __ANDROID__
18 
19 #include <ditto/binder.h>
20 #include <ditto/instruction.h>
21 
22 #include <storage/IMountService.h>
23 
24 #include <random>
25 
26 #include <cstdint>
27 
28 namespace dittosuite {
29 
30 class BinderRequest : public Instruction {
31  public:
32   explicit BinderRequest(const std::string& kName, const Params& params,
33                          const std::string& service_name);
34 
35  protected:
36   std::string service_name_;
37 
38   virtual void RunSingle() = 0;
39   virtual void SetUp() = 0;
40   virtual void TearDownSingle(bool last) = 0;
41 };
42 
43 class BinderRequestDitto : public BinderRequest {
44  public:
45   inline static const std::string kName = "binder_request_ditto";
46 
47   explicit BinderRequestDitto(const Params& params, const std::string& service_name);
48 
49  protected:
50   void RunSingle() override;
51 
52  private:
53   android::sp<IDittoBinder> service_;
54 
55   void SetUp() override;
56   void TearDownSingle(bool is_last) override;
57 };
58 
59 class BinderRequestMountService : public BinderRequest {
60  public:
61   inline static const std::string kName = "binder_request_ms";
62 
63   explicit BinderRequestMountService(const Params& params);
64 
65  protected:
66   void RunSingle() override;
67 
68  private:
69   android::sp<android::IMountService> service_;
70 
71   void SetUp() override;
72   void TearDownSingle(bool last) override;
73 };
74 
75 class GenericBinderRequest : public BinderRequest {
76  public:
77   inline static const std::string kName = "binder_request_generic";
78   explicit GenericBinderRequest(const Params& params,
79       std::string service_name,  int32_t code,
80       const google::protobuf::RepeatedPtrField<dittosuiteproto::BinderRequest_GenericService_ParcelInput> parcel_input);
81 
82  protected:
83   void RunSingle() override;
84   const google::protobuf::RepeatedPtrField<dittosuiteproto::BinderRequest_GenericService_ParcelInput> parcel_input_;
85   std::string service_name_;
86   int32_t code_;
87   android::sp<android::IBinder> service_;
88 
89  private:
90   void SetUp() override;
91   void TearDownSingle(bool is_last) override;
92 };
93 }  // namespace dittosuite
94 
95 #endif
96