Snap for 4745538 from a6b773a3e1 to pi-release

Change-Id: Ic0b835494f325dc78286b9361ad558b4b992ef61
This commit is contained in:
android-build-team Robot
2018-04-26 07:26:15 +00:00
31 changed files with 286 additions and 153 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -27,7 +27,7 @@
android:id="@+id/search_bar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/suggestion_condition_background">
android:background="?android:attr/colorPrimary">
<android.support.v7.widget.CardView
android:id="@+id/search_bar"
android:layout_width="match_parent"

Binary file not shown.

View File

@@ -95,7 +95,7 @@
<color name="usage_graph_dots">#B0BEC5</color>
<!-- Gestures settings -->
<color name="gestures_setting_background_color">#f4f4f4</color>
<color name="gestures_setting_background_color">#ffffff</color>
<color name="status_bar_color">#3c3c3c</color>

View File

@@ -474,7 +474,7 @@
</style>
<style name="SuggestionConditionStyle">
<item name="android:background">@color/suggestion_condition_background</item>
<item name="android:background">?android:attr/colorPrimary</item>
</style>
<style name="TextAppearance.SearchBar" parent="@android:style/TextAppearance.Material.Widget.Toolbar.Subtitle">

View File

@@ -30,6 +30,7 @@
android:key="gesture_assist"
android:title="@string/assist_gesture_title"
app:keywords="@string/keywords_assist_gesture_launch"
app:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
app:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -33,6 +33,7 @@
settings:keywords="@string/keywords_display_auto_brightness"
settings:controller="com.android.settings.display.AutoBrightnessPreferenceController"
settings:useAdminDisabledSummary="true"
settings:userRestriction="no_config_brightness" />
settings:userRestriction="no_config_brightness"
settings:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -31,6 +31,7 @@
android:title="@string/double_tap_power_for_camera_title"
android:summary="@string/double_tap_power_for_camera_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -31,6 +31,7 @@
android:title="@string/ambient_display_title"
android:summary="@string/ambient_display_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
app:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -31,6 +31,7 @@
android:title="@string/double_twist_for_camera_mode_title"
android:summary="@string/double_twist_for_camera_mode_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTwistPreferenceController" />
app:controller="com.android.settings.gestures.DoubleTwistPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -82,15 +82,10 @@
</PreferenceCategory>
<PreferenceCategory
android:key="game_controller_settings_category"
android:title="@string/game_controller_settings_category">
<SwitchPreference
android:key="vibrate_input_devices"
android:title="@string/vibrate_input_devices"
android:summary="@string/vibrate_input_devices_summary" />
</PreferenceCategory>
android:summary="@string/vibrate_input_devices_summary"
settings:controller="com.android.settings.inputmethod.GameControllerPreferenceController" />
</PreferenceScreen>

View File

@@ -31,6 +31,7 @@
android:title="@string/ambient_display_pickup_title"
android:summary="@string/ambient_display_pickup_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
app:controller="com.android.settings.gestures.PickupGesturePreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -32,6 +32,7 @@
android:entries="@array/gesture_prevent_ringing_entries"
android:entryValues="@array/gesture_prevent_ringing_values"
app:controller="com.android.settings.gestures.PreventRingingPreferenceController"
app:keywords="@string/keywords_gesture" />
app:keywords="@string/keywords_gesture"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -30,6 +30,7 @@
android:title="@string/fingerprint_swipe_for_notifications_title"
android:summary="@string/fingerprint_swipe_for_notifications_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
app:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -31,6 +31,7 @@
android:title="@string/swipe_up_to_switch_apps_title"
android:summary="@string/swipe_up_to_switch_apps_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.SwipeUpPreferenceController" />
app:controller="com.android.settings.gestures.SwipeUpPreferenceController"
app:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -0,0 +1,43 @@
/*
* 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.connecteddevice.dock;
import android.content.Context;
/**
* Update the dock devices. It notifies the upper level whether to add/remove the preference
* through {@link DevicePreferenceCallback}
*/
public interface DockUpdater {
/**
* Register the dock event callback and update the list
*/
default void registerCallback() {
}
/**
* Unregister the dock event callback
*/
default void unregisterCallback() {
}
/**
* Force to update the list of dock devices
*/
default void forceUpdate() {
}
}

View File

@@ -0,0 +1,29 @@
package com.android.settings.connecteddevice.dock;
import android.content.Context;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.connecteddevice.dock.DockUpdater;
import com.android.settings.overlay.DockUpdaterFeatureProvider;
/**
* Impl for {@link DockUpdaterFeatureProvider}
*/
public class DockUpdaterFeatureProviderImpl implements DockUpdaterFeatureProvider {
@Override
public DockUpdater getConnectedDockUpdater(Context context,
DevicePreferenceCallback devicePreferenceCallback) {
final DockUpdater updater = new DockUpdater() {
};
return updater;
}
@Override
public DockUpdater getSavedDockUpdater(Context context,
DevicePreferenceCallback devicePreferenceCallback) {
final DockUpdater updater = new DockUpdater() {
};
return updater;
}
}

View File

@@ -258,10 +258,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
Log.w(TAG, "Failed to get icon from uri " + uri);
return;
}
tile.icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
final Icon icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
ThreadUtils.postOnMainThread(() -> {
preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
tile.icon = null;
preference.setIcon(icon.loadDrawable(preference.getContext()));
}
);
});

View File

@@ -13,6 +13,9 @@
*/
package com.android.settings.display;
import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MAX;
import static com.android.settingslib.display.BrightnessUtils.convertLinearToGamma;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -103,6 +106,7 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
public void updateState(Preference preference) {
updatedSummary(preference);
}
@Override
public void onStart() {
mContentResolver.registerContentObserver(BRIGHTNESS_URI, false, mBrightnessObserver);
@@ -122,15 +126,18 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
}
private double getCurrentBrightness() {
final int value;
if (isInVrMode()) {
final double value = System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR,
mMaxBrightness);
return getPercentage(value, mMinVrBrightness, mMaxVrBrightness);
value = convertLinearToGamma(System.getInt(mContentResolver,
System.SCREEN_BRIGHTNESS_FOR_VR, mMaxBrightness),
mMinVrBrightness, mMaxVrBrightness);
} else {
final double value = Settings.System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS,
mMinBrightness);
return getPercentage(value, mMinBrightness, mMaxBrightness);
value = convertLinearToGamma(Settings.System.getInt(mContentResolver,
System.SCREEN_BRIGHTNESS, mMinBrightness),
mMinBrightness, mMaxBrightness);
}
return getPercentage(value, 0, GAMMA_SPACE_MAX);
}
private double getPercentage(double value, int min, int max) {

View File

@@ -19,38 +19,27 @@ package com.android.settings.inputmethod;
import android.content.Context;
import android.hardware.input.InputManager;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.view.InputDevice;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.List;
public class GameControllerPreferenceController extends AbstractPreferenceController
public class GameControllerPreferenceController extends TogglePreferenceController
implements PreferenceControllerMixin, InputManager.InputDeviceListener, LifecycleObserver,
OnResume, OnPause {
@VisibleForTesting
static final String PREF_KEY = "vibrate_input_devices";
private static final String CATEGORY_KEY = "game_controller_settings_category";
private final InputManager mIm;
private PreferenceScreen mScreen;
private Preference mCategory;
private Preference mPreference;
public GameControllerPreferenceController(Context context) {
super(context);
public GameControllerPreferenceController(Context context, String key) {
super(context, key);
mIm = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
}
@@ -67,85 +56,61 @@ public class GameControllerPreferenceController extends AbstractPreferenceContro
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mScreen = screen;
mCategory = screen.findPreference(CATEGORY_KEY);
mPreference = screen.findPreference(PREF_KEY);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public boolean isAvailable() {
@AvailabilityStatus
public int getAvailabilityStatus() {
// If device explicitly wants to hide this, return early.
if (!mContext.getResources().getBoolean(R.bool.config_show_vibrate_input_devices)) {
return false;
return DISABLED_UNSUPPORTED;
}
final int[] devices = mIm.getInputDeviceIds();
for (int deviceId : devices) {
InputDevice device = mIm.getInputDevice(deviceId);
if (device != null && !device.isVirtual() && device.getVibrator().hasVibrator()) {
return true;
return AVAILABLE;
}
}
return false;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(PREF_KEY, preference.getKey())) {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.VIBRATE_INPUT_DEVICES,
((SwitchPreference) preference).isChecked() ? 1 : 0);
return true;
}
return false;
}
@Override
public String getPreferenceKey() {
return CATEGORY_KEY;
return DISABLED_UNSUPPORTED;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (preference == null) {
return;
}
((SwitchPreference) preference).setChecked(Settings.System.getInt(
mContext.getContentResolver(),
Settings.System.VIBRATE_INPUT_DEVICES, 1) > 0);
mPreference.setVisible(isAvailable());
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
if (!isAvailable()) {
keys.add(CATEGORY_KEY);
keys.add(PREF_KEY);
public boolean isChecked() {
return Settings.System.getInt(
mContext.getContentResolver(),
Settings.System.VIBRATE_INPUT_DEVICES, 1) > 0;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.System.putInt(mContext.getContentResolver(),
Settings.System.VIBRATE_INPUT_DEVICES, isChecked ? 1 : 0);
}
@Override
public void onInputDeviceAdded(int deviceId) {
updateGameControllers();
updateState(mPreference);
}
@Override
public void onInputDeviceRemoved(int deviceId) {
updateGameControllers();
updateState(mPreference);
}
@Override
public void onInputDeviceChanged(int deviceId) {
updateGameControllers();
}
private void updateGameControllers() {
if (isAvailable()) {
mScreen.addPreference(mCategory);
updateState(mPreference);
} else {
if (mCategory != null) {
mScreen.removePreference(mCategory);
}
}
}
}

View File

@@ -35,7 +35,6 @@ import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.inputmethod.GameControllerPreferenceController;
import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController;
import com.android.settings.inputmethod.SpellCheckerPreferenceController;
import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
@@ -124,17 +123,6 @@ public class LanguageAndInputSettings extends DashboardFragment {
controllers.add(new DefaultAutofillPreferenceController(context));
controllers.add(new UserDictionaryPreferenceController(context));
// Game Controller
final GameControllerPreferenceController gameControllerPreferenceController
= new GameControllerPreferenceController(context);
if (lifecycle != null) {
lifecycle.addObserver(gameControllerPreferenceController);
}
controllers.add(gameControllerPreferenceController);
controllers.add(new PreferenceCategoryController(context,
KEY_GAME_CONTROLLER_CATEGORY).setChildren(
Arrays.asList(gameControllerPreferenceController)));
return controllers;
}

View File

@@ -67,7 +67,7 @@ public abstract class BaseNfcPreferenceController extends AbstractPreferenceCont
@Override
public void updateNonIndexableKeys(List<String> keys) {
if (isAvailable()) {
if (!isAvailable()) {
keys.add(getPreferenceKey());
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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.overlay;
import android.content.Context;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.connecteddevice.dock.DockUpdater;
/** Feature provider for the dock updater. */
public interface DockUpdaterFeatureProvider {
/** Returns the DockUpdater of the connected dock device */
DockUpdater getConnectedDockUpdater(Context context,
DevicePreferenceCallback devicePreferenceCallback);
/** Returns the DockUpdater of the saved dock devices */
DockUpdater getSavedDockUpdater(Context context,
DevicePreferenceCallback devicePreferenceCallback);
}

View File

@@ -86,6 +86,8 @@ public abstract class FeatureFactory {
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
public abstract DockUpdaterFeatureProvider getDockUpdaterFeatureProvider();
public abstract ApplicationFeatureProvider getApplicationFeatureProvider(Context context);
public abstract LocaleFeatureProvider getLocaleFeatureProvider();

View File

@@ -29,6 +29,7 @@ import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProviderImpl;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProviderImpl;
import com.android.settings.connecteddevice.dock.DockUpdaterFeatureProviderImpl;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
@@ -63,6 +64,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
private ApplicationFeatureProvider mApplicationFeatureProvider;
private MetricsFeatureProvider mMetricsFeatureProvider;
private DashboardFeatureProviderImpl mDashboardFeatureProvider;
private DockUpdaterFeatureProvider mDockUpdaterFeatureProvider;
private LocaleFeatureProvider mLocaleFeatureProvider;
private EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider;
private SearchFeatureProvider mSearchFeatureProvider;
@@ -105,6 +107,14 @@ public class FeatureFactoryImpl extends FeatureFactory {
return mDashboardFeatureProvider;
}
@Override
public DockUpdaterFeatureProvider getDockUpdaterFeatureProvider() {
if (mDockUpdaterFeatureProvider == null) {
mDockUpdaterFeatureProvider = new DockUpdaterFeatureProviderImpl();
}
return mDockUpdaterFeatureProvider;
}
@Override
public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
if (mApplicationFeatureProvider == null) {

View File

@@ -78,7 +78,6 @@ public class ConnectedDeviceDashboardFragmentTest {
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
assertThat(niks).containsExactly(KEY_CONNECTED_DEVICES, KEY_AVAILABLE_DEVICES,
NfcPreferenceController.KEY_TOGGLE_NFC);
assertThat(niks).containsExactly(KEY_CONNECTED_DEVICES, KEY_AVAILABLE_DEVICES);
}
}

View File

@@ -122,7 +122,7 @@ public class BrightnessLevelPreferenceControllerTest {
mController.updateState(mPreference);
verify(mPreference).setSummary("85%");
verify(mPreference).setSummary("97%");
}
@Test
@@ -135,7 +135,7 @@ public class BrightnessLevelPreferenceControllerTest {
mController.updateState(mPreference);
verify(mPreference).setSummary("31%");
verify(mPreference).setSummary("78%");
}
@Test
@@ -148,7 +148,7 @@ public class BrightnessLevelPreferenceControllerTest {
mController.updateState(mPreference);
verify(mPreference).setSummary("45%");
verify(mPreference).setSummary("85%");
}
@Test

View File

@@ -16,6 +16,8 @@
package com.android.settings.inputmethod;
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.never;
import static org.mockito.Mockito.spy;
@@ -37,10 +39,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class GameControllerPreferenceControllerTest {
@@ -57,7 +55,7 @@ public class GameControllerPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
mController = new GameControllerPreferenceController(mContext);
mController = new GameControllerPreferenceController(mContext, "test_key");
}
@Test
@@ -75,59 +73,59 @@ public class GameControllerPreferenceControllerTest {
}
@Test
public void testIsAvailable_hasDeviceWithVibrator_shouldReturnTrue() {
public void getAvailabilityStatus_hasDeviceWithVibrator_shouldReturnAvailable() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(false);
when(mInputDevice.getVibrator().hasVibrator()).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void testIsAvailable_hasNoVibratingDevice_shouldReturnFalse() {
public void getAvailabilityStatus_hasNoVibratingDevice_shouldReturnDisabled() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(false);
when(mInputDevice.getVibrator().hasVibrator()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
public void testIsAvailable_hasNoPhysicalDevice_shouldReturnFalse() {
public void getAvailabilityStatus_hasNoPhysicalDevice_shouldReturnDisabled() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
public void testIsAvailable_hasNoDevice_shouldReturnFalse() {
public void getAvailabilityStatus_hasNoDevice_shouldReturnDisabled() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {});
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
mController = new GameControllerPreferenceController(mContext);
public void getAvailabilityStatus_ifDisabled_shouldReturnDisabled() {
mController = new GameControllerPreferenceController(mContext, "testkey");
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});
public void setChecked_toEnabled_shouldSetToSettingsProvider() {
mController.setChecked(true);
assertThat(mController.isChecked()).isTrue();
}
final List<String> nonIndexables = new ArrayList<>();
mController.updateNonIndexableKeys(nonIndexables);
assertThat(mController.isAvailable()).isFalse();
assertThat(nonIndexables).containsExactlyElementsIn(Arrays.asList(
GameControllerPreferenceController.PREF_KEY,
mController.getPreferenceKey()));
@Test
public void setChecked_toDisabled_shouldSetToSettingsProvider() {
mController.setChecked(true);
mController.setChecked(false);
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -41,6 +41,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class AndroidBeamPreferenceControllerTest {
@@ -132,4 +135,24 @@ public class AndroidBeamPreferenceControllerTest {
mAndroidBeamController.onResume();
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
}
@Test
public void updateNonIndexableKeys_available_shouldNotUpdate() {
when(mNfcAdapter.isEnabled()).thenReturn(true);
final List<String> keys = new ArrayList<>();
mAndroidBeamController.updateNonIndexableKeys(keys);
assertThat(keys).isEmpty();
}
@Test
public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
ReflectionHelpers.setField(mAndroidBeamController, "mNfcAdapter", null);
final List<String> keys = new ArrayList<>();
mAndroidBeamController.updateNonIndexableKeys(keys);
assertThat(keys).hasSize(1);
}
}

View File

@@ -39,6 +39,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class NfcPreferenceControllerTest {
@@ -134,4 +137,24 @@ public class NfcPreferenceControllerTest {
mNfcController.onResume();
assertThat(mNfcPreference.isChecked()).isFalse();
}
@Test
public void updateNonIndexableKeys_available_shouldNotUpdate() {
when(mNfcAdapter.isEnabled()).thenReturn(true);
final List<String> keys = new ArrayList<>();
mNfcController.updateNonIndexableKeys(keys);
assertThat(keys).isEmpty();
}
@Test
public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
final List<String> keys = new ArrayList<>();
mNfcController.updateNonIndexableKeys(keys);
assertThat(keys).hasSize(1);
}
}

View File

@@ -30,6 +30,7 @@ import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.overlay.DockUpdaterFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.overlay.SurveyFeatureProvider;
@@ -52,6 +53,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public final MetricsFeatureProvider metricsFeatureProvider;
public final PowerUsageFeatureProvider powerUsageFeatureProvider;
public final DashboardFeatureProvider dashboardFeatureProvider;
public final DockUpdaterFeatureProvider dockUpdaterFeatureProvider;
public final LocaleFeatureProvider localeFeatureProvider;
public final ApplicationFeatureProvider applicationFeatureProvider;
public final EnterprisePrivacyFeatureProvider enterprisePrivacyFeatureProvider;
@@ -91,6 +93,7 @@ public class FakeFeatureFactory extends FeatureFactory {
metricsFeatureProvider = mock(MetricsFeatureProvider.class);
powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
dockUpdaterFeatureProvider = mock(DockUpdaterFeatureProvider.class);
localeFeatureProvider = mock(LocaleFeatureProvider.class);
applicationFeatureProvider = mock(ApplicationFeatureProvider.class);
enterprisePrivacyFeatureProvider = mock(EnterprisePrivacyFeatureProvider.class);
@@ -131,6 +134,11 @@ public class FakeFeatureFactory extends FeatureFactory {
return dashboardFeatureProvider;
}
@Override
public DockUpdaterFeatureProvider getDockUpdaterFeatureProvider() {
return dockUpdaterFeatureProvider;
}
@Override
public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
return applicationFeatureProvider;