Move background data notif to data saver status icon
Bug: 26796370
Change-Id: Ibf53c3affa63100b603e362b58ca6d2958791321
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 3a185d6..54f9093 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -29,6 +29,7 @@
<string-array name="config_statusBarIcons">
<item><xliff:g id="id">@string/status_bar_rotate</xliff:g></item>
<item><xliff:g id="id">@string/status_bar_headset</xliff:g></item>
+ <item><xliff:g id="id">@string/status_bar_data_saver</xliff:g></item>
<item><xliff:g id="id">@string/status_bar_managed_profile</xliff:g></item>
<item><xliff:g id="id">@string/status_bar_ime</xliff:g></item>
<item><xliff:g id="id">@string/status_bar_sync_failing</xliff:g></item>
@@ -56,6 +57,7 @@
<string translatable="false" name="status_bar_rotate">rotate</string>
<string translatable="false" name="status_bar_headset">headset</string>
+ <string translatable="false" name="status_bar_data_saver">data_saver</string>
<string translatable="false" name="status_bar_managed_profile">managed_profile</string>
<string translatable="false" name="status_bar_ime">ime</string>
<string translatable="false" name="status_bar_sync_failing">sync_failing</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 746e7fd..9950884 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2460,6 +2460,7 @@
<java-symbol type="string" name="status_bar_rotate" />
<java-symbol type="string" name="status_bar_headset" />
+ <java-symbol type="string" name="status_bar_data_saver" />
<java-symbol type="string" name="status_bar_managed_profile" />
<java-symbol type="string" name="status_bar_ime" />
<java-symbol type="string" name="status_bar_sync_failing" />
diff --git a/packages/SystemUI/res/drawable/stat_sys_data_saver.xml b/packages/SystemUI/res/drawable/stat_sys_data_saver.xml
new file mode 100644
index 0000000..a45f9a2
--- /dev/null
+++ b/packages/SystemUI/res/drawable/stat_sys_data_saver.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright (C) 2016 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.
+-->
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ android:insetLeft="2.5dp"
+ android:insetRight="2.5dp">
+ <vector
+ android:width="17.0dp"
+ android:height="17.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="
+ M9.0,16.0l2.0,0.0L11.0,8.0L9.0,8.0l0.0,8.0z
+ m3.0,-14.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0z
+ m0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0z
+ m1.0,-4.0l2.0,0.0l0.0,-8.0l-2.0,0.0l0.0,8.0z"/>
+ </vector>
+</inset>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DataSaverTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DataSaverTile.java
index a1789a5..fa235d3 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DataSaverTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DataSaverTile.java
@@ -61,8 +61,8 @@
state.value = arg instanceof Boolean ? (Boolean) arg
: mDataSaverController.isDataSaverEnabled();
state.label = mContext.getString(R.string.data_saver);
- state.contentDescription = mContext.getString(state.value ?
- R.string.accessibility_data_saver_on : R.string.accessibility_data_saver_off);
+ state.contentDescription = mContext.getString(state.value
+ ? R.string.accessibility_data_saver_on : R.string.accessibility_data_saver_off);
state.icon = ResourceIcon.get(state.value ? R.drawable.ic_data_saver
: R.drawable.ic_data_saver_off);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 1089852..d60ea20 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -646,7 +646,7 @@
// Lastly, call to the icon policy to install/update all the icons.
mIconPolicy = new PhoneStatusBarPolicy(mContext, mIconController, mCastController,
mHotspotController, mUserInfoController, mBluetoothController,
- mRotationLockController);
+ mRotationLockController, mNetworkController.getDataSaverController());
mIconPolicy.setCurrentUserSetup(mUserSetup);
mSettingsObserver.onChange(false); // set up
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
index 6550c87..c883cc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -44,6 +44,7 @@
import com.android.systemui.statusbar.policy.BluetoothController.Callback;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.CastController.CastDevice;
+import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.RotationLockController;
import com.android.systemui.statusbar.policy.UserInfoController;
@@ -53,7 +54,7 @@
* bar at boot time. It goes through the normal API for icons, even though it probably
* strictly doesn't need to.
*/
-public class PhoneStatusBarPolicy implements Callback, RotationLockController.RotationLockControllerCallback {
+public class PhoneStatusBarPolicy implements Callback, RotationLockController.RotationLockControllerCallback, DataSaverController.Listener {
private static final String TAG = "PhoneStatusBarPolicy";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -67,6 +68,7 @@
private final String mSlotManagedProfile;
private final String mSlotRotate;
private final String mSlotHeadset;
+ private final String mSlotDataSaver;
private final Context mContext;
private final Handler mHandler = new Handler();
@@ -77,6 +79,7 @@
private final UserManager mUserManager;
private final StatusBarIconController mIconController;
private final RotationLockController mRotationLockController;
+ private final DataSaverController mDataSaver;
// Assume it's all good unless we hear otherwise. We don't always seem
// to get broadcasts that it *is* there.
@@ -97,7 +100,8 @@
public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
CastController cast, HotspotController hotspot, UserInfoController userInfoController,
- BluetoothController bluetooth, RotationLockController rotationLockController) {
+ BluetoothController bluetooth, RotationLockController rotationLockController,
+ DataSaverController dataSaver) {
mContext = context;
mIconController = iconController;
mCast = cast;
@@ -108,6 +112,7 @@
mUserInfoController = userInfoController;
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mRotationLockController = rotationLockController;
+ mDataSaver = dataSaver;
mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast);
mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot);
@@ -120,6 +125,7 @@
com.android.internal.R.string.status_bar_managed_profile);
mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate);
mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
+ mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver);
mRotationLockController.addRotationLockControllerCallback(this);
@@ -176,6 +182,12 @@
mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status,
mContext.getString(R.string.accessibility_managed_profile));
mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible);
+
+ // data saver
+ mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver,
+ context.getString(R.string.accessibility_data_saver_on));
+ mIconController.setIconVisibility(mSlotDataSaver, false);
+ mDataSaver.addListener(this);
}
public void setZenMode(int zen) {
@@ -477,6 +489,11 @@
}
}
+ @Override
+ public void onDataSaverChanged(boolean isDataSaving) {
+ mIconController.setIconVisibility(mSlotDataSaver, isDataSaving);
+ }
+
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DataSaverController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DataSaverController.java
index 186e8b5..6dd196b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DataSaverController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DataSaverController.java
@@ -60,6 +60,10 @@
public void setDataSaverEnabled(boolean enabled) {
mPolicyManager.setRestrictBackground(enabled);
+ try {
+ mPolicyListener.onRestrictBackgroundChanged(enabled);
+ } catch (RemoteException e) {
+ }
}
private final INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 3421433..fc40f9f 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -240,8 +240,6 @@
private static final String ATTR_APP_ID = "appId";
private static final String ATTR_POLICY = "policy";
- private static final String TAG_ALLOW_BACKGROUND = TAG + ":allowBackground";
-
private static final String ACTION_ALLOW_BACKGROUND =
"com.android.server.net.action.ALLOW_BACKGROUND";
private static final String ACTION_SNOOZE_WARNING =
@@ -844,11 +842,6 @@
}
}
- // ongoing notification when restricting background data
- if (mRestrictBackground) {
- enqueueRestrictedNotification(TAG_ALLOW_BACKGROUND);
- }
-
// cancel stale notifications that we didn't renew above
for (int i = beforeNotifs.size()-1; i >= 0; i--) {
final String tag = beforeNotifs.valueAt(i);
@@ -1026,42 +1019,6 @@
}
}
- /**
- * Show ongoing notification to reflect that {@link #mRestrictBackground}
- * has been enabled.
- */
- private void enqueueRestrictedNotification(String tag) {
- final Resources res = mContext.getResources();
- final Notification.Builder builder = new Notification.Builder(mContext);
-
- final CharSequence title = res.getText(R.string.data_usage_restricted_title);
- final CharSequence body = res.getString(R.string.data_usage_restricted_body);
-
- builder.setOnlyAlertOnce(true);
- builder.setOngoing(true);
- builder.setSmallIcon(R.drawable.stat_notify_error);
- builder.setTicker(title);
- builder.setContentTitle(title);
- builder.setContentText(body);
- builder.setColor(mContext.getColor(
- com.android.internal.R.color.system_notification_accent_color));
-
- final Intent intent = buildAllowBackgroundDataIntent();
- builder.setContentIntent(
- PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
-
- // TODO: move to NotificationManager once we can mock it
- try {
- final String packageName = mContext.getPackageName();
- final int[] idReceived = new int[1];
- mNotifManager.enqueueNotificationWithTag(packageName, packageName, tag,
- 0x0, builder.getNotification(), idReceived, UserHandle.USER_ALL);
- mActiveNotifs.add(tag);
- } catch (RemoteException e) {
- // ignored; service lives in system_server
- }
- }
-
private void cancelNotification(String tag) {
// TODO: move to NotificationManager once we can mock it
try {