Remove hardcoded Uri to get slice settings
Now we get it from BluetoothDevice.getMetaData() Bug: 124121451 Test: RunSettingsRoboTests Change-Id: Id96480f257b93dd03bb290c954e01cde9dcf30ad
This commit is contained in:
@@ -171,9 +171,6 @@
|
|||||||
<!-- Email address for the homepage contextual cards feedback -->
|
<!-- Email address for the homepage contextual cards feedback -->
|
||||||
<string name="config_contextual_card_feedback_email" translatable="false"></string>
|
<string name="config_contextual_card_feedback_email" translatable="false"></string>
|
||||||
|
|
||||||
<!-- Uri that represents extra bluetooth settings -->
|
|
||||||
<string name="config_bluetooth_device_settings_uri" translatable="false">content://com.google.android.gms.nearby.fastpair/settings_slice?addr=<xliff:g id="mac_address">%1$s</xliff:g></string>
|
|
||||||
|
|
||||||
<!-- ComponentName to launch a vendor-specific enrollment activity if available -->
|
<!-- ComponentName to launch a vendor-specific enrollment activity if available -->
|
||||||
<string name="config_face_enroll" translatable="false"></string>
|
<string name="config_face_enroll" translatable="false"></string>
|
||||||
|
|
||||||
|
@@ -121,7 +121,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
|||||||
FeatureFlags.SLICE_INJECTION);
|
FeatureFlags.SLICE_INJECTION);
|
||||||
|
|
||||||
use(BlockingSlicePrefController.class).setSliceUri(injectionEnabled
|
use(BlockingSlicePrefController.class).setSliceUri(injectionEnabled
|
||||||
? featureProvider.getBluetoothDeviceSettingsUri(mDeviceAddress)
|
? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice())
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,8 +26,8 @@ public interface BluetoothFeatureProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link Uri} that represents extra settings for a specific bluetooth device
|
* Get the {@link Uri} that represents extra settings for a specific bluetooth device
|
||||||
* @param macAddress Bluetooth mac address
|
* @param bluetoothDevice bluetooth device
|
||||||
* @return {@link Uri} for extra settings
|
* @return {@link Uri} for extra settings
|
||||||
*/
|
*/
|
||||||
Uri getBluetoothDeviceSettingsUri(String macAddress);
|
Uri getBluetoothDeviceSettingsUri(BluetoothDevice bluetoothDevice);
|
||||||
}
|
}
|
||||||
|
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Impl of {@link BluetoothFeatureProvider}
|
* Impl of {@link BluetoothFeatureProvider}
|
||||||
*/
|
*/
|
||||||
@@ -33,9 +32,9 @@ public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri getBluetoothDeviceSettingsUri(String macAddress) {
|
public Uri getBluetoothDeviceSettingsUri(BluetoothDevice bluetoothDevice) {
|
||||||
final String uriString = mContext.getString(R.string.config_bluetooth_device_settings_uri,
|
final String uriString = bluetoothDevice.getMetadata(
|
||||||
macAddress);
|
BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI);
|
||||||
return Uri.parse(uriString);
|
return uriString != null ? Uri.parse(uriString) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,30 +17,40 @@ package com.android.settings.bluetooth;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BluetoothFeatureProviderImplTest {
|
public class BluetoothFeatureProviderImplTest {
|
||||||
private static final String PARAMETER_KEY = "addr";
|
private static final String SETTINGS_URI = "content://test.provider/settings_uri";
|
||||||
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
|
||||||
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private BluetoothDevice mBluetoothDevice;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(
|
mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(
|
||||||
RuntimeEnvironment.application);
|
RuntimeEnvironment.application);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBluetoothDeviceSettingsUri_containCorrectMacAddress() {
|
public void getBluetoothDeviceSettingsUri_containCorrectMacAddress() {
|
||||||
final Uri uri = mBluetoothFeatureProvider.getBluetoothDeviceSettingsUri(MAC_ADDRESS);
|
when(mBluetoothDevice.getMetadata(
|
||||||
assertThat(uri.getQueryParameterNames()).containsExactly(PARAMETER_KEY);
|
BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI)).thenReturn(SETTINGS_URI);
|
||||||
assertThat(uri.getQueryParameter(PARAMETER_KEY)).isEqualTo(MAC_ADDRESS);
|
final Uri uri = mBluetoothFeatureProvider.getBluetoothDeviceSettingsUri(mBluetoothDevice);
|
||||||
|
assertThat(uri.toString()).isEqualTo(SETTINGS_URI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user