1 //
2 // Copyright (C) 2016 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 TPM_MANAGER_CLIENT_TPM_OWNERSHIP_BINDER_PROXY_H_
18 #define TPM_MANAGER_CLIENT_TPM_OWNERSHIP_BINDER_PROXY_H_
19 
20 #include <base/macros.h>
21 
22 #include "android/tpm_manager/ITpmOwnership.h"
23 #include "tpm_manager/common/export.h"
24 #include "tpm_manager/common/tpm_ownership_interface.h"
25 
26 namespace tpm_manager {
27 
28 // An implementation of TpmOwnershipInterface that forwards requests to
29 // tpm_managerd using Binder.
30 class TPM_MANAGER_EXPORT TpmOwnershipBinderProxy
31     : public TpmOwnershipInterface {
32  public:
33   TpmOwnershipBinderProxy() = default;
34   explicit TpmOwnershipBinderProxy(android::tpm_manager::ITpmOwnership* binder);
35   ~TpmOwnershipBinderProxy() override = default;
36 
37   // Initializes the client. Returns true on success.
38   bool Initialize();
39 
40   // TpmOwnershipInterface methods. All assume a message loop and binder watcher
41   // have already been configured elsewhere.
42   void GetTpmStatus(const GetTpmStatusRequest& request,
43                     const GetTpmStatusCallback& callback) override;
44   void TakeOwnership(const TakeOwnershipRequest& request,
45                      const TakeOwnershipCallback& callback) override;
46   void RemoveOwnerDependency(
47       const RemoveOwnerDependencyRequest& request,
48       const RemoveOwnerDependencyCallback& callback) override;
49 
50  private:
51   android::sp<android::tpm_manager::ITpmOwnership> default_binder_;
52   android::tpm_manager::ITpmOwnership* binder_ = nullptr;
53 
54   DISALLOW_COPY_AND_ASSIGN(TpmOwnershipBinderProxy);
55 };
56 
57 }  // namespace tpm_manager
58 
59 #endif  // TPM_MANAGER_CLIENT_TPM_OWNERSHIP_BINDER_PROXY_H_
60