Merge "Shuffle sound settings UI arrangment" into pi-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8767198..fc49e02 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2639,6 +2639,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.apps"/>
+ <meta-data android:name="com.android.settings.summary"
+ android:resource="@string/summary_empty"/>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ConfigureNotificationSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
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/values/strings.xml b/res/values/strings.xml
index 029f2ad..406251d 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" />
@@ -7649,11 +7647,11 @@
<string name="app_settings_link">Additional settings in the app</string>
<!-- [CHAR LIMIT=45] App notification listing summary, blocked apps -->
- <string name="app_notification_listing_summary_zero">Turned on for all apps</string>
+ <string name="app_notification_listing_summary_zero">On for all apps</string>
<!-- [CHAR LIMIT=45] App notification listing summary, blocked apps -->
<plurals name="app_notification_listing_summary_others">
- <item quantity="one">Turned off for <xliff:g id="count" example="1">%d</xliff:g> app</item>
- <item quantity="other">Turned off for <xliff:g id="count" example="10">%d</xliff:g> apps</item>
+ <item quantity="one">Off for <xliff:g id="count" example="1">%d</xliff:g> app</item>
+ <item quantity="other">Off for <xliff:g id="count" example="10">%d</xliff:g> apps</item>
</plurals>
<!-- [CHAR LIMIT=NONE] Footer listing a count of deleted channels. -->
@@ -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/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/appinfo/AppNotificationPreferenceController.java b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
index 4c1f009..33b44ff 100644
--- a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
@@ -81,11 +81,15 @@
if (appRow == null) {
return "";
}
- if (appRow.banned || appRow.channelCount == appRow.blockedChannelCount) {
- return context.getString(R.string.notifications_disabled);
+ if (appRow.banned) {
+ return context.getText(R.string.notifications_disabled);
+ } else if (appRow.channelCount == 0) {
+ return context.getText(R.string.notifications_enabled);
+ } else if (appRow.channelCount == appRow.blockedChannelCount) {
+ return context.getText(R.string.notifications_disabled);
} else {
if (appRow.blockedChannelCount == 0) {
- return context.getString(R.string.notifications_enabled);
+ return context.getText(R.string.notifications_enabled);
}
return context.getString(R.string.notifications_enabled_with_info,
context.getResources().getQuantityString(R.plurals.notifications_categories_off,
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/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index e8668d1..111b279 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -21,17 +21,20 @@
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
-import android.os.BatteryManager;
+import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Build;
+import android.os.Process;
import android.os.SystemClock;
+import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.util.SparseLongArray;
@@ -43,6 +46,7 @@
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
import com.android.settingslib.utils.PowerUtil;
import java.lang.annotation.Retention;
@@ -531,5 +535,65 @@
return false;
}
+
+ /**
+ * Return {@code true} if we should hide anomaly app represented by {@code uid}
+ */
+ public boolean shouldHideAnomaly(PowerWhitelistBackend powerWhitelistBackend, int uid) {
+ final String[] packageNames = mPackageManager.getPackagesForUid(uid);
+ if (ArrayUtils.isEmpty(packageNames)) {
+ // Don't show it if app has been uninstalled
+ return true;
+ }
+
+ return isSystemUid(uid) || powerWhitelistBackend.isSysWhitelistedExceptIdle(packageNames)
+ || (isSystemApp(mPackageManager, packageNames) && !hasLauncherEntry(packageNames));
+ }
+
+ private boolean isSystemUid(int uid) {
+ final int appUid = UserHandle.getAppId(uid);
+ return appUid >= Process.ROOT_UID && appUid < Process.FIRST_APPLICATION_UID;
+ }
+
+ private boolean isSystemApp(PackageManager packageManager, String[] packageNames) {
+ for (String packageName : packageNames) {
+ try {
+ final ApplicationInfo info = packageManager.getApplicationInfo(packageName,
+ 0 /* flags */);
+ if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ return true;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Package not found: " + packageName, e);
+ }
+ }
+
+ return false;
+ }
+
+ private boolean hasLauncherEntry(String[] packageNames) {
+ final Intent launchIntent = new Intent(Intent.ACTION_MAIN, null);
+ launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ // If we do not specify MATCH_DIRECT_BOOT_AWARE or
+ // MATCH_DIRECT_BOOT_UNAWARE, system will derive and update the flags
+ // according to the user's lock state. When the user is locked,
+ // components
+ // with ComponentInfo#directBootAware == false will be filtered. We should
+ // explicitly include both direct boot aware and unaware components here.
+ final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(launchIntent,
+ PackageManager.MATCH_DISABLED_COMPONENTS
+ | PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
+ | PackageManager.MATCH_SYSTEM_ONLY);
+ for (int i = 0, size = resolveInfos.size(); i < size; i++) {
+ final ResolveInfo resolveInfo = resolveInfos.get(i);
+ if (ArrayUtils.contains(packageNames, resolveInfo.activityInfo.packageName)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 8928efd..661cb53 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -30,6 +30,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Process;
@@ -145,21 +146,24 @@
: Settings.Global.getInt(contentResolver,
Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON;
final String packageName = batteryUtils.getPackageName(uid);
- if (uid != UID_NULL && !isSystemUid(uid)
- && !powerWhitelistBackend.isSysWhitelistedExceptIdle(
- packageManager.getPackagesForUid(uid))) {
- boolean anomalyDetected = true;
- if (anomalyInfo.anomalyType
- == StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE) {
- if (!batteryUtils.isPreOApp(packageName)
- || !batteryUtils.isAppHeavilyUsed(batteryStatsHelper, userManager, uid,
- policy.excessiveBgDrainPercentage)) {
- // Don't report if it is not legacy app or haven't used much battery
- anomalyDetected = false;
- }
- }
- if (anomalyDetected) {
+ final boolean anomalyDetected;
+ if (isExcessiveBackgroundAnomaly(anomalyInfo)) {
+ anomalyDetected = batteryUtils.isPreOApp(packageName)
+ && batteryUtils.isAppHeavilyUsed(batteryStatsHelper, userManager, uid,
+ policy.excessiveBgDrainPercentage);
+ } else {
+ anomalyDetected = true;
+ }
+
+ if (anomalyDetected) {
+ if (batteryUtils.shouldHideAnomaly(powerWhitelistBackend, uid)) {
+ metricsFeatureProvider.action(context,
+ MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
+ packageName,
+ Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT,
+ anomalyInfo.anomalyType));
+ } else {
if (autoFeatureOn && anomalyInfo.autoRestriction) {
// Auto restrict this app
batteryUtils.setForceAppStandby(uid, packageName,
@@ -215,8 +219,8 @@
return UID_NULL;
}
- private boolean isSystemUid(int uid) {
- final int appUid = UserHandle.getAppId(uid);
- return appUid >= Process.ROOT_UID && appUid < Process.FIRST_APPLICATION_UID;
+ private boolean isExcessiveBackgroundAnomaly(AnomalyInfo anomalyInfo) {
+ return anomalyInfo.anomalyType
+ == StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE;
}
}
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/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/network/VpnPreferenceController.java b/src/com/android/settings/network/VpnPreferenceController.java
index c4ecf4f..98cf312 100644
--- a/src/com/android/settings/network/VpnPreferenceController.java
+++ b/src/com/android/settings/network/VpnPreferenceController.java
@@ -159,9 +159,10 @@
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary));
}
- private String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
+ @VisibleForTesting
+ String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
if (cfg.legacy) {
- return mContext.getString(R.string.bluetooth_connected);
+ return mContext.getString(R.string.wifi_display_status_connected);
}
// The package name for an active VPN is stored in the 'user' field of its VpnConfig
final String vpnPackage = cfg.user;
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index c9aa19d..1ca4a4d 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -26,11 +26,13 @@
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
+import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -152,6 +154,54 @@
}
/**
+ * For summary
+ */
+ static class SummaryProvider implements SummaryLoader.SummaryProvider {
+
+ private final Context mContext;
+ private final SummaryLoader mSummaryLoader;
+ private NotificationBackend mBackend;
+
+ public SummaryProvider(Context context, SummaryLoader summaryLoader) {
+ mContext = context;
+ mSummaryLoader = summaryLoader;
+ mBackend = new NotificationBackend();
+ }
+
+ @VisibleForTesting
+ protected void setBackend(NotificationBackend backend) {
+ mBackend = backend;
+ }
+
+ @Override
+ public void setListening(boolean listening) {
+ if (!listening) {
+ return;
+ }
+ int blockedAppCount = mBackend.getBlockedAppCount();
+ if (blockedAppCount == 0) {
+ mSummaryLoader.setSummary(this,
+ mContext.getText(R.string.app_notification_listing_summary_zero));
+ } else {
+ mSummaryLoader.setSummary(this,
+ mContext.getResources().getQuantityString(
+ R.plurals.app_notification_listing_summary_others,
+ blockedAppCount, blockedAppCount));
+ }
+ }
+ }
+
+ public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
+ new SummaryLoader.SummaryProviderFactory() {
+ @Override
+ public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
+ SummaryLoader summaryLoader) {
+ return new ConfigureNotificationSettings.SummaryProvider(
+ activity, summaryLoader);
+ }
+ };
+
+ /**
* For Search.
*/
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 62c8388..5e8ef19 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -250,6 +250,15 @@
}
}
+ public int getBlockedAppCount() {
+ try {
+ return sINM.getBlockedAppCount(UserHandle.myUserId());
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return 0;
+ }
+ }
+
static class Row {
public String section;
}
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/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
index a453f78..88526dc 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
@@ -150,4 +150,13 @@
appRow.channelCount = 10;
assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
}
+
+ @Test
+ public void getNotificationSummary_noChannels() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = false;
+ appRow.blockedChannelCount = 0;
+ appRow.channelCount = 0;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
+ }
}
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/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index e05ff52..772bb8d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -37,8 +37,10 @@
import android.app.AppOpsManager;
import android.content.Context;
+import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
import android.os.Build;
import android.os.Bundle;
@@ -53,6 +55,7 @@
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
import org.junit.Before;
import org.junit.Test;
@@ -81,7 +84,7 @@
private static final long TIME_SINCE_LAST_FULL_CHARGE_US =
TIME_SINCE_LAST_FULL_CHARGE_MS * 1000;
- private static final int UID = 123;
+ private static final int UID = 12345;
private static final long TIME_EXPECTED_FOREGROUND = 1500;
private static final long TIME_EXPECTED_BACKGROUND = 6000;
private static final long TIME_EXPECTED_ALL = 7500;
@@ -141,6 +144,8 @@
private ApplicationInfo mHighApplicationInfo;
@Mock
private ApplicationInfo mLowApplicationInfo;
+ @Mock
+ private PowerWhitelistBackend mPowerWhitelistBackend;
private BatteryUtils mBatteryUtils;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mProvider;
@@ -166,9 +171,9 @@
when(mBatteryStatsHelper.getStats().computeBatteryRealtime(anyLong(), anyInt())).thenReturn(
TIME_SINCE_LAST_FULL_CHARGE_US);
- when(mPackageManager.getApplicationInfo(HIGH_SDK_PACKAGE, PackageManager.GET_META_DATA))
+ when(mPackageManager.getApplicationInfo(eq(HIGH_SDK_PACKAGE), anyInt()))
.thenReturn(mHighApplicationInfo);
- when(mPackageManager.getApplicationInfo(LOW_SDK_PACKAGE, PackageManager.GET_META_DATA))
+ when(mPackageManager.getApplicationInfo(eq(LOW_SDK_PACKAGE), anyInt()))
.thenReturn(mLowApplicationInfo);
mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
@@ -570,4 +575,42 @@
assertThat(mBatteryUtils.isAppHeavilyUsed(mBatteryStatsHelper, mUserManager, UID,
DISCHARGE_AMOUNT /* threshold */ )).isFalse();
}
+
+ @Test
+ public void testShouldHideAnomaly_systemAppWithLauncher_returnTrue() {
+ final List<ResolveInfo> resolveInfos = new ArrayList<>();
+ final ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.activityInfo = new ActivityInfo();
+ resolveInfo.activityInfo.packageName = HIGH_SDK_PACKAGE;
+
+ doReturn(resolveInfos).when(mPackageManager).queryIntentActivities(any(), anyInt());
+ doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
+ mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+
+ assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID)).isTrue();
+ }
+
+ @Test
+ public void testShouldHideAnomaly_systemAppWithoutLauncher_returnTrue() {
+ doReturn(new ArrayList<>()).when(mPackageManager).queryIntentActivities(any(), anyInt());
+ doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
+ mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+
+ assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID)).isTrue();
+ }
+
+ @Test
+ public void testShouldHideAnomaly_systemUid_returnTrue() {
+ final int systemUid = Process.ROOT_UID;
+ doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(systemUid);
+
+ assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, systemUid)).isTrue();
+ }
+
+ @Test
+ public void testShouldHideAnomaly_normalApp_returnFalse() {
+ doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
+
+ assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID)).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
index 49567f6..16d7c3f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
@@ -142,6 +142,31 @@
}
@Test
+ public void testSaveAnomalyToDatabase_systemApp_doNotSaveButLog() {
+ final ArrayList<String> cookies = new ArrayList<>();
+ cookies.add(SUBSCRIBER_COOKIES_AUTO_RESTRICTION);
+ mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
+ doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
+ doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
+ doReturn(Process.FIRST_APPLICATION_UID).when(
+ mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
+ doReturn(true).when(mBatteryUtils).shouldHideAnomaly(any(), anyInt());
+
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
+ mPowerWhitelistBackend, mContext.getContentResolver(),
+ mFeatureFactory.powerUsageFeatureProvider,
+ mFeatureFactory.metricsFeatureProvider, mBundle);
+
+ verify(mBatteryDatabaseManager, never()).insertAnomaly(anyInt(), anyString(), anyInt(),
+ anyInt(), anyLong());
+ verify(mFeatureFactory.metricsFeatureProvider).action(mContext,
+ MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
+ SYSTEM_PACKAGE,
+ Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, ANOMALY_TYPE));
+ }
+
+ @Test
public void testSaveAnomalyToDatabase_systemUid_doNotSave() {
doReturn(Process.SYSTEM_UID).when(
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
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/network/VpnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
index c4bd245..2ef3e9b 100644
--- a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.network;
+import static com.google.common.truth.Truth.assertThat;
import static android.arch.lifecycle.Lifecycle.Event.ON_PAUSE;
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
import static org.mockito.Matchers.any;
@@ -31,9 +32,11 @@
import android.net.IConnectivityManager;
import android.net.NetworkRequest;
import android.os.IBinder;
+import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.net.VpnConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -42,6 +45,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowServiceManager;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -99,4 +103,16 @@
verify(mConnectivityManager).unregisterNetworkCallback(
any(ConnectivityManager.NetworkCallback.class));
}
+
+ @Test
+ public void getNameForVpnConfig_legacyVPNConfig_shouldSetSummaryToConnected() {
+ final VpnConfig config = new VpnConfig();
+ config.legacy = true;
+ final VpnPreferenceController controller =
+ new VpnPreferenceController(RuntimeEnvironment.application);
+
+ final String summary = controller.getNameForVpnConfig(config, UserHandle.CURRENT);
+
+ assertThat(summary).isEqualTo("Connected");
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
index 51f5a6a..d3463ce 100644
--- a/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
@@ -17,17 +17,35 @@
package com.android.settings.notification;
import static com.android.settings.notification.ConfigureNotificationSettings.KEY_LOCKSCREEN;
-import static com.android.settings.notification.ConfigureNotificationSettings.KEY_LOCKSCREEN_WORK_PROFILE;
-import static com.android.settings.notification.ConfigureNotificationSettings.KEY_LOCKSCREEN_WORK_PROFILE_HEADER;
+import static com.android.settings.notification.ConfigureNotificationSettings
+ .KEY_LOCKSCREEN_WORK_PROFILE;
+import static com.android.settings.notification.ConfigureNotificationSettings
+ .KEY_LOCKSCREEN_WORK_PROFILE_HEADER;
import static com.android.settings.notification.ConfigureNotificationSettings.KEY_SWIPE_DOWN;
+import static com.android.settings.notification.ConfigureNotificationSettings
+ .SUMMARY_PROVIDER_FACTORY;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Activity;
+
+import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.notification.ConfigureNotificationSettings.SummaryProvider;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowUtils;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -36,6 +54,13 @@
@RunWith(SettingsRobolectricTestRunner.class)
public class ConfigureNotificationSettingsTest {
+ private Activity mActivity;
+
+ @Before
+ public void setUp() {
+ mActivity = spy(Robolectric.buildActivity(Activity.class).get());
+ }
+
@Test
@Config(shadows = {
ShadowUtils.class,
@@ -49,4 +74,39 @@
KEY_SWIPE_DOWN, KEY_LOCKSCREEN, KEY_LOCKSCREEN_WORK_PROFILE,
KEY_LOCKSCREEN_WORK_PROFILE_HEADER);
}
+
+ @Test
+ public void getSummary_noneBlocked() {
+ SummaryLoader loader = mock(SummaryLoader.class);
+ NotificationBackend backend = mock(NotificationBackend.class);
+ when(backend.getBlockedAppCount()).thenReturn(0);
+ SummaryProvider provider =
+ (SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
+ provider.setBackend(backend);
+
+ provider.setListening(true);
+
+ ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+ verify(loader).setSummary(any(), captor.capture());
+
+ assertThat(captor.getValue().toString()).contains("On");
+ }
+
+ @Test
+ public void getSummary_someBlocked() {
+ SummaryLoader loader = mock(SummaryLoader.class);
+ NotificationBackend backend = mock(NotificationBackend.class);
+ when(backend.getBlockedAppCount()).thenReturn(5);
+ SummaryProvider provider =
+ (SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
+ provider.setBackend(backend);
+
+ provider.setListening(true);
+
+ ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+ verify(loader).setSummary(any(), captor.capture());
+
+ assertThat(captor.getValue().toString()).contains("Off");
+ assertThat(captor.getValue().toString()).contains("5");
+ }
}
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;
}