Merge changes from topic "anomaly_system_app" into pi-dev
* changes:
Add method to check if app has launcher activity
Add system app check for anomaly detection.
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/drawable/ic_devices_other_black.xml b/res/drawable/ic_devices_other_black.xml
new file mode 100644
index 0000000..9974eaf
--- /dev/null
+++ b/res/drawable/ic_devices_other_black.xml
@@ -0,0 +1,29 @@
+<!--
+ Copyright 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:width="24dp"
+ android:height="24dp">
+ <path android:fillColor="#FF000000"
+ android:pathData="M3 6h18V4H3C1.9 4 1 4.9 1 6v12c0 1.10.9 2 2 2h4v-2H3V6z M13 12H9
+ v1.78C8.39 14.33 8 15.11 8 16c0 0.89 0.39 1.67 1 2.22 V20h4v-1.78c0.61-0.55 1-1.34
+ 1-2.22s-0.39-1.67-1-2.22V12z M11 17.5c-0.83 0-1.5-0.67-1.5-1.5s0.67-1.5 1.5-1.5s1.5
+ 0.67 1.5 1.5 S11.83 17.5 11 17.5z M22 8h-6c-0.5 0-1 0.5-1 1v10c0 0.5 0.5 1 1
+ 1h6c0.5 0 1-0.5 1-1V9C23 8.5 22.5 8 22 8z M21 18h-4v-8h4V18z" />
+ <path android:fillColor="#00000000"
+ android:pathData="M0 0h24v24H0V0z"/>
+</vector>
\ No newline at end of file
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..323d075 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>
@@ -6664,6 +6660,8 @@
<string name="help_url_font_size" translatable="false"></string>
<!-- Help URL, Display size [DO NOT TRANSLATE] -->
<string name="help_url_display_size" translatable="false"></string>
+ <!-- Help URL, Previously connected bluetooth devices [DO NOT TRANSLATE] -->
+ <string name="help_url_previously_connected_devices" translatable="false"></string>
<!-- Help URL, Auto brightness [DO NOT TRANSLATE] -->
<string name="help_url_auto_brightness" translatable="false" />
@@ -8022,7 +8020,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/connected_devices.xml b/res/xml/connected_devices.xml
index 7428019..030428f 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -24,27 +24,29 @@
android:key="connected_device_list"
android:title="@string/connected_device_connected_title"/>
- <PreferenceCategory
- android:key="saved_device_list"
- android:title="@string/connected_device_saved_title"/>
-
<com.android.settingslib.RestrictedPreference
- android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
android:key="add_bt_devices"
android:title="@string/connected_device_add_device_title"
android:icon="@drawable/ic_menu_add"
android:summary="@string/connected_device_add_device_summary"
+ android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
settings:allowDividerAbove="true"
settings:userRestriction="no_config_bluetooth"
settings:useAdminDisabledSummary="true"
settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
+ <Preference
+ android:key="previously_connected_devices"
+ android:title="@string/connected_device_previously_connected_title"
+ android:icon="@drawable/ic_devices_other_black"
+ android:fragment="com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment"
+ settings:allowDividerAbove="true"/>
+
<com.android.settingslib.RestrictedSwitchPreference
android:key="toggle_bluetooth_switch"
android:title="@string/bluetooth_settings_title"
android:icon="@drawable/ic_settings_bluetooth"
android:summary="@string/bluetooth_pref_summary"
- settings:allowDividerAbove="true"
settings:controller="com.android.settings.bluetooth.BluetoothSwitchPreferenceController"
settings:userRestriction="no_bluetooth"
settings:platform_slice="true"/>
@@ -56,7 +58,7 @@
android:summary="@string/nfc_quick_toggle_summary"/>
<Preference
- android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"
android:key="connection_preferences"
- android:title="@string/connected_device_connections_title"/>
+ android:title="@string/connected_device_connections_title"
+ android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"/>
</PreferenceScreen>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index ee99998..064d625 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -73,6 +73,7 @@
android:icon="@drawable/ic_airplanemode_active"
android:disableDependentsState="true"
android:order="5"
+ settings:controller="com.android.settings.network.AirplaneModePreferenceController"
settings:userRestriction="no_airplane_mode"/>
<Preference
diff --git a/res/xml/previously_connected_devices.xml b/res/xml/previously_connected_devices.xml
new file mode 100644
index 0000000..b0578a7
--- /dev/null
+++ b/res/xml/previously_connected_devices.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="connected_devices_screen_previously"
+ android:title="@string/connected_device_previously_connected_title">
+
+ <PreferenceCategory
+ android:key="saved_device_list"
+ settings:controller="com.android.settings.connecteddevice.SavedDeviceGroupController"/>
+
+</PreferenceScreen>
\ No newline at end of file
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/AirplaneModeEnabler.java b/src/com/android/settings/AirplaneModeEnabler.java
index 5f93589..11f1a28 100644
--- a/src/com/android/settings/AirplaneModeEnabler.java
+++ b/src/com/android/settings/AirplaneModeEnabler.java
@@ -24,8 +24,6 @@
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.PhoneStateIntentReceiver;
@@ -33,16 +31,26 @@
import com.android.settingslib.WirelessUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListener {
+public class AirplaneModeEnabler {
private static final int EVENT_SERVICE_STATE_CHANGED = 3;
private final Context mContext;
- private final SwitchPreference mSwitchPref;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private PhoneStateIntentReceiver mPhoneStateReceiver;
+ private OnAirplaneModeChangedListener mOnAirplaneModeChangedListener;
+
+ public interface OnAirplaneModeChangedListener {
+ /**
+ * Called when airplane mode status is changed.
+ *
+ * @param isAirplaneModeOn the airplane mode is on
+ */
+ void onAirplaneModeChanged(boolean isAirplaneModeOn);
+ }
+
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -61,25 +69,19 @@
}
};
- public AirplaneModeEnabler(Context context, SwitchPreference airplaneModeSwitchPreference,
- MetricsFeatureProvider metricsFeatureProvider) {
+ public AirplaneModeEnabler(Context context, MetricsFeatureProvider metricsFeatureProvider,
+ OnAirplaneModeChangedListener listener) {
mContext = context;
- mSwitchPref = airplaneModeSwitchPreference;
mMetricsFeatureProvider = metricsFeatureProvider;
-
- airplaneModeSwitchPreference.setPersistent(false);
+ mOnAirplaneModeChangedListener = listener;
mPhoneStateReceiver = new PhoneStateIntentReceiver(mContext, mHandler);
mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);
}
public void resume() {
-
- mSwitchPref.setChecked(WirelessUtils.isAirplaneModeOn(mContext));
-
mPhoneStateReceiver.registerIntent();
- mSwitchPref.setOnPreferenceChangeListener(this);
mContext.getContentResolver().registerContentObserver(
Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
mAirplaneModeObserver);
@@ -87,7 +89,6 @@
public void pause() {
mPhoneStateReceiver.unregisterIntent();
- mSwitchPref.setOnPreferenceChangeListener(null);
mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
}
@@ -95,8 +96,11 @@
// Change the system setting
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
enabling ? 1 : 0);
- // Update the UI to reflect system setting
- mSwitchPref.setChecked(enabling);
+
+ // Notify listener the system setting is changed.
+ if (mOnAirplaneModeChangedListener != null) {
+ mOnAirplaneModeChangedListener.onAirplaneModeChanged(enabling);
+ }
// Post the intent
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
@@ -113,22 +117,20 @@
* - mobile does not send failure notification, fail on timeout.
*/
private void onAirplaneModeChanged() {
- mSwitchPref.setChecked(WirelessUtils.isAirplaneModeOn(mContext));
+ if (mOnAirplaneModeChangedListener != null) {
+ mOnAirplaneModeChangedListener.onAirplaneModeChanged(isAirplaneModeOn());
+ }
}
- /**
- * Called when someone clicks on the checkbox preference.
- */
- public boolean onPreferenceChange(Preference preference, Object newValue) {
+ public void setAirplaneMode(boolean isAirplaneModeOn) {
if (Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
// In ECM mode, do not update database at this point
} else {
- Boolean value = (Boolean) newValue;
- mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_AIRPLANE_TOGGLE, value);
- setAirplaneModeOn(value);
+ mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_AIRPLANE_TOGGLE,
+ isAirplaneModeOn);
+ setAirplaneModeOn(isAirplaneModeOn);
}
- return true;
}
public void setAirplaneModeInECM(boolean isECMExit, boolean isAirplaneModeOn) {
@@ -141,4 +143,7 @@
}
}
+ public boolean isAirplaneModeOn() {
+ return WirelessUtils.isAirplaneModeOn(mContext);
+ }
}
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/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index b3dd8ac..942fd7b 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -72,7 +72,6 @@
Lifecycle lifecycle, DashboardFragment dashboardFragment) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ConnectedDeviceGroupController(context, dashboardFragment, lifecycle));
- controllers.add(new SavedDeviceGroupController(context, dashboardFragment, lifecycle));
final NfcPreferenceController nfcPreferenceController =
new NfcPreferenceController(context);
diff --git a/src/com/android/settings/connecteddevice/PreviouslyConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/PreviouslyConnectedDeviceDashboardFragment.java
new file mode 100644
index 0000000..195daf3
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/PreviouslyConnectedDeviceDashboardFragment.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.connecteddevice;
+
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.SearchIndexableRaw;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This fragment contains previously connected device
+ */
+public class PreviouslyConnectedDeviceDashboardFragment extends DashboardFragment {
+
+ private static final String TAG = "PreConnectedDeviceFrag";
+ static final String KEY_PREVIOUSLY_CONNECTED_DEVICES = "saved_device_list";
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_previously_connected_devices;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.previously_connected_devices;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.PREVIOUSLY_CONNECTED_DEVICES;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ use(SavedDeviceGroupController.class).init(this);
+ }
+
+ /**
+ * For Search.
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableRaw> getRawDataToIndex(
+ Context context, boolean enabled) {
+ final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
+ final Resources res = context.getResources();
+
+ // Add fragment title
+ SearchIndexableRaw data = new SearchIndexableRaw(context);
+ data.key = KEY_PREVIOUSLY_CONNECTED_DEVICES;
+ data.title = res.getString(
+ R.string.connected_device_previously_connected_title);
+ data.screenTitle = res.getString(
+ R.string.connected_device_previously_connected_title);
+ result.add(data);
+ return result;
+ }
+ };
+}
\ No newline at end of file
diff --git a/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
index ff21bff..d045c9e 100644
--- a/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
+++ b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
@@ -46,18 +46,15 @@
PreferenceGroup mPreferenceGroup;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
- public SavedDeviceGroupController(Context context, DashboardFragment fragment,
- Lifecycle lifecycle) {
+ public SavedDeviceGroupController(Context context) {
super(context, KEY);
- init(lifecycle, new SavedBluetoothDeviceUpdater(context, fragment,
- SavedDeviceGroupController.this));
}
@VisibleForTesting
- SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
+ SavedDeviceGroupController(DashboardFragment fragment,
BluetoothDeviceUpdater bluetoothDeviceUpdater) {
super(fragment.getContext(), KEY);
- init(lifecycle, bluetoothDeviceUpdater);
+ mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
}
@Override
@@ -108,10 +105,8 @@
}
}
- private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
- if (lifecycle != null && isAvailable()) {
- lifecycle.addObserver(this);
- }
- mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
+ public void init(DashboardFragment fragment) {
+ mBluetoothDeviceUpdater = new SavedBluetoothDeviceUpdater(fragment.getContext(),
+ fragment, SavedDeviceGroupController.this);
}
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index afa5f5e..ede23dc 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -55,6 +55,7 @@
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
+import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
import com.android.settings.datausage.DataUsageList;
import com.android.settings.datausage.DataUsageSummary;
@@ -257,6 +258,7 @@
DataUsageList.class.getName(),
DirectoryAccessDetails.class.getName(),
ToggleBackupSettingFragment.class.getName(),
+ PreviouslyConnectedDeviceDashboardFragment.class.getName(),
};
public static final String[] SETTINGS_FOR_RESTRICTED = {
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/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
index 98ff244..1f79e7c 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
@@ -30,6 +30,7 @@
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.batterytip.actions.BatterySaverAction;
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
+import com.android.settings.fuelgauge.batterytip.actions.OpenBatterySaverAction;
import com.android.settings.fuelgauge.batterytip.actions.OpenRestrictAppFragmentAction;
import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction;
import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
@@ -93,7 +94,11 @@
case BatteryTip.TipType.SMART_BATTERY_MANAGER:
return new SmartBatteryAction(settingsActivity, fragment);
case BatteryTip.TipType.BATTERY_SAVER:
- return new BatterySaverAction(settingsActivity);
+ if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
+ return new OpenBatterySaverAction(settingsActivity);
+ } else {
+ return new BatterySaverAction(settingsActivity);
+ }
case BatteryTip.TipType.APP_RESTRICTION:
if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
return new OpenRestrictAppFragmentAction(settingsActivity, fragment,
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java
new file mode 100644
index 0000000..9f9a99d
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java
@@ -0,0 +1,56 @@
+/*
+ * 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.actions;
+
+import android.content.Context;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.core.InstrumentedPreferenceFragment;
+import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.RestrictedAppDetails;
+import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
+import com.android.settings.fuelgauge.batterytip.AppInfo;
+import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
+
+import java.util.List;
+
+/**
+ *
+ * Action to open the {@link com.android.settings.fuelgauge.batterysaver.BatterySaverSettings}
+ */
+public class OpenBatterySaverAction extends BatteryTipAction {
+
+ public OpenBatterySaverAction(Context context) {
+ super(context);
+ }
+
+ /**
+ * Handle the action when user clicks positive button
+ */
+ @Override
+ public void handlePositiveAction(int metricsKey) {
+ mMetricsFeatureProvider.action(mContext,
+ MetricsProto.MetricsEvent.ACTION_TIP_OPEN_BATTERY_SAVER_PAGE, metricsKey);
+ new SubSettingLauncher(mContext)
+ .setDestination(BatterySaverSettings.class.getName())
+ .setSourceMetricsCategory(metricsKey)
+ .launch();
+ }
+}
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/network/AirplaneModePreferenceController.java b/src/com/android/settings/network/AirplaneModePreferenceController.java
index 0b77179..b4851e6 100644
--- a/src/com/android/settings/network/AirplaneModePreferenceController.java
+++ b/src/com/android/settings/network/AirplaneModePreferenceController.java
@@ -27,17 +27,17 @@
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.AirplaneModeEnabler;
-import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.R;
-import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
-public class AirplaneModePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
+public class AirplaneModePreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnResume, OnPause,
+ AirplaneModeEnabler.OnAirplaneModeChangedListener {
public static final int REQUEST_CODE_EXIT_ECM = 1;
@@ -45,18 +45,21 @@
private static final String EXIT_ECM_RESULT = "exit_ecm_result";
- private final Fragment mFragment;
+ private Fragment mFragment;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private AirplaneModeEnabler mAirplaneModeEnabler;
private SwitchPreference mAirplaneModePreference;
- public AirplaneModePreferenceController(Context context, Fragment hostFragment) {
- super(context);
- mFragment = hostFragment;
+ public AirplaneModePreferenceController(Context context, String key) {
+ super(context, key);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
+ public void setFragment(Fragment hostFragment) {
+ mFragment = hostFragment;
+ }
+
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_TOGGLE_AIRPLANE.equals(preference.getKey()) && Boolean.parseBoolean(
@@ -75,30 +78,22 @@
@Override
public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
if (isAvailable()) {
mAirplaneModePreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
- if (mAirplaneModePreference != null) {
- mAirplaneModeEnabler = new AirplaneModeEnabler(mContext, mAirplaneModePreference,
- mMetricsFeatureProvider);
- }
- } else {
- setVisible(screen, getPreferenceKey(), false /* visible */);
+ mAirplaneModeEnabler = new AirplaneModeEnabler(mContext, mMetricsFeatureProvider, this);
}
}
- @Override
- public boolean isAvailable() {
- return isAvailable(mContext);
- }
-
public static boolean isAvailable(Context context) {
return context.getResources().getBoolean(R.bool.config_show_toggle_airplane)
&& !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
@Override
- public String getPreferenceKey() {
- return KEY_TOGGLE_AIRPLANE;
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
public void onResume() {
@@ -122,4 +117,23 @@
mAirplaneModePreference.isChecked());
}
}
+
+ @Override
+ public boolean isChecked() {
+ return mAirplaneModeEnabler.isAirplaneModeOn();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ if (isChecked() == isChecked) {
+ return false;
+ }
+ mAirplaneModeEnabler.setAirplaneMode(isChecked);
+ return true;
+ }
+
+ @Override
+ public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
+ mAirplaneModePreference.setChecked(isAirplaneModeOn);
+ }
}
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 955c503..466fa01 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -71,6 +71,8 @@
public void onAttach(Context context) {
super.onAttach(context);
mNetworkResetController = new NetworkResetActionMenuController(context, MENU_NETWORK_RESET);
+
+ use(AirplaneModePreferenceController.class).setFragment(this);
}
@Override
@@ -94,8 +96,6 @@
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, MetricsFeatureProvider metricsFeatureProvider, Fragment fragment,
MobilePlanPreferenceHost mobilePlanHost) {
- final AirplaneModePreferenceController airplaneModePreferenceController =
- new AirplaneModePreferenceController(context, fragment);
final MobilePlanPreferenceController mobilePlanPreferenceController =
new MobilePlanPreferenceController(context, mobilePlanHost);
final WifiMasterSwitchPreferenceController wifiPreferenceController =
@@ -108,7 +108,6 @@
new PrivateDnsPreferenceController(context);
if (lifecycle != null) {
- lifecycle.addObserver(airplaneModePreferenceController);
lifecycle.addObserver(mobilePlanPreferenceController);
lifecycle.addObserver(wifiPreferenceController);
lifecycle.addObserver(mobileNetworkPreferenceController);
@@ -117,7 +116,6 @@
}
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(airplaneModePreferenceController);
controllers.add(mobileNetworkPreferenceController);
controllers.add(new TetherPreferenceController(context, lifecycle));
controllers.add(vpnPreferenceController);
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/search/SearchIndexableResourcesImpl.java b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
index 3e4e0be6..33bc2e0 100644
--- a/src/com/android/settings/search/SearchIndexableResourcesImpl.java
+++ b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
@@ -22,6 +22,7 @@
import com.android.settings.DisplaySettings;
import com.android.settings.LegalSettings;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
+import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.datausage.DataUsageSummaryLegacy;
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -183,6 +184,7 @@
addIndex(MyDeviceInfoFragment.class);
addIndex(VibrationSettings.class);
addIndex(RecentLocationRequestSeeAllFragment.class);
+ addIndex(PreviouslyConnectedDeviceDashboardFragment.class);
}
@Override
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 05f0974..a2479a2 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -51,7 +51,6 @@
import android.support.v4.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceMetadata;
import androidx.slice.builders.ListBuilder;
import androidx.slice.builders.SliceAction;
@@ -154,7 +153,7 @@
* @return {@link PendingIntent} for a non-primary {@link SliceAction}.
*/
public static PendingIntent getActionIntent(Context context, String action, SliceData data) {
- Intent intent = new Intent(action);
+ final Intent intent = new Intent(action);
intent.setClass(context, SliceBroadcastReceiver.class);
intent.putExtra(EXTRA_SLICE_KEY, data.getKey());
intent.putExtra(EXTRA_SLICE_PLATFORM_DEFINED, data.isPlatformDefined());
@@ -165,11 +164,8 @@
/**
* @return {@link PendingIntent} for the primary {@link SliceAction}.
*/
- public static PendingIntent getContentIntent(Context context, SliceData sliceData) {
- Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
- sliceData.getFragmentClassName(), sliceData.getKey(), sliceData.getScreenTitle(),
- 0 /* TODO */);
- intent.setClassName("com.android.settings", SubSettings.class.getName());
+ public static PendingIntent getContentPendingIntent(Context context, SliceData sliceData) {
+ final Intent intent = getContentIntent(context, sliceData);
return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
}
@@ -215,9 +211,20 @@
.build();
}
+ @VisibleForTesting
+ static Intent getContentIntent(Context context, SliceData sliceData) {
+ final Uri contentUri = new Uri.Builder().appendPath(sliceData.getKey()).build();
+ final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
+ sliceData.getFragmentClassName(), sliceData.getKey(), sliceData.getScreenTitle(),
+ 0 /* TODO */);
+ intent.setClassName(context.getPackageName(), SubSettings.class.getName());
+ intent.setData(contentUri);
+ return intent;
+ }
+
private static Slice buildToggleSlice(Context context, SliceData sliceData,
BasePreferenceController controller) {
- final PendingIntent contentIntent = getContentIntent(context, sliceData);
+ final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
final Icon icon = Icon.createWithResource(context, sliceData.getIconResource());
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
final TogglePreferenceController toggleController =
@@ -237,7 +244,7 @@
private static Slice buildIntentSlice(Context context, SliceData sliceData,
BasePreferenceController controller) {
- final PendingIntent contentIntent = getContentIntent(context, sliceData);
+ final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
final Icon icon = Icon.createWithResource(context, sliceData.getIconResource());
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
@@ -314,12 +321,12 @@
break;
case DISABLED_FOR_USER:
summary = context.getString(R.string.disabled_for_user_setting_summary);
- primaryAction = new SliceAction(getContentIntent(context, data),
+ primaryAction = new SliceAction(getContentPendingIntent(context, data),
(IconCompat) null /* actionIcon */, null /* actionTitle */);
break;
case DISABLED_DEPENDENT_SETTING:
summary = context.getString(R.string.disabled_dependent_setting_summary);
- primaryAction = new SliceAction(getContentIntent(context, data),
+ primaryAction = new SliceAction(getContentPendingIntent(context, data),
(IconCompat) null /* actionIcon */, null /* actionTitle */);
break;
case UNAVAILABLE_UNKNOWN:
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/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
index ee76269..e0ba829 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -30,6 +30,8 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +51,10 @@
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private BluetoothDevice mBluetoothDevice;
+ @Mock
+ private LocalBluetoothManager mLocalManager;
+ @Mock
+ private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
private Context mContext;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -60,9 +66,10 @@
mContext = RuntimeEnvironment.application;
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
- mDevicePreferenceCallback, null));
+ mDevicePreferenceCallback, mLocalManager));
mBluetoothDeviceUpdater.setPrefContext(mContext);
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/SavedDeviceGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/SavedDeviceGroupControllerTest.java
index 3d606dd..a0d3d7b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/SavedDeviceGroupControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/SavedDeviceGroupControllerTest.java
@@ -14,32 +14,20 @@
* limitations under the License
*/
package com.android.settings.connecteddevice;
-
-import static android.arch.lifecycle.Lifecycle.Event.ON_START;
-
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
-
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-
import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.PackageManager;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceManager;
-import android.support.v7.preference.PreferenceScreen;
-
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,68 +35,55 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class SavedDeviceGroupControllerTest {
private static final String PREFERENCE_KEY_1 = "pref_key_1";
-
@Mock
private DashboardFragment mDashboardFragment;
@Mock
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
- @Mock
- private PreferenceScreen mPreferenceScreen;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@Mock
private PackageManager mPackageManager;
-
- private PreferenceGroup mPreferenceGroup;
private Context mContext;
- private Preference mPreference;
- private SavedDeviceGroupController mConnectedDeviceGroupController;
+ private SavedDeviceGroupController mSavedDeviceGroupController;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
-
mContext = spy(RuntimeEnvironment.application);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
-
doReturn(mContext).when(mDashboardFragment).getContext();
doReturn(mPackageManager).when(mContext).getPackageManager();
+ mSavedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
+ mBluetoothDeviceUpdater);
}
-
@Test
- public void constructor_noBluetoothFeature_shouldNotRegisterCallback() {
- doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
-
- mConnectedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
- mLifecycle, mBluetoothDeviceUpdater);
-
- assertThat(mConnectedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
- DISABLED_UNSUPPORTED);
-
- mLifecycle.handleLifecycleEvent(ON_START);
- verify(mBluetoothDeviceUpdater, never()).registerCallback();
- }
-
-
- @Test
- public void constructor_hasBluetoothFeature_shouldRegisterCallback() {
- doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
-
- mConnectedDeviceGroupController = new SavedDeviceGroupController(mDashboardFragment,
- mLifecycle, mBluetoothDeviceUpdater);
-
- assertThat(mConnectedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
- AVAILABLE);
-
- mLifecycle.handleLifecycleEvent(ON_START);
+ public void testRegister() {
+ // register the callback in onStart()
+ mSavedDeviceGroupController.onStart();
verify(mBluetoothDeviceUpdater).registerCallback();
}
-}
+ @Test
+ public void testUnregister() {
+ // unregister the callback in onStop()
+ mSavedDeviceGroupController.onStop();
+ verify(mBluetoothDeviceUpdater).unregisterCallback();
+ }
+ @Test
+ public void testGetAvailabilityStatus_noBluetoothFeature_returnUnSupported() {
+ doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+ assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
+ DISABLED_UNSUPPORTED);
+ }
+ @Test
+ public void testGetAvailabilityStatus_BluetoothFeature_returnSupported() {
+ doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+ assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
+ AVAILABLE);
+ }
+}
\ No newline at end of file
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/BatteryTipUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
index c731a2e..7a25555 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
@@ -23,9 +23,12 @@
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
+import com.android.settings.fuelgauge.batterytip.actions.BatterySaverAction;
+import com.android.settings.fuelgauge.batterytip.actions.OpenBatterySaverAction;
import com.android.settings.fuelgauge.batterytip.actions.OpenRestrictAppFragmentAction;
import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -47,6 +50,7 @@
@Mock
private InstrumentedPreferenceFragment mFragment;
private RestrictAppTip mRestrictAppTip;
+ private EarlyWarningTip mEarlyWarningTip;
@Before
public void setUp() {
@@ -55,6 +59,7 @@
FakeFeatureFactory.setupForTest();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
mRestrictAppTip = spy(new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>()));
+ mEarlyWarningTip = spy(new EarlyWarningTip(BatteryTip.StateType.NEW, true));
}
@Test
@@ -72,4 +77,20 @@
assertThat(BatteryTipUtils.getActionForBatteryTip(mRestrictAppTip, mSettingsActivity,
mFragment)).isInstanceOf(OpenRestrictAppFragmentAction.class);
}
+
+ @Test
+ public void testGetActionForBatteryTip_typeEarlyWarningStateNew_returnActionBatterySaver() {
+ when(mEarlyWarningTip.getState()).thenReturn(BatteryTip.StateType.NEW);
+
+ assertThat(BatteryTipUtils.getActionForBatteryTip(mEarlyWarningTip, mSettingsActivity,
+ mFragment)).isInstanceOf(BatterySaverAction.class);
+ }
+
+ @Test
+ public void testGetActionForBatteryTip_typeEarlyWarningStateHandled_returnActionOpen() {
+ when(mEarlyWarningTip.getState()).thenReturn(BatteryTip.StateType.HANDLED);
+
+ assertThat(BatteryTipUtils.getActionForBatteryTip(mEarlyWarningTip, mSettingsActivity,
+ mFragment)).isInstanceOf(OpenBatterySaverAction.class);
+ }
}
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/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
index 33eed3e..a255333 100644
--- a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -22,13 +22,18 @@
import static org.mockito.Mockito.when;
import android.arch.lifecycle.LifecycleOwner;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.provider.Settings;
+import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -41,13 +46,17 @@
@RunWith(SettingsRobolectricTestRunner.class)
public class AirplaneModePreferenceControllerTest {
- @Mock
- private PreferenceScreen mScreen;
+ private static final int ON = 1;
+ private static final int OFF = 0;
@Mock
private PackageManager mPackageManager;
private Context mContext;
+ private ContentResolver mResolver;
+ private PreferenceManager mPreferenceManager;
+ private PreferenceScreen mScreen;
+ private RestrictedSwitchPreference mPreference;
private AirplaneModePreferenceController mController;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@@ -57,8 +66,17 @@
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
mContext = spy(RuntimeEnvironment.application);
+ mResolver = RuntimeEnvironment.application.getContentResolver();
doReturn(mPackageManager).when(mContext).getPackageManager();
- mController = spy(new AirplaneModePreferenceController(mContext, null));
+ mController = new AirplaneModePreferenceController(mContext,
+ AirplaneModePreferenceController.KEY_TOGGLE_AIRPLANE);
+
+ mPreferenceManager = new PreferenceManager(mContext);
+ mScreen = mPreferenceManager.createPreferenceScreen(mContext);
+ mPreference = new RestrictedSwitchPreference(mContext);
+ mPreference.setKey("toggle_airplane");
+ mScreen.addPreference(mPreference);
+ mController.setFragment(null);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mLifecycle.addObserver(mController);
@@ -67,7 +85,8 @@
@Test
@Config(qualifiers = "mcc999")
public void airplaneModePreference_shouldNotBeAvailable_ifSetToNotVisible() {
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus())
+ .isNotEqualTo(BasePreferenceController.AVAILABLE);
mController.displayPreference(mScreen);
@@ -79,7 +98,8 @@
@Test
public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus())
+ .isNotEqualTo(BasePreferenceController.AVAILABLE);
mController.displayPreference(mScreen);
@@ -91,6 +111,70 @@
@Test
public void airplaneModePreference_shouldBeAvailable_ifNoLeanbackFeature() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(false);
- assertThat(mController.isAvailable()).isTrue();
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void airplaneModePreference_testSetValue_updatesCorrectly() {
+ // Airplane mode default off
+ Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
+
+ mController.displayPreference(mScreen);
+ mController.onResume();
+
+ assertThat(mPreference.isChecked()).isFalse();
+
+ assertThat(mController.isChecked()).isFalse();
+
+ // Set airplane mode ON by setChecked
+ boolean updated = mController.setChecked(true);
+ assertThat(updated).isTrue();
+
+ // Check return value if set same status.
+ updated = mController.setChecked(true);
+ assertThat(updated).isFalse();
+
+ // UI is updated
+ assertThat(mPreference.isChecked()).isTrue();
+
+ // Settings status changed.
+ int updatedValue = Settings.Global.getInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
+ assertThat(updatedValue).isEqualTo(ON);
+
+ // Set to OFF
+ assertThat(mController.setChecked(false)).isTrue();
+ assertThat(mPreference.isChecked()).isFalse();
+ updatedValue = Settings.Global.getInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
+ assertThat(updatedValue).isEqualTo(OFF);
+ }
+
+ @Test
+ public void airplaneModePreference_testGetValue_correctValueReturned() {
+ // Set airplane mode ON
+ Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, ON);
+
+ mController.displayPreference(mScreen);
+ mController.onResume();
+
+ assertThat(mController.isChecked()).isTrue();
+
+ Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void airplaneModePreference_testPreferenceUI_updatesCorrectly() {
+ // Airplane mode default off
+ Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
+
+ mController.displayPreference(mScreen);
+ mController.onResume();
+
+ assertThat(mPreference.isChecked()).isFalse();
+
+ mController.onAirplaneModeChanged(true);
+
+ assertThat(mPreference.isChecked()).isTrue();
}
}
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/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 58ee969..59eb7ce 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -24,8 +24,10 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.provider.Settings;
@@ -389,6 +391,17 @@
SliceTester.testSettingsUnavailableSlice(mContext, slice, data);
}
+ @Test
+ public void testContentIntent_includesUniqueData() {
+ final SliceData sliceData = getDummyData();
+ final Uri expectedUri = new Uri.Builder().appendPath(sliceData.getKey()).build();
+
+ final Intent intent = SliceBuilderUtils.getContentIntent(mContext, sliceData);
+ final Uri intentData = intent.getData();
+
+ assertThat(intentData).isEqualTo(expectedUri);
+ }
+
private SliceData getDummyData() {
return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH);
}
diff --git a/tests/robotests/src/com/android/settings/testutils/SliceTester.java b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
index ef62d77..905277e 100644
--- a/tests/robotests/src/com/android/settings/testutils/SliceTester.java
+++ b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
@@ -64,7 +64,7 @@
final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
assertThat(primaryPendingIntent).isEqualTo(
- SliceBuilderUtils.getContentIntent(context, sliceData));
+ SliceBuilderUtils.getContentPendingIntent(context, sliceData));
final List<SliceItem> sliceItems = slice.getItems();
assertTitle(sliceItems, sliceData.getTitle());
@@ -97,7 +97,7 @@
// Check primary intent
final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
assertThat(primaryPendingIntent).isEqualTo(
- SliceBuilderUtils.getContentIntent(context, sliceData));
+ SliceBuilderUtils.getContentPendingIntent(context, sliceData));
final List<SliceItem> sliceItems = slice.getItems();
assertTitle(sliceItems, sliceData.getTitle());
@@ -147,7 +147,7 @@
case DISABLED_FOR_USER:
case DISABLED_DEPENDENT_SETTING:
assertThat(primaryPendingIntent).isEqualTo(
- SliceBuilderUtils.getContentIntent(context, sliceData));
+ SliceBuilderUtils.getContentPendingIntent(context, sliceData));
break;
}
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()));
+ }
+}