Don't show bubble settings when framework doesn't support it

Some devices don't support bubbles by configuring config_supportsBubble
value. When the value is set false, it doesn't make sense to show bubble
related preferences.

This CL disables showing bubble preferences when device doesn't support
it.

Bug: 274711609
Test: Set config_supportsBubble false, and check UI.
Test: m -j80 RunSettingsRoboTests ROBOTEST_FILTER="Bubble"
Change-Id: I670ad2a9e243819ea014e5e1ddb9d62ad76d2168
This commit is contained in:
Hiroki Sato
2023-05-02 12:13:50 +09:00
parent 2095c5c5e9
commit e44848cdce
9 changed files with 88 additions and 70 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2023 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
/**
* Helper class for configuring notification bubbles.
*/
public class BubbleHelper {
/**
* {@link Settings.Secure.NOTIFICATION_BUBBLES} is enabled.
*/
public static final int SYSTEM_WIDE_ON = 1;
/**
* {@link Settings.Secure.NOTIFICATION_BUBBLES} is disabled.
*/
public static final int SYSTEM_WIDE_OFF = 0;
/**
* Returns true if the device supports bubbles.
*/
public static boolean isSupportedByDevice(Context context) {
ActivityManager am = context.getSystemService(ActivityManager.class);
if (am.isLowRamDevice()) {
return false;
}
if (!Resources.getSystem().getBoolean(com.android.internal.R.bool.config_supportsBubble)) {
return false;
}
return true;
}
/**
* Returns true if the device supports bubbles and the global settings is enabled.
*/
public static boolean isEnabledSystemWide(Context context) {
if (!isSupportedByDevice(context)) {
return false;
}
return Settings.Secure.getInt(context.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_ON) == SYSTEM_WIDE_ON;
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
@@ -26,7 +25,6 @@ import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -44,11 +42,6 @@ public class BubbleNotificationPreferenceController extends
private static final String TAG = "BubbleNotifPrefContr"; private static final String TAG = "BubbleNotifPrefContr";
@VisibleForTesting
static final int ON = 1;
@VisibleForTesting
static final int OFF = 0;
private SettingObserver mSettingObserver; private SettingObserver mSettingObserver;
public BubbleNotificationPreferenceController(Context context, String preferenceKey) { public BubbleNotificationPreferenceController(Context context, String preferenceKey) {
@@ -79,8 +72,7 @@ public class BubbleNotificationPreferenceController extends
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
ActivityManager am = mContext.getSystemService(ActivityManager.class); return BubbleHelper.isSupportedByDevice(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return am.isLowRamDevice() ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
} }
@Override @Override
@@ -96,14 +88,14 @@ public class BubbleNotificationPreferenceController extends
@Override @Override
public boolean isChecked() { public boolean isChecked() {
return Settings.Global.getInt(mContext.getContentResolver(), return Settings.Global.getInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
NOTIFICATION_BUBBLES, ON) == ON; BubbleHelper.SYSTEM_WIDE_ON) == BubbleHelper.SYSTEM_WIDE_ON;
} }
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
NOTIFICATION_BUBBLES, isChecked ? ON : OFF); isChecked ? BubbleHelper.SYSTEM_WIDE_ON : BubbleHelper.SYSTEM_WIDE_OFF);
return true; return true;
} }

View File

@@ -18,12 +18,9 @@ package com.android.settings.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -32,9 +29,6 @@ import com.android.settings.core.BasePreferenceController;
*/ */
public class BubbleSummaryNotificationPreferenceController extends BasePreferenceController { public class BubbleSummaryNotificationPreferenceController extends BasePreferenceController {
@VisibleForTesting
static final int ON = 1;
public BubbleSummaryNotificationPreferenceController(Context context, String preferenceKey) { public BubbleSummaryNotificationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }
@@ -49,12 +43,11 @@ public class BubbleSummaryNotificationPreferenceController extends BasePreferenc
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
ActivityManager am = mContext.getSystemService(ActivityManager.class); return BubbleHelper.isSupportedByDevice(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return am.isLowRamDevice() ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
} }
private boolean areBubblesEnabled() { private boolean areBubblesEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(), return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON; NOTIFICATION_BUBBLES, BubbleHelper.SYSTEM_WIDE_ON) == BubbleHelper.SYSTEM_WIDE_ON;
} }
} }

View File

@@ -16,20 +16,17 @@
package com.android.settings.notification.app; package com.android.settings.notification.app;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.notification.BubbleHelper;
public class BubbleCategoryPreferenceController extends NotificationPreferenceController { public class BubbleCategoryPreferenceController extends NotificationPreferenceController {
private static final String KEY = "bubbles"; private static final String KEY = "bubbles";
@VisibleForTesting
static final int ON = 1;
public BubbleCategoryPreferenceController(Context context) { public BubbleCategoryPreferenceController(Context context) {
super(context, null); super(context, null);
@@ -40,7 +37,7 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
if (!super.isAvailable()) { if (!super.isAvailable()) {
return false; return false;
} }
return areBubblesEnabled(); return BubbleHelper.isEnabledSystemWide(mContext);
} }
@Override @Override
@@ -64,10 +61,4 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
preference.setIntent(intent); preference.setIntent(intent);
} }
} }
private boolean areBubblesEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
} }

View File

@@ -16,20 +16,17 @@
package com.android.settings.notification.app; package com.android.settings.notification.app;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.notification.BubbleHelper;
public class BubbleLinkPreferenceController extends NotificationPreferenceController { public class BubbleLinkPreferenceController extends NotificationPreferenceController {
private static final String KEY = "notification_bubbles"; private static final String KEY = "notification_bubbles";
@VisibleForTesting
static final int ON = 1;
public BubbleLinkPreferenceController(Context context) { public BubbleLinkPreferenceController(Context context) {
super(context, null); super(context, null);
@@ -40,7 +37,7 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
if (!super.isAvailable()) { if (!super.isAvailable()) {
return false; return false;
} }
return areBubblesEnabled(); return BubbleHelper.isEnabledSystemWide(mContext);
} }
@Override @Override
@@ -64,10 +61,4 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
preference.setIntent(intent); preference.setIntent(intent);
} }
} }
private boolean areBubblesEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
}
} }

View File

@@ -20,16 +20,15 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.notification.BubbleHelper;
import com.android.settings.notification.NotificationBackend; import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.RestrictedSwitchPreference;
@@ -42,10 +41,6 @@ public class BubblePreferenceController extends NotificationPreferenceController
private static final String TAG = "BubblePrefContr"; private static final String TAG = "BubblePrefContr";
private static final String KEY = "bubble_pref"; private static final String KEY = "bubble_pref";
@VisibleForTesting
static final int SYSTEM_WIDE_ON = 1;
@VisibleForTesting
static final int SYSTEM_WIDE_OFF = 0;
private FragmentManager mFragmentManager; private FragmentManager mFragmentManager;
private boolean mIsAppPage; private boolean mIsAppPage;
@@ -146,9 +141,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
} }
private boolean isEnabled() { private boolean isEnabled() {
ActivityManager am = mContext.getSystemService(ActivityManager.class); return BubbleHelper.isEnabledSystemWide(mContext);
return !am.isLowRamDevice() && Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF) == SYSTEM_WIDE_ON;
} }
/** /**
@@ -163,7 +156,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
// correct preference state // correct preference state
Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.putInt(context.getContentResolver(),
NOTIFICATION_BUBBLES, NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF); BubbleHelper.SYSTEM_WIDE_OFF);
} }
/** /**
@@ -176,6 +169,6 @@ public class BubblePreferenceController extends NotificationPreferenceController
// correct preference state // correct preference state
Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.putInt(context.getContentResolver(),
NOTIFICATION_BUBBLES, NOTIFICATION_BUBBLES,
SYSTEM_WIDE_ON); BubbleHelper.SYSTEM_WIDE_ON);
} }
} }

View File

@@ -18,18 +18,16 @@ package com.android.settings.notification.app;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.notification.BubbleHelper;
import com.android.settings.notification.NotificationBackend; import com.android.settings.notification.NotificationBackend;
/** /**
@@ -38,9 +36,6 @@ import com.android.settings.notification.NotificationBackend;
public class BubbleSummaryPreferenceController extends NotificationPreferenceController { public class BubbleSummaryPreferenceController extends NotificationPreferenceController {
private static final String KEY = "bubble_pref_link"; private static final String KEY = "bubble_pref_link";
@VisibleForTesting
static final int ON = 1;
public BubbleSummaryPreferenceController(Context context, NotificationBackend backend) { public BubbleSummaryPreferenceController(Context context, NotificationBackend backend) {
super(context, backend); super(context, backend);
} }
@@ -105,8 +100,6 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
} }
private boolean isGloballyEnabled() { private boolean isGloballyEnabled() {
ActivityManager am = mContext.getSystemService(ActivityManager.class); return BubbleHelper.isEnabledSystemWide(mContext);
return !am.isLowRamDevice() && Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON) == ON;
} }
} }

View File

@@ -25,8 +25,8 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF; import static com.android.settings.notification.BubbleHelper.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON; import static com.android.settings.notification.BubbleHelper.SYSTEM_WIDE_ON;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;

View File

@@ -23,8 +23,8 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF; import static com.android.settings.notification.BubbleHelper.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON; import static com.android.settings.notification.BubbleHelper.SYSTEM_WIDE_ON;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;