Add preference click metric logs for some special cases

Bug: 137559984
Test: visual, robotest
Change-Id: If8624b49abcd0000487065160ce4a7ba861f234c
This commit is contained in:
Jason Chiu
2019-12-19 15:59:07 +08:00
parent d889dec474
commit 2d609759cd
18 changed files with 134 additions and 42 deletions

View File

@@ -35,6 +35,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
private static final String TAG = "AvailableMediaBluetoothDeviceUpdater";
private static final boolean DBG = false;
private static final String PREF_KEY = "available_media_bt";
private final AudioManager mAudioManager;
public AvailableMediaBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
@@ -97,9 +99,14 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
@Override
public boolean onPreferenceClick(Preference preference) {
mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
.getBluetoothDevice();
return device.setActive();
}
}
@Override
protected String getPreferenceKey() {
return PREF_KEY;
}
}

View File

@@ -28,12 +28,14 @@ import com.android.settings.R;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.GearPreference;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.Collection;
import java.util.HashMap;
@@ -52,6 +54,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
private static final String TAG = "BluetoothDeviceUpdater";
private static final boolean DBG = false;
protected final MetricsFeatureProvider mMetricsFeatureProvider;
protected final DevicePreferenceCallback mDevicePreferenceCallback;
protected final Map<BluetoothDevice, Preference> mPreferenceMap;
protected Context mPrefContext;
@@ -76,6 +79,8 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
mDevicePreferenceCallback = devicePreferenceCallback;
mPreferenceMap = new HashMap<>();
mLocalManager = localManager;
mMetricsFeatureProvider = FeatureFactory.getFactory(mFragment.getContext())
.getMetricsFeatureProvider();
}
/**
@@ -206,6 +211,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
*/
public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice);
/**
* Return a preference key for logging
*/
protected abstract String getPreferenceKey();
/**
* Update whether to show {@link CachedBluetoothDevice} in the list.
*/
@@ -228,6 +238,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
new BluetoothDevicePreference(mPrefContext, cachedDevice,
true /* showDeviceWithoutNames */,
BluetoothDevicePreference.SortType.TYPE_DEFAULT);
btPreference.setKey(getPreferenceKey());
btPreference.setOnGearClickListener(mDeviceProfilesListener);
if (this instanceof Preference.OnPreferenceClickListener) {
btPreference.setOnPreferenceClickListener(
@@ -264,6 +275,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
* {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment}
*/
protected void launchDeviceDetails(Preference preference) {
mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
final CachedBluetoothDevice device =
((BluetoothDevicePreference) preference).getBluetoothDevice();
if (device == null) {

View File

@@ -35,6 +35,8 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
private static final String TAG = "ConnBluetoothDeviceUpdater";
private static final boolean DBG = false;
private static final String PREF_KEY = "connected_bt";
private final AudioManager mAudioManager;
public ConnectedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
@@ -111,4 +113,9 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
});
}
}
@Override
protected String getPreferenceKey() {
return PREF_KEY;
}
}

View File

@@ -30,9 +30,12 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice;
*/
public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
implements Preference.OnPreferenceClickListener {
private static final String TAG = "SavedBluetoothDeviceUpdater";
private static final boolean DBG = false;
private static final String PREF_KEY = "saved_bt";
public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
DevicePreferenceCallback devicePreferenceCallback) {
super(context, fragment, devicePreferenceCallback);
@@ -51,9 +54,15 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
@Override
public boolean onPreferenceClick(Preference preference) {
mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
.getBluetoothDevice();
device.connect(true);
return true;
}
@Override
protected String getPreferenceKey() {
return PREF_KEY;
}
}