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

@@ -16,7 +16,7 @@
package com.android.settings.notification;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.ContentResolver;
@@ -88,14 +88,14 @@ public class BubbleNotificationPreferenceController extends TogglePreferenceCont
@Override
public boolean isChecked() {
return Settings.Global.getInt(mContext.getContentResolver(),
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, isChecked ? ON : OFF);
return Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
isChecked ? ON : OFF);
}
@Override
@@ -106,7 +106,7 @@ public class BubbleNotificationPreferenceController extends TogglePreferenceCont
class SettingObserver extends ContentObserver {
private final Uri NOTIFICATION_BUBBLES_URI =
Settings.Global.getUriFor(NOTIFICATION_BUBBLES);
Settings.Secure.getUriFor(NOTIFICATION_BUBBLES);
private final Preference mPreference;

View File

@@ -16,7 +16,7 @@
package com.android.settings.notification;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.Context;
@@ -54,7 +54,7 @@ public class BubbleSummaryNotificationPreferenceController extends BasePreferenc
}
private boolean areBubblesEnabled() {
return Settings.Global.getInt(mContext.getContentResolver(),
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
}

View File

@@ -16,7 +16,7 @@
package com.android.settings.notification.app;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.content.Context;
import android.content.Intent;
@@ -67,7 +67,7 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
private boolean areBubblesEnabled() {
return Settings.Global.getInt(mContext.getContentResolver(),
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
}

View File

@@ -16,7 +16,7 @@
package com.android.settings.notification.app;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.content.Context;
import android.content.Intent;
@@ -67,7 +67,7 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
private boolean areBubblesEnabled() {
return Settings.Global.getInt(mContext.getContentResolver(),
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
}

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);
}
}

View File

@@ -18,7 +18,7 @@ package com.android.settings.notification.app;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
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.content.Context;
@@ -106,7 +106,7 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
private boolean isGloballyEnabled() {
ActivityManager am = mContext.getSystemService(ActivityManager.class);
return !am.isLowRamDevice() && Settings.Global.getInt(mContext.getContentResolver(),
return !am.isLowRamDevice() && Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
}

View File

@@ -47,8 +47,8 @@ public class GlobalBubblePermissionObserverMixin extends ContentObserver {
public void onStart() {
mContext.getContentResolver().registerContentObserver(
Settings.Global.getUriFor(
Settings.Global.NOTIFICATION_BUBBLES),
Settings.Secure.getUriFor(
Settings.Secure.NOTIFICATION_BUBBLES),
false /* notifyForDescendants */,
this /* observer */);
}