Implement previously connected device UI

* Move save device group to "Previously connected devices"

Bug: 74134939
Test: make -j60 RunSettingsRoboTests
Change-Id: Iff7894033df402d42dcc0ccaea6db3106edb7013
Merged-In: Iff7894033df402d42dcc0ccaea6db3106edb7013
This commit is contained in:
hughchen
2018-04-03 16:15:03 +08:00
committed by Hugh Chen
parent e6750d6c2d
commit aa31bd43a3
11 changed files with 196 additions and 71 deletions

View File

@@ -0,0 +1,29 @@
<!--
Copyright 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="24"
android:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<path android:fillColor="#FF000000"
android:pathData="M3 6h18V4H3C1.9 4 1 4.9 1 6v12c0 1.10.9 2 2 2h4v-2H3V6z M13 12H9
v1.78C8.39 14.33 8 15.11 8 16c0 0.89 0.39 1.67 1 2.22 V20h4v-1.78c0.61-0.55 1-1.34
1-2.22s-0.39-1.67-1-2.22V12z M11 17.5c-0.83 0-1.5-0.67-1.5-1.5s0.67-1.5 1.5-1.5s1.5
0.67 1.5 1.5 S11.83 17.5 11 17.5z M22 8h-6c-0.5 0-1 0.5-1 1v10c0 0.5 0.5 1 1
1h6c0.5 0 1-0.5 1-1V9C23 8.5 22.5 8 22 8z M21 18h-4v-8h4V18z" />
<path android:fillColor="#00000000"
android:pathData="M0 0h24v24H0V0z"/>
</vector>

View File

@@ -6660,6 +6660,8 @@
<string name="help_url_font_size" translatable="false"></string>
<!-- Help URL, Display size [DO NOT TRANSLATE] -->
<string name="help_url_display_size" translatable="false"></string>
<!-- Help URL, Previously connected bluetooth devices [DO NOT TRANSLATE] -->
<string name="help_url_previously_connected_devices" translatable="false"></string>
<!-- Help URL, Auto brightness [DO NOT TRANSLATE] -->
<string name="help_url_auto_brightness" translatable="false" />

View File

@@ -24,27 +24,29 @@
android:key="connected_device_list"
android:title="@string/connected_device_connected_title"/>
<PreferenceCategory
android:key="saved_device_list"
android:title="@string/connected_device_saved_title"/>
<com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
android:key="add_bt_devices"
android:title="@string/connected_device_add_device_title"
android:icon="@drawable/ic_menu_add"
android:summary="@string/connected_device_add_device_summary"
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
settings:allowDividerAbove="true"
settings:userRestriction="no_config_bluetooth"
settings:useAdminDisabledSummary="true"
settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
<Preference
android:key="previously_connected_devices"
android:title="@string/connected_device_previously_connected_title"
android:icon="@drawable/ic_devices_other_black"
android:fragment="com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment"
settings:allowDividerAbove="true"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="toggle_bluetooth_switch"
android:title="@string/bluetooth_settings_title"
android:icon="@drawable/ic_settings_bluetooth"
android:summary="@string/bluetooth_pref_summary"
settings:allowDividerAbove="true"
settings:controller="com.android.settings.bluetooth.BluetoothSwitchPreferenceController"
settings:userRestriction="no_bluetooth"
settings:platform_slice="true"/>
@@ -56,7 +58,7 @@
android:summary="@string/nfc_quick_toggle_summary"/>
<Preference
android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"
android:key="connection_preferences"
android:title="@string/connected_device_connections_title"/>
android:title="@string/connected_device_connections_title"
android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"/>
</PreferenceScreen>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="connected_devices_screen_previously"
android:title="@string/connected_device_previously_connected_title">
<PreferenceCategory
android:key="saved_device_list"
settings:controller="com.android.settings.connecteddevice.SavedDeviceGroupController"/>
</PreferenceScreen>

View File

@@ -72,7 +72,6 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
Lifecycle lifecycle, DashboardFragment dashboardFragment) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ConnectedDeviceGroupController(context, dashboardFragment, lifecycle));
controllers.add(new SavedDeviceGroupController(context, dashboardFragment, lifecycle));
final NfcPreferenceController nfcPreferenceController =
new NfcPreferenceController(context);

View File

@@ -0,0 +1,85 @@
/*
* Copyright 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.connecteddevice;
import android.content.Context;
import android.content.res.Resources;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.SearchIndexableRaw;
import java.util.ArrayList;
import java.util.List;
/**
* This fragment contains previously connected device
*/
public class PreviouslyConnectedDeviceDashboardFragment extends DashboardFragment {
private static final String TAG = "PreConnectedDeviceFrag";
static final String KEY_PREVIOUSLY_CONNECTED_DEVICES = "saved_device_list";
@Override
public int getHelpResource() {
return R.string.help_url_previously_connected_devices;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.previously_connected_devices;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.PREVIOUSLY_CONNECTED_DEVICES;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(SavedDeviceGroupController.class).init(this);
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(
Context context, boolean enabled) {
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
final Resources res = context.getResources();
// Add fragment title
SearchIndexableRaw data = new SearchIndexableRaw(context);
data.key = KEY_PREVIOUSLY_CONNECTED_DEVICES;
data.title = res.getString(
R.string.connected_device_previously_connected_title);
data.screenTitle = res.getString(
R.string.connected_device_previously_connected_title);
result.add(data);
return result;
}
};
}

View File

@@ -46,18 +46,15 @@ public class SavedDeviceGroupController extends BasePreferenceController
PreferenceGroup mPreferenceGroup;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
public SavedDeviceGroupController(Context context, DashboardFragment fragment,
Lifecycle lifecycle) {
public SavedDeviceGroupController(Context context) {
super(context, KEY);
init(lifecycle, new SavedBluetoothDeviceUpdater(context, fragment,
SavedDeviceGroupController.this));
}
@VisibleForTesting
SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
SavedDeviceGroupController(DashboardFragment fragment,
BluetoothDeviceUpdater bluetoothDeviceUpdater) {
super(fragment.getContext(), KEY);
init(lifecycle, bluetoothDeviceUpdater);
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
}
@Override
@@ -108,10 +105,8 @@ public class SavedDeviceGroupController extends BasePreferenceController
}
}
private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
if (lifecycle != null && isAvailable()) {
lifecycle.addObserver(this);
}
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
public void init(DashboardFragment fragment) {
mBluetoothDeviceUpdater = new SavedBluetoothDeviceUpdater(fragment.getContext(),
fragment, SavedDeviceGroupController.this);
}
}

View File

@@ -55,6 +55,7 @@ import com.android.settings.backup.ToggleBackupSettingFragment;
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
import com.android.settings.datausage.DataUsageList;
import com.android.settings.datausage.DataUsageSummary;
@@ -257,6 +258,7 @@ public class SettingsGateway {
DataUsageList.class.getName(),
DirectoryAccessDetails.class.getName(),
ToggleBackupSettingFragment.class.getName(),
PreviouslyConnectedDeviceDashboardFragment.class.getName(),
};
public static final String[] SETTINGS_FOR_RESTRICTED = {

View File

@@ -22,6 +22,7 @@ import com.android.settings.DateTimeSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.LegalSettings;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.datausage.DataUsageSummaryLegacy;
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -183,6 +184,7 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
addIndex(MyDeviceInfoFragment.class);
addIndex(VibrationSettings.class);
addIndex(RecentLocationRequestSeeAllFragment.class);
addIndex(PreviouslyConnectedDeviceDashboardFragment.class);
}
@Override

View File

@@ -30,6 +30,8 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +51,10 @@ public class SavedBluetoothDeviceUpdaterTest {
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private BluetoothDevice mBluetoothDevice;
@Mock
private LocalBluetoothManager mLocalManager;
@Mock
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
private Context mContext;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -60,9 +66,10 @@ public class SavedBluetoothDeviceUpdaterTest {
mContext = RuntimeEnvironment.application;
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
mDevicePreferenceCallback, null));
mDevicePreferenceCallback, mLocalManager));
mBluetoothDeviceUpdater.setPrefContext(mContext);
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());

View File

@@ -14,32 +14,20 @@
* limitations under the License
*/
package com.android.settings.connecteddevice;
import static android.arch.lifecycle.Lifecycle.Event.ON_START;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,68 +35,55 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class SavedDeviceGroupControllerTest {
private static final String PREFERENCE_KEY_1 = "pref_key_1";
@Mock
private DashboardFragment mDashboardFragment;
@Mock
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@Mock
private PackageManager mPackageManager;
private PreferenceGroup mPreferenceGroup;
private Context mContext;
private Preference mPreference;
private SavedDeviceGroupController mConnectedDeviceGroupController;
private SavedDeviceGroupController mSavedDeviceGroupController;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
doReturn(mContext).when(mDashboardFragment).getContext();
doReturn(mPackageManager).when(mContext).getPackageManager();
mSavedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
mBluetoothDeviceUpdater);
}
@Test
public void constructor_noBluetoothFeature_shouldNotRegisterCallback() {
doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
mConnectedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
mLifecycle, mBluetoothDeviceUpdater);
assertThat(mConnectedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
DISABLED_UNSUPPORTED);
mLifecycle.handleLifecycleEvent(ON_START);
verify(mBluetoothDeviceUpdater, never()).registerCallback();
}
@Test
public void constructor_hasBluetoothFeature_shouldRegisterCallback() {
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
mConnectedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
mLifecycle, mBluetoothDeviceUpdater);
assertThat(mConnectedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
AVAILABLE);
mLifecycle.handleLifecycleEvent(ON_START);
public void testRegister() {
// register the callback in onStart()
mSavedDeviceGroupController.onStart();
verify(mBluetoothDeviceUpdater).registerCallback();
}
@Test
public void testUnregister() {
// unregister the callback in onStop()
mSavedDeviceGroupController.onStop();
verify(mBluetoothDeviceUpdater).unregisterCallback();
}
@Test
public void testGetAvailabilityStatus_noBluetoothFeature_returnUnSupported() {
doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
DISABLED_UNSUPPORTED);
}
@Test
public void testGetAvailabilityStatus_BluetoothFeature_returnSupported() {
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
AVAILABLE);
}
}