Only show Bubbles link for messaging apps
Apps that have sent at least one valid conversation Test: manual, atest Fixes: 156033178 Change-Id: If4fff6810f2e390ba0ad0f7587b8d8c2d5819c93
This commit is contained in:
@@ -37,12 +37,12 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
settings:allowDividerAbove="false"
|
settings:allowDividerAbove="false"
|
||||||
settings:allowDividerBelow="false">
|
settings:allowDividerBelow="false">
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="invalid_conversation_switch"
|
|
||||||
android:title="@string/conversation_section_switch_title" />
|
|
||||||
<Preference
|
|
||||||
android:key="invalid_conversation_info"/>
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="invalid_conversation_switch"
|
||||||
|
android:title="@string/conversation_section_switch_title" />
|
||||||
|
<Preference
|
||||||
|
android:key="invalid_conversation_info"/>
|
||||||
|
|
||||||
<!--Bubbles -->
|
<!--Bubbles -->
|
||||||
<Preference
|
<Preference
|
||||||
|
@@ -72,9 +72,20 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
if (!super.isAvailable()) {
|
// copy rather than inherit super's isAvailable because apps can link to this page
|
||||||
|
// as part of onboarding, before they send a valid conversation notification
|
||||||
|
if (mAppRow == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mAppRow.banned) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mChannel != null) {
|
||||||
|
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|
||||||
|
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) {
|
if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -268,6 +268,15 @@ public class NotificationBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasSentValidMsg(String pkg, int uid) {
|
||||||
|
try {
|
||||||
|
return sINM.hasSentValidMsg(pkg, uid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Error calling NoMan", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInInvalidMsgState(String pkg, int uid) {
|
public boolean isInInvalidMsgState(String pkg, int uid) {
|
||||||
try {
|
try {
|
||||||
return sINM.isInInvalidMsgState(pkg, uid);
|
return sINM.isInInvalidMsgState(pkg, uid);
|
||||||
|
@@ -46,7 +46,6 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
|||||||
|
|
||||||
protected List<ConversationChannelWrapper> mConversations = new ArrayList<>();
|
protected List<ConversationChannelWrapper> mConversations = new ArrayList<>();
|
||||||
protected PreferenceCategory mPreference;
|
protected PreferenceCategory mPreference;
|
||||||
private boolean mIsInInvalidMsgState;
|
|
||||||
|
|
||||||
public AppConversationListPreferenceController(Context context, NotificationBackend backend) {
|
public AppConversationListPreferenceController(Context context, NotificationBackend backend) {
|
||||||
super(context, backend);
|
super(context, backend);
|
||||||
@@ -71,7 +70,8 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid) || mBackend.isInInvalidMsgState(
|
||||||
|
mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,7 +88,6 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
|||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... unused) {
|
protected Void doInBackground(Void... unused) {
|
||||||
mIsInInvalidMsgState = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
|
||||||
ParceledListSlice<ConversationChannelWrapper> list =
|
ParceledListSlice<ConversationChannelWrapper> list =
|
||||||
mBackend.getConversations(mAppRow.pkg, mAppRow.uid);
|
mBackend.getConversations(mAppRow.pkg, mAppRow.uid);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
@@ -122,7 +121,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mIsInInvalidMsgState && !mConversations.isEmpty()) {
|
if (!mConversations.isEmpty()) {
|
||||||
// TODO: if preference has children, compare with newly loaded list
|
// TODO: if preference has children, compare with newly loaded list
|
||||||
mPreference.removeAll();
|
mPreference.removeAll();
|
||||||
mPreference.setTitle(getTitleResId());
|
mPreference.setTitle(getTitleResId());
|
||||||
|
@@ -49,7 +49,7 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
|
|||||||
if (!super.isAvailable()) {
|
if (!super.isAvailable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mAppRow == null && mChannel == null) {
|
if (mAppRow == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
@@ -62,7 +62,7 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
|
|||||||
return mAppRow != null;
|
return mAppRow != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isGloballyEnabled();
|
return isGloballyEnabled() && mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -31,6 +31,8 @@ import static junit.framework.TestCase.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -59,6 +61,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationBackend mBackend;
|
private NotificationBackend mBackend;
|
||||||
|
NotificationBackend.AppRow mAppRow;
|
||||||
|
|
||||||
private BubbleSummaryPreferenceController mController;
|
private BubbleSummaryPreferenceController mController;
|
||||||
|
|
||||||
@@ -67,6 +70,10 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(true);
|
||||||
|
mAppRow = new NotificationBackend.AppRow();
|
||||||
|
mAppRow.pkg = "pkg";
|
||||||
|
mAppRow.uid = 0;
|
||||||
mController = spy(new BubbleSummaryPreferenceController(mContext, mBackend));
|
mController = spy(new BubbleSummaryPreferenceController(mContext, mBackend));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,20 +92,27 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_nullChannelNOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
public void isAvailable_NOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
mController.onResume(mAppRow, null, null, null, null, null);
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_nullChannelNOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() {
|
||||||
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
mController.onResume(mAppRow, null, null, null, null, null);
|
||||||
|
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_NOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||||
SYSTEM_WIDE_OFF);
|
SYSTEM_WIDE_OFF);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
mController.onResume(mAppRow, null, null, null, null, null);
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -107,10 +121,9 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
public void isAvailable_nonNullChannelNOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
public void isAvailable_nonNullChannelNOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||||
SYSTEM_WIDE_OFF);
|
SYSTEM_WIDE_OFF);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(mAppRow, channel, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -118,20 +131,18 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_defaultChannelNOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
public void isAvailable_defaultChannelNOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(mAppRow, channel, null, null, null, null);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_setsIntent() {
|
public void updateState_setsIntent() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
mController.onResume(mAppRow, null, null, null, null, null);
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
|
||||||
|
|
||||||
Preference pref = new Preference(mContext);
|
Preference pref = new Preference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
Reference in New Issue
Block a user