Merge "Clean-up settings slices" into pi-dev
diff --git a/res/layout/choose_lock_pattern_common.xml b/res/layout/choose_lock_pattern_common.xml
index c4a9381..77dd12d 100644
--- a/res/layout/choose_lock_pattern_common.xml
+++ b/res/layout/choose_lock_pattern_common.xml
@@ -50,6 +50,7 @@
<TextView
android:id="@+id/suw_layout_title"
style="@style/SuwGlifHeaderTitle"
+ android:accessibilityLiveRegion="polite"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
diff --git a/res/layout/storage_item.xml b/res/layout/storage_item.xml
index ba1c697..aa2b4f8 100644
--- a/res/layout/storage_item.xml
+++ b/res/layout/storage_item.xml
@@ -72,7 +72,7 @@
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondaryNoDisable"
+ android:textColor="?android:attr/textColorSecondary"
android:maxLines="10"
android:layout_alignParentEnd="true"/>
diff --git a/res/values/config.xml b/res/values/config.xml
index f8a7acc..e3ec74f 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -131,7 +131,4 @@
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
<string-array name="config_settings_slices_accessibility_components" translatable="false"/>
- <!-- Whether or not swipe up gesture's opt-in setting is available on this device -->
- <bool name="config_swipe_up_gesture_setting_available">false</bool>
-
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fda46b7..ca11c9b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9249,7 +9249,7 @@
<!-- Informational text about update time only, without carrier. First argument intentionally skipped. [CHAR LIMIT=30] -->
<string name="no_carrier_update_text">Updated <xliff:g name="time" example="3m">^2</xliff:g> ago</string>
- <!-- Informational text about a recent carrier and update time [CHAR LIMIT=30] -->
+ <!-- Informational text about a recent carrier and update time [CHAR LIMIT=34] -->
<string name="carrier_and_update_now_text">Updated by <xliff:g name="carrier" example="T-mobile">^1</xliff:g> just now</string>
<!-- Informational text about recent update time only, without carrier [CHAR LIMIT=30] -->
diff --git a/res/xml/app_info_settings.xml b/res/xml/app_info_settings.xml
index 86b0df0..15afb5f 100644
--- a/res/xml/app_info_settings.xml
+++ b/res/xml/app_info_settings.xml
@@ -162,9 +162,16 @@
</PreferenceCategory>
<Preference
+ android:key="app_settings_link"
+ android:title="@string/app_settings_link"
+ settings:controller="com.android.settings.applications.appinfo.AppSettingPreferenceController"
+ settings:allowDividerAbove="true" />
+
+ <Preference
android:key="app_version"
android:selectable="false"
android:order="9999"
- settings:controller="com.android.settings.applications.appinfo.AppVersionPreferenceController" />
+ settings:controller="com.android.settings.applications.appinfo.AppVersionPreferenceController"
+ settings:allowDividerAbove="true" />
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/bluetooth_screen.xml b/res/xml/bluetooth_screen.xml
index 407feb6..9f09a8a 100644
--- a/res/xml/bluetooth_screen.xml
+++ b/res/xml/bluetooth_screen.xml
@@ -21,7 +21,7 @@
<com.android.settingslib.RestrictedPreference
android:key="bluetooth_screen_add_bt_devices"
- android:title="@string/connected_device_add_device_title"
+ android:title="@string/bluetooth_pairing_pref_title"
android:icon="@drawable/ic_menu_add"
android:summary="@string/connected_device_add_device_summary"
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index 5bee7b0..a70c85d 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -62,12 +62,6 @@
android:order="-160"
settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>
- <!-- Also vibrate for calls -->
- <SwitchPreference
- android:key="vibrate_when_ringing"
- android:title="@string/vibrate_when_ringing_title"
- android:order="-155"/>
-
<!-- Alarm volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="alarm_volume"
@@ -84,6 +78,13 @@
android:order="-140"
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>
+ <!-- Also vibrate for calls -->
+ <SwitchPreference
+ android:key="vibrate_when_ringing"
+ android:title="@string/vibrate_when_ringing_title"
+ settings:controller="com.android.settings.notification.VibrateWhenRingPreferenceController"
+ android:order="-130"/>
+
<!-- Interruptions -->
<com.android.settingslib.RestrictedPreference
android:key="zen_mode"
diff --git a/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java b/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
index 4b7631a..15d1789 100644
--- a/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
@@ -68,7 +68,7 @@
mEntityHeaderController = EntityHeaderController
.newInstance(activity, mParent, mHeader.findViewById(R.id.entity_header))
.setPackageName(mPackageName)
- .setButtonActions(EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
+ .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
EntityHeaderController.ActionType.ACTION_NONE)
.bindHeaderButtons();
}
diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
index 4a0db4e..e71c8d1 100755
--- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
@@ -167,6 +167,9 @@
use(AppOpenByDefaultPreferenceController.class).setParentFragment(this);
use(AppPermissionPreferenceController.class).setParentFragment(this);
use(AppPermissionPreferenceController.class).setPackageName(packageName);
+ use(AppSettingPreferenceController.class)
+ .setPackageName(packageName)
+ .setParentFragment(this);
use(AppStoragePreferenceController.class).setParentFragment(this);
use(AppVersionPreferenceController.class).setParentFragment(this);
use(InstantAppDomainsPreferenceController.class).setParentFragment(this);
diff --git a/src/com/android/settings/applications/appinfo/AppSettingPreferenceController.java b/src/com/android/settings/applications/appinfo/AppSettingPreferenceController.java
new file mode 100644
index 0000000..f2941b2
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppSettingPreferenceController.java
@@ -0,0 +1,77 @@
+/*
+ * 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.applications.appinfo;
+
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_OPEN_APP_SETTING;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.settings.overlay.FeatureFactory;
+
+public class AppSettingPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private String mPackageName;
+
+ public AppSettingPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ public AppSettingPreferenceController setPackageName(String packageName) {
+ mPackageName = packageName;
+ return this;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (TextUtils.isEmpty(mPackageName) || mParent == null) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ final Intent intent = resolveIntent(
+ new Intent(Intent.ACTION_APPLICATION_PREFERENCES).setPackage(mPackageName));
+ return intent != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+ final Intent intent = resolveIntent(
+ new Intent(Intent.ACTION_APPLICATION_PREFERENCES).setPackage(mPackageName));
+ if (intent == null) {
+ return false;
+ }
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
+ .actionWithSource(mContext, mParent.getMetricsCategory(),
+ ACTION_OPEN_APP_SETTING);
+ mContext.startActivity(intent);
+ return true;
+ }
+
+ private Intent resolveIntent(Intent i) {
+ ResolveInfo result = mContext.getPackageManager().resolveActivity(i, 0);
+ if (result != null) {
+ return new Intent(i.getAction())
+ .setClassName(result.activityInfo.packageName, result.activityInfo.name);
+ }
+ return null;
+ }
+}
diff --git a/src/com/android/settings/gestures/SwipeUpPreferenceController.java b/src/com/android/settings/gestures/SwipeUpPreferenceController.java
index 27c7241..b768a2c 100644
--- a/src/com/android/settings/gestures/SwipeUpPreferenceController.java
+++ b/src/com/android/settings/gestures/SwipeUpPreferenceController.java
@@ -24,7 +24,7 @@
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
-import com.android.settings.R;
+import com.android.internal.R;
public class SwipeUpPreferenceController extends GesturePreferenceController {
@@ -46,7 +46,7 @@
}
final ComponentName recentsComponentName = ComponentName.unflattenFromString(
- context.getString(com.android.internal.R.string.config_recentsComponentName));
+ context.getString(R.string.config_recentsComponentName));
final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP)
.setPackage(recentsComponentName.getPackageName());
if (context.getPackageManager().resolveService(quickStepIntent,
@@ -81,7 +81,7 @@
@Override
public boolean isChecked() {
final int defaultValue = mContext.getResources()
- .getBoolean(com.android.internal.R.bool.config_swipe_up_gesture_default) ? ON : OFF;
+ .getBoolean(R.bool.config_swipe_up_gesture_default) ? ON : OFF;
final int swipeUpEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SWIPE_UP_TO_SWITCH_APPS_ENABLED, defaultValue);
return swipeUpEnabled != OFF;
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 1c9959e..1f19031 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -131,7 +131,8 @@
@Override
public void onCreate(Bundle savedInstanceState) {
- if (mBluetoothAdapter != null) {
+ if (mBluetoothAdapter != null &&
+ mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
BluetoothProfile.PAN);
}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 3ba71a1..7fffb76 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -48,7 +48,6 @@
private static final String SELECTED_PREFERENCE_KEY = "selected_preference";
private static final int REQUEST_CODE = 200;
private static final String KEY_ZEN_MODE = "zen_mode";
-
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
@VisibleForTesting
@@ -195,7 +194,6 @@
SoundSettings fragment, Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModePreferenceController(context, lifecycle, KEY_ZEN_MODE));
- controllers.add(new VibrateWhenRingPreferenceController(context));
// Volumes are added via xml
diff --git a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
index d41e16b..d2ff7c5 100644
--- a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
+++ b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.provider.Settings.System.VIBRATE_WHEN_RINGING;
+
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -24,26 +26,41 @@
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
-import android.support.v7.preference.TwoStatePreference;
import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+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 static android.provider.Settings.System.VIBRATE_WHEN_RINGING;
-
-public class VibrateWhenRingPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
- LifecycleObserver, OnResume, OnPause {
+public class VibrateWhenRingPreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnResume, OnPause {
private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing";
+ private final int DEFAULT_VALUE = 0;
+ private final int NOTIFICATION_VIBRATE_WHEN_RINGING = 1;
private SettingObserver mSettingObserver;
- public VibrateWhenRingPreferenceController(Context context) {
- super(context);
+ public VibrateWhenRingPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.System.getInt(mContext.getContentResolver(),
+ VIBRATE_WHEN_RINGING, DEFAULT_VALUE) != DEFAULT_VALUE;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.System.putInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING,
+ isChecked ? NOTIFICATION_VIBRATE_WHEN_RINGING : DEFAULT_VALUE);
+ }
+
+ @Override
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -70,38 +87,10 @@
}
}
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- return false;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_VIBRATE_WHEN_RINGING;
- }
-
- @Override
- public boolean isAvailable() {
- return Utils.isVoiceCapable(mContext);
- }
-
- @Override
- public void updateState(Preference preference) {
- ((TwoStatePreference) preference).setChecked(
- Settings.System.getInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING, 0) != 0);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean val = (Boolean) newValue;
- return Settings.System.putInt(mContext.getContentResolver(),
- VIBRATE_WHEN_RINGING, val ? 1 : 0);
- }
-
private final class SettingObserver extends ContentObserver {
private final Uri VIBRATE_WHEN_RINGING_URI =
- Settings.System.getUriFor(VIBRATE_WHEN_RINGING);
+ Settings.System.getUriFor(VIBRATE_WHEN_RINGING);
private final Preference mPreference;
@@ -127,5 +116,4 @@
}
}
}
-
}
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 5a167b8..d744fbd 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -188,7 +188,12 @@
*/
public static CharSequence getSubtitleText(Context context,
AbstractPreferenceController controller, SliceData sliceData) {
- CharSequence summaryText;
+ CharSequence summaryText = sliceData.getScreenTitle();
+ if (isValidSummary(context, summaryText) && !TextUtils.equals(summaryText,
+ sliceData.getTitle())) {
+ return summaryText;
+ }
+
if (controller != null) {
summaryText = controller.getSummary();
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 5131159..6d67eb4 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -18,7 +18,6 @@
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
.ACTION_OPEN_APP_NOTIFICATION_SETTING;
-import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_OPEN_APP_SETTING;
import android.annotation.IdRes;
import android.annotation.UserIdInt;
@@ -28,7 +27,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
-import android.content.pm.ResolveInfo;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -59,15 +57,13 @@
public class EntityHeaderController {
@IntDef({ActionType.ACTION_NONE,
- ActionType.ACTION_APP_PREFERENCE,
ActionType.ACTION_NOTIF_PREFERENCE,
ActionType.ACTION_DND_RULE_PREFERENCE,})
@Retention(RetentionPolicy.SOURCE)
public @interface ActionType {
int ACTION_NONE = 0;
- int ACTION_APP_PREFERENCE = 1;
- int ACTION_NOTIF_PREFERENCE = 2;
- int ACTION_DND_RULE_PREFERENCE = 3;
+ int ACTION_NOTIF_PREFERENCE = 1;
+ int ACTION_DND_RULE_PREFERENCE = 2;
}
public static final String PREF_KEY_APP_HEADER = "pref_app_header";
@@ -298,9 +294,9 @@
@Override
public void onClick(View v) {
AppInfoBase.startAppInfoFragment(
- AppInfoDashboardFragment.class, R.string.application_info_label,
- mPackageName, mUid, mFragment, 0 /* request */,
- mMetricsCategory);
+ AppInfoDashboardFragment.class, R.string.application_info_label,
+ mPackageName, mUid, mFragment, 0 /* request */,
+ mMetricsCategory);
}
});
return;
@@ -371,27 +367,6 @@
}
return;
}
- case ActionType.ACTION_APP_PREFERENCE: {
- final Intent intent = resolveIntent(
- new Intent(Intent.ACTION_APPLICATION_PREFERENCES).setPackage(mPackageName));
- if (intent == null) {
- button.setImageDrawable(null);
- button.setVisibility(View.GONE);
- return;
- }
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- FeatureFactory.getFactory(mAppContext).getMetricsFeatureProvider()
- .actionWithSource(mAppContext, mMetricsCategory,
- ACTION_OPEN_APP_SETTING);
- mFragment.startActivity(intent);
- }
- });
- button.setImageResource(R.drawable.ic_settings_24dp);
- button.setVisibility(View.VISIBLE);
- return;
- }
case ActionType.ACTION_NONE: {
button.setVisibility(View.GONE);
return;
@@ -399,14 +374,6 @@
}
}
- private Intent resolveIntent(Intent i) {
- ResolveInfo result = mAppContext.getPackageManager().resolveActivity(i, 0);
- if (result != null) {
- return new Intent(i.getAction())
- .setClassName(result.activityInfo.packageName, result.activityInfo.name);
- }
- return null;
- }
private void setText(@IdRes int id, CharSequence text) {
TextView textView = mHeader.findViewById(id);
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppSettingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppSettingPreferenceControllerTest.java
new file mode 100644
index 0000000..66b58c8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppSettingPreferenceControllerTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+
+import android.app.Application;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ResolveInfo;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowPackageManager;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class AppSettingPreferenceControllerTest {
+
+ private static final String TEST_PKG_NAME = "test_pkg";
+ private static final String TEST_CLASS_NAME = "name";
+ private static final Intent TEST_INTENT =
+ new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
+ .setClassName(TEST_PKG_NAME, TEST_CLASS_NAME);
+ private static final Intent RESOLVED_INTENT =
+ new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
+ .setPackage(TEST_PKG_NAME);
+
+ @Mock
+ private AppInfoDashboardFragment mParent;
+ private Application mApplication;
+ private ShadowPackageManager mPackageManager;
+ private AppSettingPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mApplication = RuntimeEnvironment.application;
+ mPackageManager = shadowOf(mApplication.getPackageManager());
+ mController = new AppSettingPreferenceController(mApplication, "test_key");
+ mController.setPackageName(TEST_PKG_NAME).setParentFragment(mParent);
+ mPreference = new Preference(mApplication);
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_noAppSetting_shouldNotBeAvailable() {
+ assertThat(mController.isAvailable())
+ .isFalse();
+ }
+
+ @Test
+ public void getAvailabilityStatus_noPackageName_shouldNotBeAvailable() {
+ mController.setPackageName(null);
+
+ assertThat(mController.isAvailable())
+ .isFalse();
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasAppSetting_shouldBeAvailable() {
+ final ResolveInfo info = new ResolveInfo();
+ info.activityInfo = new ActivityInfo();
+ info.activityInfo.packageName = TEST_PKG_NAME;
+ info.activityInfo.name = TEST_CLASS_NAME;
+
+ mPackageManager.addResolveInfoForIntent(RESOLVED_INTENT, info);
+
+ assertThat(mController.isAvailable())
+ .isTrue();
+ }
+
+ @Test
+ public void clickPreference_noAppSetting_shouldDoNothing() {
+ assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
+ }
+
+ @Test
+ public void clickPreference_hasAppSetting_shouldLaunchIntent() {
+ final ResolveInfo info = new ResolveInfo();
+ info.activityInfo = new ActivityInfo();
+ info.activityInfo.packageName = TEST_PKG_NAME;
+ info.activityInfo.name = TEST_CLASS_NAME;
+
+ mPackageManager.addResolveInfoForIntent(RESOLVED_INTENT, info);
+
+ assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
+ assertThat(shadowOf(mApplication).getNextStartedActivity().getComponent())
+ .isEqualTo(TEST_INTENT.getComponent());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeUpPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeUpPreferenceControllerTest.java
index 4107b73..3585650 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeUpPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeUpPreferenceControllerTest.java
@@ -27,7 +27,7 @@
import android.os.UserManager;
import android.provider.Settings;
-import com.android.settings.R;
+import com.android.internal.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -57,8 +57,7 @@
public void setUp() {
SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available,
true);
- SettingsShadowResources.overrideResource(
- com.android.internal.R.bool.config_swipe_up_gesture_default, true);
+ SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_default, true);
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
@@ -107,8 +106,7 @@
@Test
public void testIsChecked_defaultIsFalse_shouldReturnFalse() {
- SettingsShadowResources.overrideResource(
- com.android.internal.R.bool.config_swipe_up_gesture_default, false);
+ SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_default, false);
assertThat(mController.isChecked()).isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 6166d29..ac573b4 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -75,10 +75,21 @@
@Test
public void lifeCycle_onCreate_shouldInitBluetoothPan() {
+ when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
mController.onCreate(null);
- verify(mBluetoothAdapter)
- .getProfileProxy(mContext, mController.mBtProfileServiceListener, BluetoothProfile.PAN);
+ verify(mBluetoothAdapter).getState();
+ verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
+ BluetoothProfile.PAN);
+ }
+
+ @Test
+ public void lifeCycle_onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
+ when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
+ mController.onCreate(null);
+
+ verify(mBluetoothAdapter).getState();
+ verifyNoMoreInteractions(mBluetoothAdapter);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
index 9314109..4e69c46 100644
--- a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
@@ -17,11 +17,17 @@
package com.android.settings.notification;
import static android.provider.Settings.System.VIBRATE_WHEN_RINGING;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
@@ -37,26 +43,32 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadow.api.Shadow;
+import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class)
public class VibrateWhenRingPreferenceControllerTest {
- @Mock
+ private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing";
+ private final int DEFAULT_VALUE = 0;
+ private final int NOTIFICATION_VIBRATE_WHEN_RINGING = 1;
private Context mContext;
+ private ContentResolver mContentResolver;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
-
private VibrateWhenRingPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mContentResolver = mContext.getContentResolver();
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
- mController = new VibrateWhenRingPreferenceController(mContext);
- mPreference = new Preference(RuntimeEnvironment.application);
+ mController = new VibrateWhenRingPreferenceController(mContext, KEY_VIBRATE_WHEN_RINGING);
+ mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@@ -80,26 +92,95 @@
}
@Test
+ public void testOnPreferenceChange_turnOn_returnOn() {
+ mController.onPreferenceChange(null, true);
+ final int mode = Settings.System.getInt(mContext.getContentResolver(),
+ VIBRATE_WHEN_RINGING, DEFAULT_VALUE);
+
+ assertThat(mode).isEqualTo(NOTIFICATION_VIBRATE_WHEN_RINGING);
+ }
+
+ @Test
+ public void testOnPreferenceChange_turnOff_returnOff() {
+ mController.onPreferenceChange(null, false);
+ final int mode = Settings.System.getInt(mContext.getContentResolver(),
+ VIBRATE_WHEN_RINGING, DEFAULT_VALUE);
+
+ assertThat(mode).isEqualTo(DEFAULT_VALUE);
+ }
+
+ @Test
+ public void voiceCapable_availabled() {
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void voiceCapable_notAvailabled() {
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
public void updateState_settingIsOn_preferenceShouldBeChecked() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
- final Context context = RuntimeEnvironment.application;
- Settings.System.putInt(context.getContentResolver(), VIBRATE_WHEN_RINGING, 1);
+ Settings.System.putInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING, 1);
- mController = new VibrateWhenRingPreferenceController(context);
mController.updateState(preference);
- verify(preference).setChecked(true);
+ assertThat(mController.isChecked()).isTrue();
}
@Test
public void updateState_settingIsOff_preferenceShouldNotBeChecked() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
- final Context context = RuntimeEnvironment.application;
- Settings.System.putInt(context.getContentResolver(), VIBRATE_WHEN_RINGING, 0);
+ Settings.System.putInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING, 0);
- mController = new VibrateWhenRingPreferenceController(context);
mController.updateState(preference);
- verify(preference).setChecked(false);
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setChecked_settingsIsOn() {
+ mController.setChecked(true);
+ final int mode = Settings.System.getInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING,
+ -1);
+
+ assertThat(mode).isEqualTo(NOTIFICATION_VIBRATE_WHEN_RINGING);
+ }
+
+ @Test
+ public void setChecked_settingsIsOff() {
+ mController.setChecked(false);
+ final int mode = Settings.System.getInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING,
+ -1);
+
+ assertThat(mode).isEqualTo(DEFAULT_VALUE);
+ }
+
+ @Test
+ public void testObserver_onResume_shouldRegisterObserver() {
+ final ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
+ mController.displayPreference(mScreen);
+
+ mController.onResume();
+
+ assertThat(shadowContentResolver.getContentObservers(
+ Settings.System.getUriFor(VIBRATE_WHEN_RINGING))).isNotEmpty();
+ }
+
+ @Test
+ public void testObserver_onPause_shouldUnregisterObserver() {
+ final ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
+ mController.displayPreference(mScreen);
+
+ mController.onResume();
+ mController.onPause();
+
+ assertThat(shadowContentResolver.getContentObservers(
+ Settings.System.getUriFor(VIBRATE_WHEN_RINGING))).isEmpty();
}
}
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index bd589bf..00e8fe1 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -204,18 +204,18 @@
}
@Test
- public void testDynamicSummary_returnsSliceSummary() {
+ public void getDynamicSummary_returnsScreenTitle() {
final SliceData data = getDummyData();
final FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
final CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
- assertThat(summary).isEqualTo(data.getSummary());
+ assertThat(summary).isEqualTo(data.getScreenTitle());
}
@Test
- public void testDynamicSummary_returnsFragmentSummary() {
- final SliceData data = getDummyData(null);
+ public void getDynamicSummary_noScreenTitle_returnsPrefControllerSummary() {
+ final SliceData data = getDummyData("", "");
final FakePreferenceController controller = spy(
new FakePreferenceController(mContext, KEY));
final String controllerSummary = "new_Summary";
@@ -227,8 +227,21 @@
}
@Test
- public void testDynamicSummary_returnsSliceEmptyString() {
- final SliceData data = getDummyData(null);
+ public void getDynamicSummary_screenTitleMatchesTitle_returnsPrefControllerSummary() {
+ final SliceData data = getDummyData("", TITLE);
+ final FakePreferenceController controller = spy(
+ new FakePreferenceController(mContext, KEY));
+ final String controllerSummary = "new_Summary";
+ doReturn(controllerSummary).when(controller).getSummary();
+
+ final CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+
+ assertThat(summary).isEqualTo(controllerSummary);
+ }
+
+ @Test
+ public void getDynamicSummary_emptyScreenTitle_emptyControllerSummary_returnsEmptyString() {
+ final SliceData data = getDummyData(null, null);
final FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
final CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
@@ -236,8 +249,9 @@
}
@Test
- public void testDynamicSummary_placeHolderString_returnsEmptyString() {
- final SliceData data = getDummyData(mContext.getString(R.string.summary_placeholder));
+ public void
+ getDynamicSummary_emptyScreenTitle_placeHolderControllerSummary_returnsEmptyString() {
+ final SliceData data = getDummyData(mContext.getString(R.string.summary_placeholder), null);
final FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
final CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
@@ -245,9 +259,9 @@
}
@Test
- public void testDynamicSummary_sliceDataAndFragmentPlaceholder_returnsSliceEmptyString() {
+ public void getDynamicSummary_screenTitleAndControllerPlaceholder_returnsSliceEmptyString() {
final String summaryPlaceholder = mContext.getString(R.string.summary_placeholder);
- final SliceData data = getDummyData(summaryPlaceholder);
+ final SliceData data = getDummyData(summaryPlaceholder, summaryPlaceholder);
final FakePreferenceController controller = spy(
new FakePreferenceController(mContext, KEY));
doReturn(summaryPlaceholder).when(controller).getSummary();
@@ -258,18 +272,6 @@
}
@Test
- public void summaryText_bothDynamicAndStaticSummary_dynamicSummaryReturned() {
- SliceData data = getDummyData("bad_summary");
- FakePreferenceController controller = spy(new FakePreferenceController(mContext, KEY));
- String controllerSummary = "new_Summary";
- doReturn(controllerSummary).when(controller).getSummary();
-
- CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
-
- assertThat(summary).isEqualTo(controllerSummary);
- }
-
- @Test
public void getPathData_splitsIntentUri() {
final Uri uri = new Uri.Builder()
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
@@ -417,23 +419,24 @@
}
private SliceData getDummyData() {
- return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH);
+ return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH, SCREEN_TITLE);
}
- private SliceData getDummyData(String summary) {
- return getDummyData(TOGGLE_CONTROLLER, summary, SliceData.SliceType.SWITCH);
+ private SliceData getDummyData(String summary, String screenTitle) {
+ return getDummyData(TOGGLE_CONTROLLER, summary, SliceData.SliceType.SWITCH, screenTitle);
}
private SliceData getDummyData(Class prefController, int sliceType) {
- return getDummyData(prefController, SUMMARY, sliceType);
+ return getDummyData(prefController, SUMMARY, sliceType, SCREEN_TITLE);
}
- private SliceData getDummyData(Class prefController, String summary, int sliceType) {
+ private SliceData getDummyData(Class prefController, String summary, int sliceType,
+ String screenTitle) {
return new SliceData.Builder()
.setKey(KEY)
.setTitle(TITLE)
.setSummary(summary)
- .setScreenTitle(SCREEN_TITLE)
+ .setScreenTitle(screenTitle)
.setKeywords(KEYWORDS)
.setIcon(ICON)
.setFragmentName(FRAGMENT_NAME)
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index e32ef77..22ad764 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -41,7 +41,6 @@
import android.widget.ImageButton;
import android.widget.TextView;
-import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -113,7 +112,7 @@
public void bindViews_shouldBindAllData() {
final String testString = "test";
final View header =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
+ mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
final TextView label = header.findViewById(R.id.entity_header_title);
final TextView summary = header.findViewById(R.id.entity_header_summary);
final TextView secondSummary = header.findViewById(R.id.entity_header_second_summary);
@@ -134,41 +133,6 @@
}
@Test
- public void bindButton_hasAppPref_shouldShowButton() {
- final ResolveInfo info = new ResolveInfo();
- info.activityInfo = new ActivityInfo();
- info.activityInfo.packageName = "123";
- info.activityInfo.name = "321";
- final View appLinks =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
- when(mActivity.getApplicationContext()).thenReturn(mContext);
- when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(info);
-
- mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
- mController.setButtonActions(
- EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
- EntityHeaderController.ActionType.ACTION_NONE);
- mController.done(mActivity);
-
- final ImageButton button1 = appLinks.findViewById(android.R.id.button1);
- assertThat(button1).isNotNull();
- assertThat(button1.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(button1.getDrawable()).isNotNull();
- assertThat(appLinks.findViewById(android.R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- try {
- appLinks.findViewById(android.R.id.button1).performClick();
- } catch (Exception e) {
- // Ignore exception because the launching intent is fake.
- }
- verify(mFeatureFactory.metricsFeatureProvider).actionWithSource(mContext,
- MetricsProto.MetricsEvent.VIEW_UNKNOWN,
- MetricsProto.MetricsEvent.ACTION_OPEN_APP_SETTING);
- verify(mFragment).startActivity(any(Intent.class));
- }
-
- @Test
public void bindButton_hasEditRuleNameClickListener_shouldShowButton() {
final ResolveInfo info = new ResolveInfo();
info.activityInfo = new ActivityInfo();
@@ -217,30 +181,9 @@
@Test
- public void bindButton_noAppPref_shouldNotShowButton() {
- final View appLinks =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
- when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(null);
-
- mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
- mController.setButtonActions(
- EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
- EntityHeaderController.ActionType.ACTION_NONE);
- mController.done(mActivity);
-
- final ImageButton button1 = appLinks.findViewById(android.R.id.button1);
- assertThat(button1).isNotNull();
- assertThat(button1.getVisibility()).isEqualTo(View.GONE);
- assertThat(button1.getDrawable()).isNull();
- assertThat(appLinks.findViewById(android.R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- }
-
- @Test
public void bindButton_noAppInfo_shouldNotAttachClickListener() {
final View appLinks =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
+ mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
final Activity activity = mock(Activity.class);
when(mFragment.getActivity()).thenReturn(activity);
@@ -265,7 +208,7 @@
@Test
public void bindButton_hasAppInfo_shouldAttachClickListener() {
final View appLinks =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
+ mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
final Activity activity = mock(Activity.class);
when(mFragment.getActivity()).thenReturn(activity);
when(mContext.getString(eq(R.string.application_info_label))).thenReturn("App Info");
@@ -281,13 +224,13 @@
appLinks.findViewById(R.id.entity_header_content).performClick();
verify(activity)
- .startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
+ .startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}
@Test
public void iconContentDescription_shouldWorkWithSetIcon() {
final View view =
- mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
+ mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
when(mFragment.getActivity()).thenReturn(mock(Activity.class));
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
String description = "Fake Description";