Add feature provider for bluetooth settings
Also add method to get settings uri for specific device. Use feature provider here because it give us more flexibility. Bug: 120803703 Test: RunSettingsRoboTests Change-Id: I6f4840e76279c02a75b95fdecd822a72cb0b42e5
This commit is contained in:
@@ -165,4 +165,7 @@
|
||||
|
||||
<!-- Email address for the homepage contextual cards feedback -->
|
||||
<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>
|
||||
</resources>
|
||||
|
@@ -19,9 +19,7 @@ package com.android.settings.bluetooth;
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
@@ -31,6 +29,7 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -105,12 +104,10 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
super.onAttach(context);
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(context, FeatureFlags.SLICE_INJECTION)) {
|
||||
//TODO(b/120803703): update it to get data from feature provider
|
||||
use(SlicePreferenceController.class).setSliceUri(new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority("com.google.android.apps.wearables.maestro.companion")
|
||||
.appendPath("setting_slice")
|
||||
.build());
|
||||
final BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory(context)
|
||||
.getBluetoothFeatureProvider(context);
|
||||
use(SlicePreferenceController.class).setSliceUri(
|
||||
featureProvider.getBluetoothDeviceSettingsUri(mDeviceAddress));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* Provider for bluetooth related feature
|
||||
*/
|
||||
public interface BluetoothFeatureProvider {
|
||||
|
||||
/**
|
||||
* Get the {@link Uri} that represents extra settings for a specific bluetooth device
|
||||
* @param macAddress Bluetooth mac address
|
||||
* @return {@link Uri} for extra settings
|
||||
*/
|
||||
Uri getBluetoothDeviceSettingsUri(String macAddress);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Impl of {@link BluetoothFeatureProvider}
|
||||
*/
|
||||
public class BluetoothFeatureProviderImpl implements BluetoothFeatureProvider {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public BluetoothFeatureProviderImpl(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getBluetoothDeviceSettingsUri(String macAddress) {
|
||||
final String uriString = mContext.getString(R.string.config_bluetooth_device_settings_uri,
|
||||
macAddress);
|
||||
return Uri.parse(uriString);
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.accounts.AccountFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.biometrics.face.FaceFeatureProvider;
|
||||
import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
@@ -114,6 +115,8 @@ public abstract class FeatureFactory {
|
||||
|
||||
public abstract FaceFeatureProvider getFaceFeatureProvider();
|
||||
|
||||
public abstract BluetoothFeatureProvider getBluetoothFeatureProvider(Context context);
|
||||
|
||||
public static final class FactoryNotFoundException extends RuntimeException {
|
||||
public FactoryNotFoundException(Throwable throwable) {
|
||||
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
|
||||
|
@@ -30,6 +30,8 @@ import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProviderImpl;
|
||||
import com.android.settings.biometrics.face.FaceFeatureProvider;
|
||||
import com.android.settings.biometrics.face.FaceFeatureProviderImpl;
|
||||
import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.bluetooth.BluetoothFeatureProviderImpl;
|
||||
import com.android.settings.connecteddevice.dock.DockUpdaterFeatureProviderImpl;
|
||||
import com.android.settings.core.instrumentation.SettingsMetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
@@ -81,6 +83,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
private PanelFeatureProvider mPanelFeatureProvider;
|
||||
private ContextualCardFeatureProvider mContextualCardFeatureProvider;
|
||||
private FaceFeatureProvider mFaceFeatureProvider;
|
||||
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||
|
||||
@Override
|
||||
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
||||
@@ -242,4 +245,13 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
}
|
||||
return mFaceFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothFeatureProvider getBluetoothFeatureProvider(Context context) {
|
||||
if (mBluetoothFeatureProvider == null) {
|
||||
mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(
|
||||
context.getApplicationContext());
|
||||
}
|
||||
return mBluetoothFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothFeatureProviderImplTest {
|
||||
private static final String PARAMETER_KEY = "addr";
|
||||
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
||||
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(
|
||||
RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBluetoothDeviceSettingsUri_containCorrectMacAddress() {
|
||||
final Uri uri = mBluetoothFeatureProvider.getBluetoothDeviceSettingsUri(MAC_ADDRESS);
|
||||
assertThat(uri.getQueryParameterNames()).containsExactly(PARAMETER_KEY);
|
||||
assertThat(uri.getQueryParameter(PARAMETER_KEY)).isEqualTo(MAC_ADDRESS);
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import com.android.settings.accounts.AccountFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.biometrics.face.FaceFeatureProvider;
|
||||
import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
@@ -66,6 +67,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final AccountFeatureProvider mAccountFeatureProvider;
|
||||
public final ContextualCardFeatureProvider mContextualCardFeatureProvider;
|
||||
public final FaceFeatureProvider mFaceFeatureProvider;
|
||||
public final BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||
|
||||
public PanelFeatureProvider panelFeatureProvider;
|
||||
public SlicesFeatureProvider slicesFeatureProvider;
|
||||
@@ -111,6 +113,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
mContextualCardFeatureProvider = mock(ContextualCardFeatureProvider.class);
|
||||
panelFeatureProvider = mock(PanelFeatureProvider.class);
|
||||
mFaceFeatureProvider = mock(FaceFeatureProvider.class);
|
||||
mBluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,4 +210,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public FaceFeatureProvider getFaceFeatureProvider() {
|
||||
return mFaceFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothFeatureProvider getBluetoothFeatureProvider(Context context) {
|
||||
return mBluetoothFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user