Add logging to Bluetooth settings.
- Add logging when users selects the listed devices to connect or disconnect, and when connection error is shown - Update the event for the top level bluetooth master switch toggle to have its own event. Change-Id: I58f21256fdd07fad9d733ff987ff38df1148f4f8 Fix: 35065258 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -34,7 +34,10 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -205,11 +208,20 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
void onClicked() {
|
||||
int bondState = mCachedDevice.getBondState();
|
||||
|
||||
final MetricsFeatureProvider metricsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
|
||||
|
||||
if (mCachedDevice.isConnected()) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
askDisconnect();
|
||||
} else if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
mCachedDevice.connect(true);
|
||||
} else if (bondState == BluetoothDevice.BOND_NONE) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
pair();
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ import android.provider.Settings;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.search.Index;
|
||||
@@ -52,6 +51,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
|
||||
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
|
||||
private static final int EVENT_UPDATE_INDEX = 0;
|
||||
private final int mMetricsEvent;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
@@ -77,13 +77,15 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
};
|
||||
|
||||
public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
|
||||
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager) {
|
||||
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
|
||||
int metricsEvent) {
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
mSwitchWidget = switchWidget;
|
||||
mSwitch = mSwitchWidget.getSwitch();
|
||||
mSwitchWidget.setListener(this);
|
||||
mValidListener = false;
|
||||
mMetricsEvent = metricsEvent;
|
||||
|
||||
if (manager == null) {
|
||||
// Bluetooth is not supported
|
||||
@@ -191,7 +193,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
return false;
|
||||
}
|
||||
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_BLUETOOTH_TOGGLE, isChecked);
|
||||
mMetricsFeatureProvider.action(mContext, mMetricsEvent, isChecked);
|
||||
|
||||
if (mLocalAdapter != null) {
|
||||
boolean status = mLocalAdapter.setBluetoothEnabled(isChecked);
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.bluetooth;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.lifecycle.events.OnPause;
|
||||
@@ -54,7 +55,8 @@ public class BluetoothMasterSwitchPreferenceController extends PreferenceControl
|
||||
mBtPreference = (MasterSwitchPreference) screen.findPreference(KEY_TOGGLE_BLUETOOTH);
|
||||
mBluetoothEnabler = new BluetoothEnabler(mContext,
|
||||
new MasterSwitchController(mBtPreference),
|
||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager);
|
||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
|
||||
MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -153,7 +153,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
|
||||
mBluetoothEnabler = new BluetoothEnabler(activity, new SwitchBarController(mSwitchBar),
|
||||
mMetricsFeatureProvider, Utils.getLocalBtManager(activity));
|
||||
mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
|
||||
MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
|
||||
mBluetoothEnabler.setupSwitchController();
|
||||
}
|
||||
|
||||
|
@@ -21,9 +21,12 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -84,14 +87,25 @@ public final class Utils {
|
||||
|
||||
// TODO: wire this up to show connection errors...
|
||||
static void showConnectingError(Context context, String name) {
|
||||
showError(context, name, R.string.bluetooth_connecting_error_message);
|
||||
showConnectingError(context, name, getLocalBtManager(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void showConnectingError(Context context, String name, LocalBluetoothManager manager) {
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider().visible(context,
|
||||
MetricsEvent.VIEW_UNKNOWN, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR);
|
||||
showError(context, name, R.string.bluetooth_connecting_error_message, manager);
|
||||
}
|
||||
|
||||
static void showError(Context context, String name, int messageResId) {
|
||||
showError(context, name, messageResId, getLocalBtManager(context));
|
||||
}
|
||||
|
||||
private static void showError(Context context, String name, int messageResId,
|
||||
LocalBluetoothManager manager) {
|
||||
String message = context.getString(messageResId, name);
|
||||
LocalBluetoothManager manager = getLocalBtManager(context);
|
||||
Context activity = manager.getForegroundActivity();
|
||||
if(manager.isForegroundActivity()) {
|
||||
if (manager.isForegroundActivity()) {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.bluetooth_error_title)
|
||||
.setMessage(message)
|
||||
|
Reference in New Issue
Block a user