Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 479a612e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Metrics: Move bluetooth.proto to system/bt/proto"

parents ecf92c77 a7a6d4aa
Loading
Loading
Loading
Loading
+17 −20
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
        $(call all-java-files-under, lib/mapapi)
# MAP API module

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, lib/mapapi)
LOCAL_MODULE := bluetooth.mapsapi
include $(BUILD_STATIC_JAVA_LIBRARY)

include $(CLEAR_VARS)
# Bluetooth APK

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
        $(call all-java-files-under, src) \
        $(call all-proto-files-under, src)

LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Bluetooth
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_USE_AAPT2 := true

LOCAL_JNI_SHARED_LIBRARIES := libbluetooth_jni
LOCAL_JAVA_LIBRARIES := javax.obex telephony-common libprotobuf-java-micro services.net
LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard bluetooth.mapsapi sap-api-java-static services.net
LOCAL_STATIC_ANDROID_LIBRARIES := \
        android-support-v4
LOCAL_PROTOC_OPTIMIZE_TYPE := micro

LOCAL_JAVA_LIBRARIES := javax.obex telephony-common services.net
LOCAL_STATIC_JAVA_LIBRARIES := \
        com.android.vcard \
        bluetooth.mapsapi \
        sap-api-java-static \
        services.net \
        libprotobuf-java-lite \
        bluetooth-protos-lite

LOCAL_STATIC_ANDROID_LIBRARIES := android-support-v4
LOCAL_REQUIRED_MODULES := libbluetooth

LOCAL_PROGUARD_ENABLED := disabled

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))
+11 −9
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
import com.android.bluetooth.gatt.GattService;
@@ -69,7 +70,7 @@ import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IBatteryStats;

import com.google.protobuf.micro.InvalidProtocolBufferMicroException;
import com.google.protobuf.InvalidProtocolBufferException;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
@@ -2404,22 +2405,23 @@ public class AdapterService extends Service {
    }

    private void dumpMetrics(FileDescriptor fd) {
        BluetoothProto.BluetoothLog metrics = new BluetoothProto.BluetoothLog();
        metrics.setNumBondedDevices(getBondedDevices().length);
        for (ProfileService profile : mRegisteredProfiles) {
            profile.dumpProto(metrics);
        }
        BluetoothMetricsProto.BluetoothLog.Builder metricsBuilder =
                BluetoothMetricsProto.BluetoothLog.newBuilder();
        byte[] nativeMetricsBytes = dumpMetricsNative();
        debugLog("dumpMetrics: native metrics size is " + nativeMetricsBytes.length);
        if (nativeMetricsBytes.length > 0) {
            try {
                metrics.mergeFrom(nativeMetricsBytes);
            } catch (InvalidProtocolBufferMicroException ex) {
                metricsBuilder.mergeFrom(nativeMetricsBytes);
            } catch (InvalidProtocolBufferException ex) {
                Log.w(TAG, "dumpMetrics: problem parsing metrics protobuf, " + ex.getMessage());
                return;
            }
        }
        byte[] metricsBytes = Base64.encode(metrics.toByteArray(), Base64.DEFAULT);
        metricsBuilder.setNumBondedDevices(getBondedDevices().length);
        for (ProfileService profile : mRegisteredProfiles) {
            profile.dumpProto(metricsBuilder);
        }
        byte[] metricsBytes = Base64.encode(metricsBuilder.build().toByteArray(), Base64.DEFAULT);
        debugLog("dumpMetrics: combined metrics size is " + metricsBytes.length);
        try (FileOutputStream protoOut = new FileOutputStream(fd)) {
            protoOut.write(metricsBytes);
+3 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;

/**
@@ -187,9 +188,9 @@ public abstract class ProfileService extends Service {
    /**
     * Support dumping scan events from GattService
     *
     * @param proto
     * @param builder metrics proto builder
     */
    public void dumpProto(BluetoothProto.BluetoothLog proto) {
    public void dumpProto(BluetoothMetricsProto.BluetoothLog.Builder builder) {
        // Do nothing
    }

+0 −220
Original line number Diff line number Diff line
// Copyright 2014 Google Inc. All Rights Reserved.
// Author: pkanwar@google.com (Pankaj Kanwar)
// Protos for uploading bluetooth metrics.

syntax = "proto2";

package com.android.bluetooth.btservice;

option java_package = "com.android.bluetooth.btservice";
option java_outer_classname = "BluetoothProto";
//option (datapol.file_vetting_status) = "latest";

// import "storage/datapol/annotations/proto/semantic_annotations.proto";

message BluetoothLog {

  // Session information that gets logged for every BT connection.
  repeated BluetoothSession session = 1;

  // Session information that gets logged for every Pair event.
  repeated PairEvent pair_event = 2;

  // Information for Wake locks.
  repeated WakeEvent wake_event = 3;

  // Scan event information.
  repeated ScanEvent scan_event = 4;

  // Number of bonded devices.
  optional int32 num_bonded_devices = 5;

  // Number of BluetoothSession including discarded ones beyond capacity
  optional int64 num_bluetooth_session = 6;

  // Number of PairEvent including discarded ones beyond capacity
  optional int64 num_pair_event = 7;

  // Number of WakeEvent including discarded ones beyond capacity
  optional int64 num_wake_event = 8;

  // Number of ScanEvent including discarded ones beyond capacity
  optional int64 num_scan_event = 9;
}

// The information about the device.
message DeviceInfo {

  // Device type.
  enum DeviceType {

     // Type is unknown.
     DEVICE_TYPE_UNKNOWN = 0;

     DEVICE_TYPE_BREDR = 1;

     DEVICE_TYPE_LE = 2;

     DEVICE_TYPE_DUMO = 3;
  }

  // Device class
  // https://cs.corp.google.com/#android/system/bt/stack/include/btm_api.h&q=major_computer.
  optional int32 device_class = 1;

  // Device type.
  optional DeviceType device_type = 2;
}

// Information that gets logged for every Bluetooth connection.
message BluetoothSession {

  // Type of technology used in the connection.
  enum ConnectionTechnologyType {

     CONNECTION_TECHNOLOGY_TYPE_UNKNOWN = 0;

     CONNECTION_TECHNOLOGY_TYPE_LE = 1;

     CONNECTION_TECHNOLOGY_TYPE_BREDR = 2;
  }

  // Duration of the session.
  optional int64 session_duration_sec = 2;

  // Technology type.
  optional ConnectionTechnologyType connection_technology_type = 3;

  // Reason for disconnecting.
  optional string disconnect_reason = 4;

  // The information about the device which it is connected to.
  optional DeviceInfo device_connected_to = 5;

  // The information about the RFComm session.
  optional RFCommSession rfcomm_session = 6;

  // The information about the A2DP audio session.
  optional A2DPSession a2dp_session = 7;
}

message RFCommSession {

  // bytes transmitted.
  optional int32 rx_bytes = 1;

  // bytes transmitted.
  optional int32 tx_bytes = 2;
}

// Session information that gets logged for A2DP session.
message A2DPSession {

  // Media timer in milliseconds.
  optional int32 media_timer_min_millis = 1;

  // Media timer in milliseconds.
  optional int32 media_timer_max_millis = 2;

  // Media timer in milliseconds.
  optional int32 media_timer_avg_millis = 3;

  // Buffer overruns count.
  optional int32 buffer_overruns_max_count = 4;

  // Buffer overruns total.
  optional int32 buffer_overruns_total = 5;

  // Buffer underruns average.
  optional float buffer_underruns_average = 6;

  // Buffer underruns count.
  optional int32 buffer_underruns_count = 7;

  // Total audio time in this A2DP session
  optional int64 audio_duration_millis = 8;
}

message PairEvent {

  // The reason for disconnecting
  // https://cs.corp.google.com/#android/system/bt/stack/include/hcidefs.h&q=failed_establish.
  optional int32 disconnect_reason = 1;

  // Pair event time
  optional int64 event_time_millis = 2; // [(datapol.semantic_type) = ST_TIMESTAMP];

  // The information about the device which it is paired to.
  optional DeviceInfo device_paired_with = 3;
}

message WakeEvent {

  // Information about the wake event type.
  enum WakeEventType {

     // Type is unknown.
     UNKNOWN = 0;

     // WakeLock was acquired.
     ACQUIRED = 1;

     // WakeLock was released.
     RELEASED = 2;
  }

  // Information about the wake event type.
  optional WakeEventType wake_event_type = 1;

  // Initiator of the scan. Only the first three names will be stored.
  // e.g. com.google.gms.
  optional string requestor = 2;

  // Name of the wakelock (e.g. bluedroid_timer).
  optional string name = 3;

  // Time of the event.
  optional int64 event_time_millis = 4; // [(datapol.semantic_type) = ST_TIMESTAMP];
}

message ScanEvent {

  // Scan type.
  enum ScanTechnologyType {

     // Scan Type is unknown.
     SCAN_TYPE_UNKNOWN = 0;

     SCAN_TECH_TYPE_LE = 1;

     SCAN_TECH_TYPE_BREDR = 2;

     SCAN_TECH_TYPE_BOTH = 3;
  }

  // Scan event type.
  enum ScanEventType {

     // Scan started.
     SCAN_EVENT_START = 0;

     // Scan stopped.
     SCAN_EVENT_STOP = 1;
  }

  // Scan event type.
  optional ScanEventType scan_event_type = 1;

  // Initiator of the scan. Only the first three names will be stored.
  // e.g. com.google.gms.
  optional string initiator = 2;

  // Technology used for scanning.
  optional ScanTechnologyType scan_technology_type = 3;

  // Number of results returned.
  optional int32 number_results = 4;

  // Time of the event.
  optional int64 event_time_millis = 5; // [(datapol.semantic_type) = ST_TIMESTAMP];
}
+15 −11
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.WorkSource;

import com.android.bluetooth.btservice.BluetoothProto;
import com.android.bluetooth.BluetoothMetricsProto;
import com.android.internal.app.IBatteryStats;

import java.text.DateFormat;
@@ -158,11 +158,12 @@ import java.util.List;
                    (settings.getCallbackType() & ScanSettings.CALLBACK_TYPE_FIRST_MATCH) != 0;
        }

        BluetoothProto.ScanEvent scanEvent = new BluetoothProto.ScanEvent();
        scanEvent.setScanEventType(BluetoothProto.ScanEvent.SCAN_EVENT_START);
        scanEvent.setScanTechnologyType(BluetoothProto.ScanEvent.SCAN_TECH_TYPE_LE);
        scanEvent.setEventTimeMillis(System.currentTimeMillis());
        scanEvent.setInitiator(truncateAppName(appName));
        BluetoothMetricsProto.ScanEvent scanEvent = BluetoothMetricsProto.ScanEvent.newBuilder()
                .setScanEventType(BluetoothMetricsProto.ScanEvent.ScanEventType.SCAN_EVENT_START)
                .setScanTechnologyType(
                        BluetoothMetricsProto.ScanEvent.ScanTechnologyType.SCAN_TECH_TYPE_LE)
                .setEventTimeMillis(System.currentTimeMillis())
                .setInitiator(truncateAppName(appName)).build();
        mGattService.addScanEvent(scanEvent);

        if (!isScanning()) {
@@ -198,11 +199,14 @@ import java.util.List;
        }
        mLastScans.add(scan);

        BluetoothProto.ScanEvent scanEvent = new BluetoothProto.ScanEvent();
        scanEvent.setScanEventType(BluetoothProto.ScanEvent.SCAN_EVENT_STOP);
        scanEvent.setScanTechnologyType(BluetoothProto.ScanEvent.SCAN_TECH_TYPE_LE);
        scanEvent.setEventTimeMillis(System.currentTimeMillis());
        scanEvent.setInitiator(truncateAppName(appName));
        BluetoothMetricsProto.ScanEvent scanEvent = BluetoothMetricsProto.ScanEvent.newBuilder()
                .setScanEventType(BluetoothMetricsProto.ScanEvent.ScanEventType.SCAN_EVENT_STOP)
                .setScanTechnologyType(
                        BluetoothMetricsProto.ScanEvent.ScanTechnologyType.SCAN_TECH_TYPE_LE)
                .setEventTimeMillis(System.currentTimeMillis())
                .setInitiator(truncateAppName(appName))
                .setNumberResults(scan.results)
                .build();
        mGattService.addScanEvent(scanEvent);

        if (!isScanning()) {
Loading