Change bubble settings to use Secure rather than Global

Test: make -j40 RunSettingsRoboTests ROBOTEST_FILTER="Bubble"
Bug: 173408780
Change-Id: I53fcd59c22c219551bd2eb6f0251acb5a03690ea
This commit is contained in:
Mady Mellor
2021-02-01 11:31:21 -08:00
parent 3b77220873
commit 24adce034d
11 changed files with 82 additions and 79 deletions

View File

@@ -17,10 +17,10 @@
package com.android.settings.notification.app;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.NotificationChannel;
import android.content.Context;
import android.provider.Settings;
@@ -72,7 +72,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
if (!super.isAvailable()) {
return false;
}
if (!mIsAppPage && !isGloballyEnabled()) {
if (!mIsAppPage && !isEnabled()) {
return false;
}
if (mChannel != null) {
@@ -101,7 +101,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
BubblePreference pref = (BubblePreference) preference;
pref.setDisabledByAdmin(mAdmin);
pref.setSelectedVisibility(!mHasSentInvalidMsg || mNumConversations > 0);
if (!isGloballyEnabled()) {
if (!isEnabled()) {
pref.setSelectedPreference(BUBBLE_PREFERENCE_NONE);
} else {
pref.setSelectedPreference(backEndPref);
@@ -110,7 +110,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
// We're on the channel specific notification page which displays a toggle.
RestrictedSwitchPreference switchpref = (RestrictedSwitchPreference) preference;
switchpref.setDisabledByAdmin(mAdmin);
switchpref.setChecked(mChannel.canBubble() && isGloballyEnabled());
switchpref.setChecked(mChannel.canBubble() && isEnabled());
}
}
@@ -125,7 +125,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
BubblePreference pref = (BubblePreference) preference;
if (mAppRow != null && mFragmentManager != null) {
final int value = (int) newValue;
if (!isGloballyEnabled()
if (!isEnabled()
&& pref.getSelectedPreference() == BUBBLE_PREFERENCE_NONE) {
// if the global setting is off, toggling app level permission requires extra
// confirmation
@@ -145,9 +145,9 @@ public class BubblePreferenceController extends NotificationPreferenceController
return true;
}
private boolean isGloballyEnabled() {
private boolean isEnabled() {
ActivityManager am = mContext.getSystemService(ActivityManager.class);
return !am.isLowRamDevice() && Settings.Global.getInt(mContext.getContentResolver(),
return !am.isLowRamDevice() && Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF) == SYSTEM_WIDE_ON;
}
@@ -155,25 +155,27 @@ public class BubblePreferenceController extends NotificationPreferenceController
* Used in app level prompt that confirms the user is ok with turning on bubbles
* globally. If they aren't, undo that.
*/
public static void revertBubblesApproval(Context mContext, String pkg, int uid) {
public static void revertBubblesApproval(Context context, String pkg, int uid) {
NotificationBackend backend = new NotificationBackend();
backend.setAllowBubbles(pkg, uid, BUBBLE_PREFERENCE_NONE);
// changing the global settings will cause the observer on the host page to reload
// correct preference state
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
Settings.Secure.putInt(context.getContentResolver(),
NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
}
/**
* Apply global bubbles approval
*/
public static void applyBubblesApproval(Context mContext, String pkg, int uid, int pref) {
public static void applyBubblesApproval(Context context, String pkg, int uid, int pref) {
NotificationBackend backend = new NotificationBackend();
backend.setAllowBubbles(pkg, uid, pref);
// changing the global settings will cause the observer on the host page to reload
// correct preference state
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
Settings.Secure.putInt(context.getContentResolver(),
NOTIFICATION_BUBBLES,
SYSTEM_WIDE_ON);
}
}