• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
18 
19 #include <aidl/android/hardware/memtrack/BnMemtrack.h>
20 #include <aidl/android/hardware/memtrack/DeviceInfo.h>
21 #include <aidl/android/hardware/memtrack/IMemtrack.h>
22 #include <aidl/android/hardware/memtrack/MemtrackRecord.h>
23 #include <aidl/android/hardware/memtrack/MemtrackType.h>
24 #include <android/hardware/memtrack/1.0/IMemtrack.h>
25 
26 using ::android::sp;
27 
28 namespace V1_0_hidl = ::android::hardware::memtrack::V1_0;
29 namespace V1_aidl = ::aidl::android::hardware::memtrack;
30 
31 namespace aidl {
32 namespace android {
33 namespace hardware {
34 namespace memtrack {
35 
36 __attribute__((warn_unused_result)) bool translate(const V1_0_hidl::MemtrackRecord& in,
37                                                    V1_aidl::MemtrackRecord* out);
38 
39 class MemtrackProxy : public BnMemtrack {
40 public:
41     MemtrackProxy();
42     ndk::ScopedAStatus getMemory(int pid, MemtrackType type,
43                                  std::vector<MemtrackRecord>* _aidl_return) override;
44     ndk::ScopedAStatus getGpuDeviceInfo(std::vector<DeviceInfo>* _aidl_return) override;
45 
46 private:
47     static sp<V1_0_hidl::IMemtrack> MemtrackHidlInstance();
48     static std::shared_ptr<V1_aidl::IMemtrack> MemtrackAidlInstance();
49     static bool CheckUid(uid_t calling_uid);
50     static bool CheckPid(pid_t calling_pid, pid_t request_pid);
51 
52     sp<V1_0_hidl::IMemtrack> memtrack_hidl_instance_;
53     std::shared_ptr<V1_aidl::IMemtrack> memtrack_aidl_instance_;
54 };
55 
56 } // namespace memtrack
57 } // namespace hardware
58 } // namespace android
59 } // namespace aidl
60