Add intent action for BT device detail page

Also update detail page to accept cold start:
1. Check whether profile is ready
2. When it is ready, refresh UI

Bug: 123665527
Test: SettingsRoboTests
Change-Id: I39382fd97e9da46fca08cd2e4a3ef15d32703664
This commit is contained in:
jackqdyulei
2019-02-07 15:47:52 -08:00
parent 7946eee850
commit 715408e592
6 changed files with 78 additions and 16 deletions

View File

@@ -2987,6 +2987,18 @@
android:value="true" /> android:value="true" />
</activity> </activity>
<activity android:name="Settings$BluetoothDeviceDetailActivity"
android:label="@string/device_details_title"
android:permission="android.permission.BLUETOOTH_PRIVILEGED"
android:parentActivityName="Settings$ConnectedDeviceDashboardActivity">
<intent-filter android:priority="1">
<action android:name="com.android.settings.BLUETOOTH_DEVICE_DETAIL_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.bluetooth.BluetoothDeviceDetailsFragment" />
</activity>
<activity android:name=".panel.SettingsPanelActivity" <activity android:name=".panel.SettingsPanelActivity"
android:label="@string/settings_panel_title" android:label="@string/settings_panel_title"
android:theme="@style/Theme.BottomDialog" android:theme="@style/Theme.BottomDialog"

View File

@@ -156,6 +156,7 @@ public class Settings extends SettingsActivity {
} }
public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ } public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
public static class AdvancedConnectedDeviceActivity extends SettingsActivity { /* empty */ } public static class AdvancedConnectedDeviceActivity extends SettingsActivity { /* empty */ }
public static class BluetoothDeviceDetailActivity extends SettingsActivity { /* empty */ }
// Top level categories for new IA // Top level categories for new IA
public static class NetworkDashboardActivity extends SettingsActivity {} public static class NetworkDashboardActivity extends SettingsActivity {}

View File

@@ -45,7 +45,8 @@ import java.util.List;
* supports, such as "Phone audio", "Media audio", "Contact sharing", etc. * supports, such as "Phone audio", "Media audio", "Contact sharing", etc.
*/ */
public class BluetoothDetailsProfilesController extends BluetoothDetailsController public class BluetoothDetailsProfilesController extends BluetoothDetailsController
implements Preference.OnPreferenceClickListener { implements Preference.OnPreferenceClickListener,
LocalBluetoothProfileManager.ServiceListener {
private static final String KEY_PROFILES_GROUP = "bluetooth_profiles"; private static final String KEY_PROFILES_GROUP = "bluetooth_profiles";
@VisibleForTesting @VisibleForTesting
@@ -87,6 +88,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
pref.setKey(profile.toString()); pref.setKey(profile.toString());
pref.setTitle(profile.getNameResource(mCachedDevice.getDevice())); pref.setTitle(profile.getNameResource(mCachedDevice.getDevice()));
pref.setOnPreferenceClickListener(this); pref.setOnPreferenceClickListener(this);
pref.setOrder(profile.getOrdinal());
return pref; return pref;
} }
@@ -221,7 +223,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
} }
BluetoothDevice device = mCachedDevice.getDevice(); BluetoothDevice device = mCachedDevice.getDevice();
A2dpProfile a2dp = (A2dpProfile) profile; A2dpProfile a2dp = (A2dpProfile) profile;
if (a2dp.supportsHighQualityAudio(device)) { if (a2dp.isProfileReady() && a2dp.supportsHighQualityAudio(device)) {
SwitchPreference highQualityAudioPref = new SwitchPreference( SwitchPreference highQualityAudioPref = new SwitchPreference(
mProfilesContainer.getContext()); mProfilesContainer.getContext());
highQualityAudioPref.setKey(HIGH_QUALITY_AUDIO_PREF_TAG); highQualityAudioPref.setKey(HIGH_QUALITY_AUDIO_PREF_TAG);
@@ -235,6 +237,28 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
} }
} }
@Override
public void onPause() {
super.onPause();
mProfileManager.removeServiceListener(this);
}
@Override
public void onResume() {
super.onResume();
mProfileManager.addServiceListener(this);
}
@Override
public void onServiceConnected() {
refresh();
}
@Override
public void onServiceDisconnected() {
refresh();
}
/** /**
* Refreshes the state of the switches for all profiles, possibly adding or removing switches as * Refreshes the state of the switches for all profiles, possibly adding or removing switches as
* needed. * needed.
@@ -242,7 +266,10 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
@Override @Override
protected void refresh() { protected void refresh() {
for (LocalBluetoothProfile profile : getProfiles()) { for (LocalBluetoothProfile profile : getProfiles()) {
SwitchPreference pref = (SwitchPreference) mProfilesContainer.findPreference( if (!profile.isProfileReady()) {
continue;
}
SwitchPreference pref = mProfilesContainer.findPreference(
profile.toString()); profile.toString());
if (pref == null) { if (pref == null) {
pref = createProfilePreference(mProfilesContainer.getContext(), profile); pref = createProfilePreference(mProfilesContainer.getContext(), profile);
@@ -252,7 +279,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
refreshProfilePreference(pref, profile); refreshProfilePreference(pref, profile);
} }
for (LocalBluetoothProfile removedProfile : mCachedDevice.getRemovedProfiles()) { for (LocalBluetoothProfile removedProfile : mCachedDevice.getRemovedProfiles()) {
SwitchPreference pref = (SwitchPreference) mProfilesContainer.findPreference( final SwitchPreference pref = mProfilesContainer.findPreference(
removedProfile.toString()); removedProfile.toString());
if (pref != null) { if (pref != null) {
mProfilesContainer.removePreference(pref); mProfilesContainer.removePreference(pref);

View File

@@ -107,6 +107,11 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
mDeviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS); mDeviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS);
mManager = getLocalBluetoothManager(context); mManager = getLocalBluetoothManager(context);
mCachedDevice = getCachedDevice(mDeviceAddress); mCachedDevice = getCachedDevice(mDeviceAddress);
if (mCachedDevice == null) {
// Close this page if device is null with invalid device mac address
finish();
return;
}
super.onAttach(context); super.onAttach(context);
use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice); use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice);

View File

@@ -294,6 +294,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
PbapServerProfile psp = mock(PbapServerProfile.class); PbapServerProfile psp = mock(PbapServerProfile.class);
when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap); when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap);
when(psp.toString()).thenReturn(PbapServerProfile.NAME); when(psp.toString()).thenReturn(PbapServerProfile.NAME);
when(psp.isProfileReady()).thenReturn(true);
when(mProfileManager.getPbapProfile()).thenReturn(psp); when(mProfileManager.getPbapProfile()).thenReturn(psp);
showScreen(mController); showScreen(mController);
@@ -316,6 +317,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
PbapServerProfile psp = mock(PbapServerProfile.class); PbapServerProfile psp = mock(PbapServerProfile.class);
when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap); when(psp.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_pbap);
when(psp.toString()).thenReturn(PbapServerProfile.NAME); when(psp.toString()).thenReturn(PbapServerProfile.NAME);
when(psp.isProfileReady()).thenReturn(true);
when(mProfileManager.getPbapProfile()).thenReturn(psp); when(mProfileManager.getPbapProfile()).thenReturn(psp);
showScreen(mController); showScreen(mController);
@@ -336,6 +338,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
setupDevice(makeDefaultDeviceConfig()); setupDevice(makeDefaultDeviceConfig());
MapProfile mapProfile = mock(MapProfile.class); MapProfile mapProfile = mock(MapProfile.class);
when(mapProfile.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_map); when(mapProfile.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_map);
when(mapProfile.isProfileReady()).thenReturn(true);
when(mProfileManager.getMapProfile()).thenReturn(mapProfile); when(mProfileManager.getMapProfile()).thenReturn(mapProfile);
when(mProfileManager.getProfileByName(eq(mapProfile.toString()))).thenReturn(mapProfile); when(mProfileManager.getProfileByName(eq(mapProfile.toString()))).thenReturn(mapProfile);
mDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_REJECTED); mDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_REJECTED);
@@ -361,6 +364,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
when(profile.supportsHighQualityAudio(mDevice)).thenReturn(supportsHighQualityAudio); when(profile.supportsHighQualityAudio(mDevice)).thenReturn(supportsHighQualityAudio);
when(profile.isHighQualityAudioEnabled(mDevice)).thenReturn(highQualityAudioEnabled); when(profile.isHighQualityAudioEnabled(mDevice)).thenReturn(highQualityAudioEnabled);
when(profile.isPreferred(mDevice)).thenReturn(preferred); when(profile.isPreferred(mDevice)).thenReturn(preferred);
when(profile.isProfileReady()).thenReturn(true);
mConnectableProfiles.add(profile); mConnectableProfiles.add(profile);
return profile; return profile;
} }
@@ -442,12 +446,25 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
setupDevice(makeDefaultDeviceConfig()); setupDevice(makeDefaultDeviceConfig());
A2dpProfile audioProfile = addMockA2dpProfile(false, true, true); A2dpProfile audioProfile = addMockA2dpProfile(false, true, true);
showScreen(mController); showScreen(mController);
SwitchPreference audioPref = SwitchPreference audioPref = mScreen.findPreference(audioProfile.toString());
(SwitchPreference) mScreen.findPreference(audioProfile.toString());
SwitchPreference highQualityAudioPref = getHighQualityAudioPref(); SwitchPreference highQualityAudioPref = getHighQualityAudioPref();
assertThat(audioPref).isNotNull(); assertThat(audioPref).isNotNull();
assertThat(audioPref.isChecked()).isFalse(); assertThat(audioPref.isChecked()).isFalse();
assertThat(highQualityAudioPref).isNotNull(); assertThat(highQualityAudioPref).isNotNull();
assertThat(highQualityAudioPref.isVisible()).isFalse(); assertThat(highQualityAudioPref.isVisible()).isFalse();
} }
@Test
public void onResume_addServiceListener() {
mController.onResume();
verify(mProfileManager).addServiceListener(mController);
}
@Test
public void onPause_removeServiceListener() {
mController.onPause();
verify(mProfileManager).removeServiceListener(mController);
}
} }