1 # Copyright (C) 2016 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 # use this file except in compliance with the License. You may obtain a copy of 5 # 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, WITHOUT 11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 # License for the specific language governing permissions and limitations under 13 # the License. 14 import base64 15 16 17 def get_bluetooth_metrics(ad, bluetooth_proto_module): 18 """ 19 Get metric proto from the Bluetooth stack 20 21 Parameter: 22 ad - Android device 23 bluetooth_proto_module - the Bluetooth protomodule returned by 24 compile_import_proto() 25 26 Return: 27 a protobuf object representing Bluetooth metric 28 29 """ 30 bluetooth_log = bluetooth_proto_module.BluetoothLog() 31 proto_native_str_64 = \ 32 ad.adb.shell("/system/bin/dumpsys bluetooth_manager --proto-bin") 33 proto_native_str = base64.b64decode(proto_native_str_64) 34 proto_java_str_64 = \ 35 ad.adb.shell("/system/bin/dumpsys bluetooth_manager --proto-java-bin") 36 proto_java_str = base64.b64decode(proto_java_str_64) 37 bluetooth_log.MergeFromString(proto_native_str) 38 bluetooth_log.MergeFromString(proto_java_str) 39 return bluetooth_log 40