[Audiosharing] Add logging 1.
Test: atest -c com.android.settings.connecteddevice.audiosharing.audiostreams Bug: 308368124 Change-Id: I2513824826b9d7dd6240728179ea004f33b4fbe3
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.isBroadcasting;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.content.Context;
|
||||
@@ -32,11 +33,13 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -116,6 +119,8 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll
|
||||
@Nullable private AudioSharingNamePreference mPreference;
|
||||
private final Executor mExecutor;
|
||||
private final AudioSharingNameTextValidator mAudioSharingNameTextValidator;
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private AtomicBoolean mCallbacksRegistered = new AtomicBoolean(false);
|
||||
|
||||
public AudioSharingNamePreferenceController(Context context, String preferenceKey) {
|
||||
@@ -126,6 +131,7 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll
|
||||
(mProfileManager != null) ? mProfileManager.getLeAudioBroadcastProfile() : null;
|
||||
mAudioSharingNameTextValidator = new AudioSharingNameTextValidator();
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,14 +220,19 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> {
|
||||
if (mBroadcast != null) {
|
||||
boolean isBroadcasting = isBroadcasting(mBtManager);
|
||||
mBroadcast.setBroadcastName((String) newValue);
|
||||
// We currently don't have a UI field for program info so we keep it
|
||||
// consistent with broadcast name.
|
||||
mBroadcast.setProgramInfo((String) newValue);
|
||||
if (isBroadcasting(mBtManager)) {
|
||||
if (isBroadcasting) {
|
||||
mBroadcast.updateBroadcast();
|
||||
}
|
||||
updateBroadcastName();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_STREAM_NAME_UPDATED,
|
||||
isBroadcasting ? 1 : 0);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.isBroadcasting;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
@@ -29,9 +30,11 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -48,6 +51,7 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
@Nullable private final LocalBluetoothLeBroadcast mBroadcast;
|
||||
@Nullable private AudioSharingPasswordPreference mPreference;
|
||||
private final AudioSharingPasswordValidator mAudioSharingPasswordValidator;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
public AudioSharingPasswordPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -57,6 +61,7 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
? mBtManager.getProfileManager().getLeAudioBroadcastProfile()
|
||||
: null;
|
||||
mAudioSharingPasswordValidator = new AudioSharingPasswordValidator();
|
||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,18 +99,38 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
}
|
||||
mPreference.setEditable(!isBroadcasting(mBtManager));
|
||||
var password = mBroadcast.getBroadcastCode();
|
||||
mPreference.setChecked(password == null || password.length == 0);
|
||||
mPreference.setChecked(isPublicBroadcast(password));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreferenceDataChanged(@NonNull String password, boolean isPublicBroadcast) {
|
||||
if (mBroadcast == null || isBroadcasting(mBtManager)) {
|
||||
Log.w(TAG, "onPreferenceDataChanged() changing password when broadcasting or null!");
|
||||
return;
|
||||
}
|
||||
persistDefaultPassword(mContext, password);
|
||||
mBroadcast.setBroadcastCode(isPublicBroadcast ? new byte[0] : password.getBytes());
|
||||
updatePreference();
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> {
|
||||
if (mBroadcast == null || isBroadcasting(mBtManager)) {
|
||||
Log.w(
|
||||
TAG,
|
||||
"onPreferenceDataChanged() changing password when"
|
||||
+ " broadcasting or null!");
|
||||
return;
|
||||
}
|
||||
boolean isCurrentPublicBroadcast =
|
||||
isPublicBroadcast(mBroadcast.getBroadcastCode());
|
||||
String currentDefaultPassword = getDefaultPassword(mContext);
|
||||
if (password.equals(currentDefaultPassword)
|
||||
&& isCurrentPublicBroadcast == isPublicBroadcast) {
|
||||
Log.d(TAG, "onPreferenceDataChanged() nothing changed");
|
||||
return;
|
||||
}
|
||||
persistDefaultPassword(mContext, password);
|
||||
mBroadcast.setBroadcastCode(
|
||||
isPublicBroadcast ? new byte[0] : password.getBytes());
|
||||
updatePreference();
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_STREAM_PASSWORD_UPDATED,
|
||||
isPublicBroadcast ? 1 : 0);
|
||||
});
|
||||
}
|
||||
|
||||
private void updatePreference() {
|
||||
@@ -116,7 +141,7 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> {
|
||||
byte[] password = mBroadcast.getBroadcastCode();
|
||||
boolean noPassword = (password == null || password.length == 0);
|
||||
boolean noPassword = isPublicBroadcast(password);
|
||||
String passwordToDisplay =
|
||||
noPassword
|
||||
? getDefaultPassword(mContext)
|
||||
@@ -140,25 +165,20 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
}
|
||||
|
||||
private static void persistDefaultPassword(Context context, String defaultPassword) {
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> {
|
||||
if (getDefaultPassword(context).equals(defaultPassword)) {
|
||||
return;
|
||||
}
|
||||
if (getDefaultPassword(context).equals(defaultPassword)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences sharedPref =
|
||||
context.getSharedPreferences(
|
||||
SHARED_PREF_NAME, Context.MODE_PRIVATE);
|
||||
if (sharedPref == null) {
|
||||
Log.w(TAG, "persistDefaultPassword(): sharedPref is empty!");
|
||||
return;
|
||||
}
|
||||
SharedPreferences sharedPref =
|
||||
context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
|
||||
if (sharedPref == null) {
|
||||
Log.w(TAG, "persistDefaultPassword(): sharedPref is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(SHARED_PREF_KEY, defaultPassword);
|
||||
editor.apply();
|
||||
});
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(SHARED_PREF_KEY, defaultPassword);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private static String getDefaultPassword(Context context) {
|
||||
@@ -175,4 +195,8 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static boolean isPublicBroadcast(@Nullable byte[] password) {
|
||||
return password == null || password.length == 0;
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
@@ -45,8 +46,7 @@ public class AudioStreamDetailsFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
// TODO(chelseahao): update metrics id
|
||||
return 0;
|
||||
return SettingsEnums.AUDIO_STREAM_DETAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,6 +20,7 @@ import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
@@ -40,12 +41,14 @@ import androidx.annotation.Nullable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.VolumeControlProfile;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -177,6 +180,8 @@ public class AudioStreamMediaService extends Service {
|
||||
LEAVE_BROADCAST_TEXT,
|
||||
com.android.settings.R.drawable.ic_clear);
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider =
|
||||
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
||||
private int mBroadcastId;
|
||||
@Nullable private ArrayList<BluetoothDevice> mDevices;
|
||||
@@ -322,6 +327,11 @@ public class AudioStreamMediaService extends Service {
|
||||
+ 0);
|
||||
if (mVolumeControl != null) {
|
||||
mVolumeControl.setDeviceVolume(mDevices.get(0), 0, true);
|
||||
mMetricsFeatureProvider.action(
|
||||
getApplicationContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_STREAM_NOTIFICATION_MUTE_BUTTON_CLICK,
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +351,10 @@ public class AudioStreamMediaService extends Service {
|
||||
mVolumeControl.setDeviceVolume(
|
||||
mDevices.get(0), mLatestPositiveVolume, true);
|
||||
}
|
||||
mMetricsFeatureProvider.action(
|
||||
getApplicationContext(),
|
||||
SettingsEnums.ACTION_AUDIO_STREAM_NOTIFICATION_MUTE_BUTTON_CLICK,
|
||||
0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -348,6 +362,10 @@ public class AudioStreamMediaService extends Service {
|
||||
Log.d(TAG, "onCustomAction: " + action);
|
||||
if (action.equals(LEAVE_BROADCAST_ACTION) && mAudioStreamsHelper != null) {
|
||||
mAudioStreamsHelper.removeSource(mBroadcastId);
|
||||
mMetricsFeatureProvider.action(
|
||||
getApplicationContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_STREAM_NOTIFICATION_LEAVE_BUTTON_CLICK);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -379,7 +397,7 @@ public class AudioStreamMediaService extends Service {
|
||||
mLocalSession != null ? mLocalSession.getSessionToken() : null);
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
mediaStyle.setRemotePlaybackInfo(
|
||||
deviceName, com.android.internal.R.drawable.ic_bt_headset_hfp, null);
|
||||
deviceName, com.android.settingslib.R.drawable.ic_bt_le_audio, null);
|
||||
}
|
||||
Notification.Builder notificationBuilder =
|
||||
new Notification.Builder(this, CHANNEL_ID)
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
@@ -45,8 +46,7 @@ public class AudioStreamsQrCodeFragment extends InstrumentedFragment {
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
// TODO(chelseahao): update metrics id
|
||||
return 0;
|
||||
return SettingsEnums.AUDIO_STREAM_QR_CODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -248,6 +248,6 @@ public class AudioStreamsQrCodeScanFragment extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.LE_AUDIO_BROADCAST_SCAN_QR_CODE;
|
||||
return SettingsEnums.AUDIO_STREAM_QR_CODE_SCAN;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@@ -111,7 +110,7 @@ public class AudioStreamsScanQrCodeController extends BasePreferenceController
|
||||
.setTitleRes(R.string.audio_streams_main_page_scan_qr_code_title)
|
||||
.setDestination(AudioStreamsQrCodeScanFragment.class.getName())
|
||||
.setResultListener(mFragment, REQUEST_SCAN_BT_BROADCAST_QR_CODE)
|
||||
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
|
||||
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
||||
.launch();
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user