Merge "Update the action for early warning tip." into pi-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 14fe92b..8767198 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -207,6 +207,8 @@
android:value="com.android.settings.category.ia.homepage"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
+ <meta-data android:name="android.metadata.SLICE_URI"
+ android:value="content://android.settings.slices/action/toggle_bluetooth_switch" />
</activity>
<activity android:name="AirplaneModeVoiceActivity"
@@ -2235,6 +2237,8 @@
android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.PowerUsageSummary" />
+ <meta-data android:name="android.metadata.SLICE_URI"
+ android:value="content://android.settings.slices/action/auto_brightness" />
</activity>
<activity
@@ -2251,6 +2255,8 @@
android:value="com.android.settings.fuelgauge.batterysaver.BatterySaverSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
+ <meta-data android:name="android.metadata.SLICE_URI"
+ android:value="content://android.settings.slices/action/battery_saver_summary" />
</activity>
<activity android:name=".fuelgauge.BatterySaverModeVoiceActivity"
@@ -2670,6 +2676,8 @@
android:value="true" />
<meta-data android:name="com.android.settings.summary"
android:resource="@string/sound_dashboard_summary"/>
+ <meta-data android:name="android.metadata.SLICE_URI"
+ android:value="content://android.settings.slices/action/alarm_volume" />
</activity>
<!-- Show apps for which application-level notification settings are applicable -->
diff --git a/res/drawable-nodpi/gesture_swipe_up.png b/res/drawable-nodpi/gesture_swipe_up.png
new file mode 100644
index 0000000..b9390d2
--- /dev/null
+++ b/res/drawable-nodpi/gesture_swipe_up.png
Binary files differ
diff --git a/res/layout-land/choose_lock_pattern.xml b/res/layout-land/choose_lock_pattern.xml
index cba6173..4d6f798 100644
--- a/res/layout-land/choose_lock_pattern.xml
+++ b/res/layout-land/choose_lock_pattern.xml
@@ -120,6 +120,14 @@
android:clipToPadding="false"
android:orientation="horizontal">
+ <!-- left : skip -->
+ <Button android:id="@+id/skip_button"
+ style="@style/SuwGlifButton.Secondary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/skip_label"
+ android:visibility="gone" />
+
<!-- left / top button: skip, or re-try -->
<Button android:id="@+id/footerLeftButton"
style="@style/SetupWizardButton.Negative"
diff --git a/res/layout/choose_lock_pattern_common_footer.xml b/res/layout/choose_lock_pattern_common_footer.xml
index fc36624..deea8f0 100644
--- a/res/layout/choose_lock_pattern_common_footer.xml
+++ b/res/layout/choose_lock_pattern_common_footer.xml
@@ -16,9 +16,9 @@
-->
<!-- TODO: Use aapt:attr when it is fixed (b/36809755) -->
-<LinearLayout
+<com.android.setupwizardlib.view.ButtonBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/SuwGlifButtonBar"
+ style="@style/SuwGlifButtonBar.Stackable"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@@ -49,4 +49,4 @@
android:layout_height="wrap_content"
android:text="@string/lockpattern_tutorial_continue_label" />
-</LinearLayout>
+</com.android.setupwizardlib.view.ButtonBarLayout>
diff --git a/res/raw/gesture_swipe_up.mp4 b/res/raw/gesture_swipe_up.mp4
new file mode 100644
index 0000000..16cbb2b
--- /dev/null
+++ b/res/raw/gesture_swipe_up.mp4
Binary files differ
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 029f2ad..a351bd8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -786,10 +786,10 @@
<string name="zone_time_type_dst">Daylight savings time</string>
<!-- Describes the time type "standard time" (used in zone_change_to_from_dst, when no zone specific name is available) -->
<string name="zone_time_type_standard">Standard time</string>
- <!-- The menu item to switch to selecting a time zone by region (default) -->
- <string name="zone_menu_by_region">Show time zones by region</string>
- <!-- The menu item to switch to selecting a time zone with a fixed offset (such as UTC or GMT+0200) -->
- <string name="zone_menu_by_offset">Show time zones by UTC offset</string>
+ <!-- The menu item to switch to selecting a time zone by region (default) [CHAR LIMIT=30] -->
+ <string name="zone_menu_by_region">Select by region</string>
+ <!-- The menu item to switch to selecting a time zone with a fixed offset (such as UTC or GMT+0200) [CHAR LIMIT=30] -->
+ <string name="zone_menu_by_offset">Select by UTC offset</string>
<!-- Title string shown above DatePicker, letting a user select system date
[CHAR LIMIT=20] -->
@@ -4899,10 +4899,6 @@
<string name="background_activity_title">Background restriction</string>
<!-- Summary for the background activity [CHAR_LIMIT=120] -->
<string name="background_activity_summary">Allow the app to run in the background</string>
- <!-- Summary for the background activity when it is on [CHAR_LIMIT=120] -->
- <string name="background_activity_summary_on">App can run in the background when not in use</string>
- <!-- Summary for the background activity when it is off [CHAR_LIMIT=120] -->
- <string name="background_activity_summary_off">App\'s background activity is limited when not in use</string>
<!-- Summary for the background activity when it is disabled [CHAR_LIMIT=120] -->
<string name="background_activity_summary_disabled">App not allowed to run in background</string>
<!-- TODO: Pending UX review. Summary for the background activity when it is whitlisted [CHAR_LIMIT=120] -->
@@ -5023,11 +5019,11 @@
<!-- Summary for the battery high usage tip, which presents battery may run out soon [CHAR LIMIT=NONE] -->
<string name="battery_tip_high_usage_summary">Battery may run out soon</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+ <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+ <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+ <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
<!-- Title for restricted app preference, showing how many app need to be restricted [CHAR LIMIT=NONE] -->
<plurals name="battery_tip_restrict_title">
<item quantity="one">Restrict %1$d app</item>
@@ -5097,7 +5093,7 @@
</plurals>
<!-- Footer message for restrict app details page -->
- <string name="restricted_app_detail_footer">Apps shown here aren\'t behaving properly and have been using battery in the background.\n\nThese apps are now blocked from using battery in the background. As a result, some app notifications may be delayed.</string>
+ <string name="restricted_app_detail_footer">These apps have been using battery in the background. Restricted apps may not work properly and notifications may be delayed.</string>
<!-- Title for auto restriction toggle -->
<string name="battery_auto_restriction_title">Use Battery Manager</string>
@@ -8022,7 +8018,7 @@
<string name="encryption_interstitial_no">No</string>
<!-- Label to say yes to the question of whether app is restricted. [CHAR LIMIT=20] -->
- <string name="restricted_true_label">App can\u2019t use battery in background</string>
+ <string name="restricted_true_label">Restricted</string>
<!-- Label to say no to the question of whether app is restricted. [CHAR LIMIT=20] -->
<string name="restricted_false_label">App can use battery in background</string>
diff --git a/res/xml/swipe_up_gesture_settings.xml b/res/xml/swipe_up_gesture_settings.xml
index 9c9ae7b..0f1dc4a 100644
--- a/res/xml/swipe_up_gesture_settings.xml
+++ b/res/xml/swipe_up_gesture_settings.xml
@@ -21,6 +21,11 @@
android:key="gesture_swipe_up_screen"
android:title="@string/swipe_up_to_switch_apps_title">
+ <com.android.settings.widget.VideoPreference
+ android:key="gesture_swipe_up_video"
+ app:animation="@raw/gesture_swipe_up"
+ app:preview="@drawable/gesture_swipe_up" />
+
<SwitchPreference
android:key="gesture_swipe_up"
android:title="@string/swipe_up_to_switch_apps_title"
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 24ed0b9..385e8ff 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -23,10 +23,9 @@
settings:keywords="@string/keywords_zen_mode_settings">
<!-- sound vibration -->
- <CheckBoxPreference
+ <com.android.settings.widget.DisabledCheckBoxPreference
android:key="zen_effect_sound"
- android:title="@string/zen_mode_block_effect_sound"
- android:enabled="false" />
+ android:title="@string/zen_mode_block_effect_sound" />
<!-- What to block (effects) -->
<Preference
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index ab8cc71..301e71b 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -176,7 +176,8 @@
private static final int NO_USER_SPECIFIED = -1;
// sort order
- private int mSortOrder = R.id.sort_order_alpha;
+ @VisibleForTesting
+ int mSortOrder = R.id.sort_order_alpha;
// whether showing system apps.
private boolean mShowSystem;
@@ -649,9 +650,8 @@
switch (item.getItemId()) {
case R.id.sort_order_alpha:
case R.id.sort_order_size:
- mSortOrder = menuId;
if (mApplications != null) {
- mApplications.rebuild(mSortOrder);
+ mApplications.rebuild(menuId);
}
break;
case R.id.show_system:
@@ -712,6 +712,7 @@
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mFilter = mFilterAdapter.getFilter(position);
mApplications.setFilter(mFilter);
+
if (DEBUG) Log.d(TAG, "Selecting filter " + mFilter);
}
@@ -986,6 +987,7 @@
if (sort == mLastSortMode) {
return;
}
+ mManageApplications.mSortOrder = sort;
mLastSortMode = sort;
rebuild();
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index de88279..74c65f9 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -102,7 +102,10 @@
return new AlertDialog.Builder(context)
.setMessage(getString(R.string.battery_tip_dialog_message,
- highUsageTip.getHighUsageAppList().size()))
+ highUsageTip.getHighUsageAppList().size(),
+ StringUtil.formatRelativeTime(context,
+ highUsageTip.getLastFullChargeTimeMs(),
+ false /* withSeconds */)))
.setView(view)
.setPositiveButton(android.R.string.ok, null)
.create();
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
index 8435c52..b511ee0 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
@@ -63,7 +63,8 @@
@Override
public BatteryTip detect() {
- final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
+ final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(
+ mBatteryStatsHelper, System.currentTimeMillis());
if (mPolicy.highUsageEnabled) {
parseBatteryData();
if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
@@ -99,7 +100,7 @@
}
}
- return new HighUsageTip(screenUsageTimeMs, mHighUsageAppList);
+ return new HighUsageTip(lastFullChargeTimeMs, mHighUsageAppList);
}
@VisibleForTesting
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
index 72d1fa4..c6b235b 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -26,7 +26,7 @@
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.utils.StringUtil;
+
import java.util.List;
/**
@@ -34,28 +34,28 @@
*/
public class HighUsageTip extends BatteryTip {
- private final long mScreenTimeMs;
+ private final long mLastFullChargeTimeMs;
@VisibleForTesting
final List<AppInfo> mHighUsageAppList;
- public HighUsageTip(long screenTimeMs, List<AppInfo> appList) {
+ public HighUsageTip(long lastFullChargeTimeMs, List<AppInfo> appList) {
super(TipType.HIGH_DEVICE_USAGE, appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
true /* showDialog */);
- mScreenTimeMs = screenTimeMs;
+ mLastFullChargeTimeMs = lastFullChargeTimeMs;
mHighUsageAppList = appList;
}
@VisibleForTesting
HighUsageTip(Parcel in) {
super(in);
- mScreenTimeMs = in.readLong();
+ mLastFullChargeTimeMs = in.readLong();
mHighUsageAppList = in.createTypedArrayList(AppInfo.CREATOR);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
- dest.writeLong(mScreenTimeMs);
+ dest.writeLong(mLastFullChargeTimeMs);
dest.writeTypedList(mHighUsageAppList);
}
@@ -91,8 +91,8 @@
}
}
- public long getScreenTimeMs() {
- return mScreenTimeMs;
+ public long getLastFullChargeTimeMs() {
+ return mLastFullChargeTimeMs;
}
public List<AppInfo> getHighUsageAppList() {
diff --git a/src/com/android/settings/gestures/SwipeUpPreferenceController.java b/src/com/android/settings/gestures/SwipeUpPreferenceController.java
index eb74e07..a20cd97 100644
--- a/src/com/android/settings/gestures/SwipeUpPreferenceController.java
+++ b/src/com/android/settings/gestures/SwipeUpPreferenceController.java
@@ -33,8 +33,7 @@
private final int ON = 1;
private final int OFF = 0;
- // TODO(77474484): Update when swipe up illustration video is ready
- private static final String PREF_KEY_VIDEO = "";
+ private static final String PREF_KEY_VIDEO = "gesture_swipe_up_video";
private final UserManager mUserManager;
public SwipeUpPreferenceController(Context context, String key) {
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
index 690943e..2273ffd 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
@@ -33,6 +33,10 @@
// TODO: Remove this and index all action and intent slices through search index.
String[] ACTIONS_TO_INDEX = new String[]{
Settings.ACTION_WIFI_SETTINGS,
+ Settings.ACTION_BATTERY_SAVER_SETTINGS,
+ Settings.ACTION_BLUETOOTH_SETTINGS,
+ "android.intent.action.POWER_USAGE_SUMMARY",
+ Settings.ACTION_SOUND_SETTINGS,
};
String TAG = "DeviceIndex";
@@ -40,7 +44,7 @@
String INDEX_VERSION = "settings:index_version";
// Increment when new items are added to ensure they get pushed to the device index.
- int VERSION = 1;
+ int VERSION = 2;
boolean isIndexingEnabled();
diff --git a/src/com/android/settings/widget/DisabledCheckBoxPreference.java b/src/com/android/settings/widget/DisabledCheckBoxPreference.java
new file mode 100644
index 0000000..482cff3
--- /dev/null
+++ b/src/com/android/settings/widget/DisabledCheckBoxPreference.java
@@ -0,0 +1,62 @@
+/*
+ * 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.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+
+import android.support.v7.preference.CheckBoxPreference;
+import android.support.v7.preference.PreferenceViewHolder;
+
+/**
+ * A CheckboxPreference with a disabled checkbox. Differs from CheckboxPreference.setDisabled()
+ * in that the text is not dimmed.
+ */
+public class DisabledCheckBoxPreference extends CheckBoxPreference {
+
+ public DisabledCheckBoxPreference(Context context, AttributeSet attrs,
+ int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public DisabledCheckBoxPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public DisabledCheckBoxPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ View view = holder.findViewById(android.R.id.checkbox);
+ view.setEnabled(false);
+ holder.itemView.setEnabled(false);
+ }
+
+ @Override
+ protected void performClick(View view) {
+ // Do nothing
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
index c751462..66fa212 100644
--- a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
@@ -23,6 +23,8 @@
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;
import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.Assert.assertEquals;
+
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
@@ -303,6 +305,23 @@
verify(holder, never()).updateSwitch(any(), anyBoolean(), anyBoolean());
}
+ @Test
+ public void sortOrderSavedOnRebuild() {
+ ManageApplications manageApplications = mock(ManageApplications.class);
+ manageApplications.mListType = LIST_TYPE_NOTIFICATION;
+ manageApplications.mSortOrder = -1;
+ ManageApplications.ApplicationsAdapter adapter =
+ new ManageApplications.ApplicationsAdapter(mState,
+ manageApplications, mock(AppFilterItem.class),
+ mock(Bundle.class));
+
+ adapter.rebuild(mSortRecent.getItemId());
+ assertThat(manageApplications.mSortOrder).isEqualTo(mSortRecent.getItemId());
+
+ adapter.rebuild(mSortFrequent.getItemId());
+ assertThat(manageApplications.mSortOrder).isEqualTo(mSortFrequent.getItemId());
+ }
+
private void setUpOptionMenus() {
when(mMenu.findItem(anyInt())).thenAnswer(invocation -> {
final Object[] args = invocation.getArguments();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index 5e045c1..389b714 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -183,7 +183,7 @@
mController.updateSummary(mPreference);
- assertThat(mPreference.getSummary()).isEqualTo("App can\u2019t use battery in background");
+ assertThat(mPreference.getSummary()).isEqualTo("Restricted");
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
index e07df09..1de1e48 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
@@ -112,8 +112,8 @@
final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
ShadowAlertDialog shadowDialog = shadowOf(dialog);
- assertThat(shadowDialog.getMessage())
- .isEqualTo(mContext.getString(R.string.battery_tip_dialog_message, 1));
+ assertThat(shadowDialog.getMessage()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dialog_message, 1, "60 minutes ago"));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
index ca1cba3..1ff21f8 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
@@ -43,6 +43,7 @@
private static final String PACKAGE_NAME = "com.android.app";
private static final long SCREEN_TIME = 30 * DateUtils.MINUTE_IN_MILLIS;
+ private static final long LAST_FULL_CHARGE_TIME = 20 * DateUtils.MINUTE_IN_MILLIS;
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -60,7 +61,7 @@
.setPackageName(PACKAGE_NAME)
.setScreenOnTimeMs(SCREEN_TIME)
.build());
- mBatteryTip = new HighUsageTip(SCREEN_TIME, mUsageAppList);
+ mBatteryTip = new HighUsageTip(LAST_FULL_CHARGE_TIME, mUsageAppList);
}
@Test
@@ -75,7 +76,7 @@
assertThat(parcelTip.getTitle(mContext)).isEqualTo("Phone used more than usual");
assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.HIGH_DEVICE_USAGE);
assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
- assertThat(parcelTip.getScreenTimeMs()).isEqualTo(SCREEN_TIME);
+ assertThat(parcelTip.getLastFullChargeTimeMs()).isEqualTo(LAST_FULL_CHARGE_TIME);
assertThat(parcelTip.mHighUsageAppList).isNotNull();
assertThat(parcelTip.mHighUsageAppList.size()).isEqualTo(1);
final AppInfo app = parcelTip.mHighUsageAppList.get(0);
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
index 63bf711..e38cc6a 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
@@ -101,9 +101,7 @@
ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
}
- @Config(qualifiers = "sw400dp")
- @Test
- public void sw400dp_shouldShowScreenLockOptions() {
+ private void verifyScreenLockOptionsShown() {
Button button = mActivity.findViewById(R.id.screen_lock_options);
assertThat(button).isNotNull();
assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
@@ -115,14 +113,36 @@
assertThat(count).named("List items shown").isEqualTo(3);
}
- @Config(qualifiers = "sw300dp")
+ @Config(qualifiers = "sw400dp")
@Test
- public void smallScreens_shouldHideScreenLockOptions() {
+ public void sw400dp_shouldShowScreenLockOptions() {
+ verifyScreenLockOptionsShown();
+ }
+
+ @Config(qualifiers = "sw400dp-land")
+ @Test
+ public void sw400dpLandscape_shouldShowScreenLockOptions() {
+ verifyScreenLockOptionsShown();
+ }
+
+ private void verifyScreenLockOptionsHidden() {
Button button = mActivity.findViewById(R.id.screen_lock_options);
assertThat(button).isNotNull();
assertThat(button.getVisibility()).isEqualTo(View.GONE);
}
+ @Config(qualifiers = "sw300dp")
+ @Test
+ public void smallScreens_shouldHideScreenLockOptions() {
+ verifyScreenLockOptionsHidden();
+ }
+
+ @Config(qualifiers = "sw300dp-land")
+ @Test
+ public void smallScreensLandscape_shouldHideScreenLockOptions() {
+ verifyScreenLockOptionsHidden();
+ }
+
@Test
public void skipButton_shouldBeVisible_duringNonFingerprintFlow() {
Button skipButton = mActivity.findViewById(R.id.skip_button);
diff --git a/tests/robotests/src/com/android/settings/widget/DisabledCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/DisabledCheckBoxPreferenceTest.java
new file mode 100644
index 0000000..5ab7013
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/widget/DisabledCheckBoxPreferenceTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.widget;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import android.support.v7.preference.R;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.widget.LinearLayout;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class DisabledCheckBoxPreferenceTest {
+
+ private Context mContext;
+ private View mRootView;
+ private DisabledCheckBoxPreference mPref;
+ private PreferenceViewHolder mHolder;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mRootView = View.inflate(mContext, R.layout.preference, null /* parent */);
+ mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
+ mPref = new DisabledCheckBoxPreference(mContext);
+ }
+
+ private void inflatePreference() {
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final LinearLayout widgetView = mHolder.itemView.findViewById(android.R.id.widget_frame);
+ assertThat(widgetView).isNotNull();
+ inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
+ mPref.onBindViewHolder(mHolder);
+ }
+
+ @Test
+ public void onBindViewHolder_checkboxDisabled() {
+ inflatePreference();
+ assertThat(mRootView.findViewById(android.R.id.checkbox).isEnabled()).isFalse();
+ }
+
+ @Test
+ public void checkboxOnClick_doesNothing() {
+ Preference.OnPreferenceClickListener onClick =
+ mock(Preference.OnPreferenceClickListener.class);
+ mPref.setOnPreferenceClickListener(onClick);
+ inflatePreference();
+
+ mPref.performClick(mRootView);
+
+ verify(onClick, never()).onPreferenceClick(any());
+ }
+}
diff --git a/tests/unit/src/com/android/settings/fuelgauge/batterytip/RestrictAppTest.java b/tests/unit/src/com/android/settings/fuelgauge/batterytip/RestrictAppTest.java
new file mode 100644
index 0000000..b3842d2
--- /dev/null
+++ b/tests/unit/src/com/android/settings/fuelgauge/batterytip/RestrictAppTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.fuelgauge.batterytip;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.TimeUnit;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class RestrictAppTest {
+ private static final String BATTERY_INTENT = "android.intent.action.POWER_USAGE_SUMMARY";
+ private static final String PACKAGE_SETTINGS = "com.android.settings";
+ private static final String PACKAGE_SYSTEM_UI = "com.android.systemui";
+
+ private BatteryDatabaseManager mBatteryDatabaseManager;
+ private PackageManager mPackageManager;
+
+ @Before
+ public void setUp() {
+ final Context context = InstrumentationRegistry.getTargetContext();
+ mPackageManager = context.getPackageManager();
+ mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
+ mBatteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(System.currentTimeMillis() +
+ TimeUnit.DAYS.toMillis(1));
+ }
+
+ @Test
+ public void testBatterySettings_hasOneAnomaly_showAnomaly() throws
+ PackageManager.NameNotFoundException {
+ mBatteryDatabaseManager.insertAnomaly(mPackageManager.getPackageUid(PACKAGE_SETTINGS, 0),
+ PACKAGE_SETTINGS, 1,
+ AnomalyDatabaseHelper.State.NEW, System.currentTimeMillis());
+
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ instrumentation.startActivitySync(new Intent(BATTERY_INTENT));
+ onView(withText("Restrict 1 app")).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testBatterySettings_hasTwoAnomalies_showAnomalies() throws
+ PackageManager.NameNotFoundException {
+ mBatteryDatabaseManager.insertAnomaly(mPackageManager.getPackageUid(PACKAGE_SETTINGS, 0),
+ PACKAGE_SETTINGS, 1,
+ AnomalyDatabaseHelper.State.NEW, System.currentTimeMillis());
+ mBatteryDatabaseManager.insertAnomaly(mPackageManager.getPackageUid(PACKAGE_SYSTEM_UI, 0),
+ PACKAGE_SYSTEM_UI, 1,
+ AnomalyDatabaseHelper.State.NEW, System.currentTimeMillis());
+
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ instrumentation.startActivitySync(new Intent(BATTERY_INTENT));
+ onView(withText("Restrict 2 apps")).check(matches(isDisplayed()));
+ }
+}