Merge "Update on reboots, package uninstalls" into sc-dev

This commit is contained in:
Anna Zappone
2021-06-21 12:27:13 +00:00
committed by Android (Google) Code Review
5 changed files with 251 additions and 87 deletions

View File

@@ -494,7 +494,8 @@ public class PeopleSpaceUtils {
* match the data by {@link ContactsContract.ContactsColumns#LOOKUP_KEY} key to ensure proper
* matching across all the Contacts DB tables.
*/
private static List<String> getContactLookupKeysWithBirthdaysToday(Context context) {
@VisibleForTesting
public static List<String> getContactLookupKeysWithBirthdaysToday(Context context) {
List<String> lookupKeysWithBirthdaysToday = new ArrayList<>(1);
String today = new SimpleDateFormat("MM-dd").format(new Date());
String[] projection = new String[]{
@@ -503,14 +504,20 @@ public class PeopleSpaceUtils {
String where =
ContactsContract.Data.MIMETYPE
+ "= ? AND " + ContactsContract.CommonDataKinds.Event.TYPE + "="
+ ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY + " AND substr("
+ ContactsContract.CommonDataKinds.Event.START_DATE + ",6) = ?";
+ ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY + " AND (substr("
// Birthdays stored with years will match this format
+ ContactsContract.CommonDataKinds.Event.START_DATE + ",6) = ? OR substr("
// Birthdays stored without years will match this format
+ ContactsContract.CommonDataKinds.Event.START_DATE + ",3) = ? )";
String[] selection =
new String[]{ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE, today};
new String[]{ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE, today,
today};
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
projection, where, selection, null);
cursor = context
.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI,
projection, where, selection, null);
while (cursor != null && cursor.moveToNext()) {
String lookupKey = cursor.getString(
cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.LOOKUP_KEY));

View File

@@ -265,7 +265,7 @@ public class PeopleTileViewHelper {
private RemoteViews createSuppressedView() {
RemoteViews views;
if (mTile.isUserQuieted()) {
if (mTile != null && mTile.isUserQuieted()) {
views = new RemoteViews(mContext.getPackageName(),
R.layout.people_tile_work_profile_quiet_layout);
} else {

View File

@@ -22,6 +22,7 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE;
import static com.android.systemui.people.NotificationHelper.getContactUri;
@@ -62,6 +63,7 @@ import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -172,6 +174,7 @@ public class PeopleSpaceWidgetManager {
public void init() {
synchronized (mLock) {
if (!mRegisteredReceivers) {
if (DEBUG) Log.d(TAG, "Register receivers");
IntentFilter filter = new IntentFilter();
filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
filter.addAction(ACTION_BOOT_COMPLETED);
@@ -185,6 +188,14 @@ public class PeopleSpaceWidgetManager {
mBroadcastDispatcher.registerReceiver(mBaseBroadcastReceiver, filter,
null /* executor */, UserHandle.ALL);
IntentFilter perAppFilter = new IntentFilter(ACTION_PACKAGE_REMOVED);
perAppFilter.addDataScheme("package");
// BroadcastDispatcher doesn't allow data schemes.
mContext.registerReceiver(mBaseBroadcastReceiver, perAppFilter);
IntentFilter bootComplete = new IntentFilter(ACTION_BOOT_COMPLETED);
bootComplete.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
// BroadcastDispatcher doesn't allow priority.
mContext.registerReceiver(mBaseBroadcastReceiver, bootComplete);
mRegisteredReceivers = true;
}
}
@@ -303,10 +314,6 @@ public class PeopleSpaceWidgetManager {
/** Updates tile in app widget options and the current view. */
public void updateAppWidgetOptionsAndView(int appWidgetId, PeopleSpaceTile tile) {
if (tile == null) {
if (DEBUG) Log.w(TAG, "Requested to store null tile");
return;
}
synchronized (mTiles) {
mTiles.put(appWidgetId, tile);
}
@@ -320,6 +327,17 @@ public class PeopleSpaceWidgetManager {
*/
@Nullable
public PeopleSpaceTile getTileForExistingWidget(int appWidgetId) {
try {
return getTileForExistingWidgetThrowing(appWidgetId);
} catch (Exception e) {
Log.e(TAG, "Failed to retrieve conversation for tile: " + e);
return null;
}
}
@Nullable
private PeopleSpaceTile getTileForExistingWidgetThrowing(int appWidgetId) throws
PackageManager.NameNotFoundException {
// First, check if tile is cached in memory.
PeopleSpaceTile tile;
synchronized (mTiles) {
@@ -348,7 +366,8 @@ public class PeopleSpaceWidgetManager {
* If a {@link PeopleTileKey} is not provided, fetch one from {@link SharedPreferences}.
*/
@Nullable
public PeopleSpaceTile getTileFromPersistentStorage(PeopleTileKey key, int appWidgetId) {
public PeopleSpaceTile getTileFromPersistentStorage(PeopleTileKey key, int appWidgetId) throws
PackageManager.NameNotFoundException {
if (!key.isValid()) {
Log.e(TAG, "PeopleTileKey invalid: " + key.toString());
return null;
@@ -358,7 +377,6 @@ public class PeopleSpaceWidgetManager {
Log.d(TAG, "System services are null");
return null;
}
try {
if (DEBUG) Log.d(TAG, "Retrieving Tile from storage: " + key.toString());
ConversationChannel channel = mIPeopleManager.getConversation(
@@ -383,9 +401,9 @@ public class PeopleSpaceWidgetManager {
}
// Add current state.
return updateWithCurrentState(storedTile.build(), ACTION_BOOT_COMPLETED);
} catch (Exception e) {
Log.e(TAG, "Failed to retrieve conversation for tile: " + e);
return getTileWithCurrentState(storedTile.build(), ACTION_BOOT_COMPLETED);
} catch (RemoteException e) {
Log.e(TAG, "Could not retrieve data: " + e);
return null;
}
}
@@ -397,7 +415,6 @@ public class PeopleSpaceWidgetManager {
public void updateWidgetsWithNotificationChanged(StatusBarNotification sbn,
PeopleSpaceUtils.NotificationAction notificationAction) {
if (DEBUG) {
Log.d(TAG, "updateWidgetsWithNotificationChanged called");
if (notificationAction == PeopleSpaceUtils.NotificationAction.POSTED) {
Log.d(TAG, "Notification posted, key: " + sbn.getKey());
} else {
@@ -414,7 +431,6 @@ public class PeopleSpaceWidgetManager {
PeopleTileKey key = new PeopleTileKey(
sbn.getShortcutId(), sbn.getUser().getIdentifier(), sbn.getPackageName());
if (!key.isValid()) {
Log.d(TAG, "Sbn doesn't contain valid PeopleTileKey: " + key.toString());
return;
}
int[] widgetIds = mAppWidgetManager.getAppWidgetIds(
@@ -775,7 +791,13 @@ public class PeopleSpaceWidgetManager {
/** Adds a widget based on {@code key} mapped to {@code appWidgetId}. */
public void addNewWidget(int appWidgetId, PeopleTileKey key) {
if (DEBUG) Log.d(TAG, "addNewWidget called with key for appWidgetId: " + appWidgetId);
PeopleSpaceTile tile = getTileFromPersistentStorage(key, appWidgetId);
PeopleSpaceTile tile = null;
try {
tile = getTileFromPersistentStorage(key, appWidgetId);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Cannot add widget since app was uninstalled");
return;
}
if (tile == null) {
return;
}
@@ -1017,72 +1039,85 @@ public class PeopleSpaceWidgetManager {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DEBUG) Log.d(TAG, "Update widgets from: " + action);
mBgExecutor.execute(() -> updateWidgetsOnStateChange(action));
if (DEBUG) Log.d(TAG, "Update widgets from: " + intent.getAction());
mBgExecutor.execute(() -> updateWidgetsFromBroadcastInBackground(intent.getAction()));
}
};
/** Updates any app widget based on the current state. */
/** Updates any app widget to the current state, triggered by a broadcast update. */
@VisibleForTesting
void updateWidgetsOnStateChange(String entryPoint) {
void updateWidgetsFromBroadcastInBackground(String entryPoint) {
int[] appWidgetIds = mAppWidgetManager.getAppWidgetIds(
new ComponentName(mContext, PeopleSpaceWidgetProvider.class));
if (appWidgetIds == null) {
return;
}
synchronized (mLock) {
for (int appWidgetId : appWidgetIds) {
PeopleSpaceTile tile = getTileForExistingWidget(appWidgetId);
if (tile == null) {
Log.e(TAG, "Matching conversation not found for shortcut ID");
} else {
tile = updateWithCurrentState(tile, entryPoint);
for (int appWidgetId : appWidgetIds) {
PeopleSpaceTile existingTile = null;
PeopleSpaceTile updatedTile = null;
try {
synchronized (mLock) {
existingTile = getTileForExistingWidgetThrowing(appWidgetId);
if (existingTile == null) {
Log.e(TAG, "Matching conversation not found for shortcut ID");
return;
}
updatedTile = getTileWithCurrentState(existingTile, entryPoint);
updateAppWidgetOptionsAndView(appWidgetId, updatedTile);
}
updateAppWidgetOptionsAndView(appWidgetId, tile);
} catch (PackageManager.NameNotFoundException e) {
// Delete data for uninstalled widgets.
Log.e(TAG, "Package no longer found for tile: " + e);
synchronized (mLock) {
updateAppWidgetOptionsAndView(appWidgetId, updatedTile);
}
deleteWidgets(new int[]{appWidgetId});
}
}
}
/** Checks the current state of {@code tile} dependencies, updating fields as necessary. */
/** Checks the current state of {@code tile} dependencies, modifying fields as necessary. */
@Nullable
private PeopleSpaceTile updateWithCurrentState(PeopleSpaceTile tile,
String entryPoint) {
private PeopleSpaceTile getTileWithCurrentState(PeopleSpaceTile tile,
String entryPoint) throws
PackageManager.NameNotFoundException {
PeopleSpaceTile.Builder updatedTile = tile.toBuilder();
try {
switch (entryPoint) {
case NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED:
updatedTile.setNotificationPolicyState(getNotificationPolicyState());
break;
case Intent.ACTION_PACKAGES_SUSPENDED:
case Intent.ACTION_PACKAGES_UNSUSPENDED:
updatedTile.setIsPackageSuspended(getPackageSuspended(tile));
break;
case Intent.ACTION_MANAGED_PROFILE_AVAILABLE:
case Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE:
case Intent.ACTION_USER_UNLOCKED:
updatedTile.setIsUserQuieted(getUserQuieted(tile));
break;
case Intent.ACTION_LOCALE_CHANGED:
break;
case ACTION_BOOT_COMPLETED:
default:
updatedTile.setIsUserQuieted(getUserQuieted(tile)).setIsPackageSuspended(
getPackageSuspended(tile)).setNotificationPolicyState(
getNotificationPolicyState());
}
} catch (Exception e) {
Log.e(TAG, "Package no longer found for tile: " + tile.toString() + e);
return null;
switch (entryPoint) {
case NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED:
updatedTile.setNotificationPolicyState(getNotificationPolicyState());
break;
case Intent.ACTION_PACKAGES_SUSPENDED:
case Intent.ACTION_PACKAGES_UNSUSPENDED:
updatedTile.setIsPackageSuspended(getPackageSuspended(tile));
break;
case Intent.ACTION_MANAGED_PROFILE_AVAILABLE:
case Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE:
case Intent.ACTION_USER_UNLOCKED:
updatedTile.setIsUserQuieted(getUserQuieted(tile));
break;
case Intent.ACTION_LOCALE_CHANGED:
break;
case ACTION_BOOT_COMPLETED:
default:
updatedTile.setIsUserQuieted(getUserQuieted(tile)).setIsPackageSuspended(
getPackageSuspended(tile)).setNotificationPolicyState(
getNotificationPolicyState());
}
return updatedTile.build();
}
private boolean getPackageSuspended(PeopleSpaceTile tile) throws Exception {
private boolean getPackageSuspended(PeopleSpaceTile tile) throws
PackageManager.NameNotFoundException {
boolean packageSuspended = !TextUtils.isEmpty(tile.getPackageName())
&& mPackageManager.isPackageSuspended(tile.getPackageName());
if (DEBUG) Log.d(TAG, "Package suspended: " + packageSuspended);
// isPackageSuspended() only throws an exception if the app has been uninstalled, and the
// app data has also been cleared. We want to empty the layout when the app is uninstalled
// regardless of app data clearing, which getApplicationInfoAsUser() handles.
mPackageManager.getApplicationInfoAsUser(
tile.getPackageName(), PackageManager.GET_META_DATA,
PeopleSpaceUtils.getUserId(tile));
return packageSuspended;
}

View File

@@ -17,6 +17,7 @@
package com.android.systemui.people;
import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME;
import static com.android.systemui.people.PeopleSpaceUtils.getContactLookupKeysWithBirthdaysToday;
import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +36,7 @@ import android.app.Person;
import android.app.people.IPeopleManager;
import android.app.people.PeopleSpaceTile;
import android.appwidget.AppWidgetManager;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -64,12 +66,17 @@ import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -112,6 +119,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
.setNotificationDataUri(URI)
.setMessagesCount(1)
.build();
private static final String TEST_DISPLAY_NAME = "Display Name";
private final ShortcutInfo mShortcutInfo = new ShortcutInfo.Builder(mContext,
SHORTCUT_ID_1).setLongLabel(
@@ -227,6 +235,12 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
.thenReturn(List.of(mNotificationEntry1, mNotificationEntry2, mNotificationEntry3));
}
@After
public void tearDown() {
cleanupTestContactFromContactProvider();
}
@Test
public void testAugmentTileFromNotification() {
PeopleSpaceTile tile =
@@ -467,4 +481,82 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
eq(WIDGET_ID_WITH_SHORTCUT),
any());
}
@Test
public void testBirthdayQueriesWithYear() throws Exception {
String birthdayToday = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
addBirthdayToContactsDatabase(birthdayToday);
List<String> lookupKeys = getContactLookupKeysWithBirthdaysToday(mContext);
assertThat(lookupKeys).hasSize(1);
}
@Test
public void testBirthdayQueriesWithoutYear() throws Exception {
String birthdayToday = new SimpleDateFormat("--MM-dd").format(new Date());
addBirthdayToContactsDatabase(birthdayToday);
List<String> lookupKeys = getContactLookupKeysWithBirthdaysToday(mContext);
assertThat(lookupKeys).hasSize(1);
}
@Test
public void testBirthdayQueriesWithDifferentDates() throws Exception {
Date yesterday = new Date(System.currentTimeMillis() - Duration.ofDays(1).toMillis());
String birthdayYesterday = new SimpleDateFormat("--MM-dd").format(yesterday);
addBirthdayToContactsDatabase(birthdayYesterday);
List<String> lookupKeys = getContactLookupKeysWithBirthdaysToday(mContext);
assertThat(lookupKeys).isEmpty();
}
private void addBirthdayToContactsDatabase(String birthdayDate) throws Exception {
ContentResolver resolver = mContext.getContentResolver();
ArrayList<ContentProviderOperation> ops = new ArrayList<>(3);
ops.add(ContentProviderOperation
.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, "com.google")
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, "fakeAccountName")
.build());
ops.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
TEST_DISPLAY_NAME)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.Event.TYPE,
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
.withValue(
ContactsContract.CommonDataKinds.Event.START_DATE, birthdayDate)
.build());
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
}
private void cleanupTestContactFromContactProvider() {
Cursor cursor = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + "=?",
new String[]{TEST_DISPLAY_NAME},
null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.NAME_RAW_CONTACT_ID));
mContext.getContentResolver().delete(ContactsContract.Data.CONTENT_URI,
ContactsContract.Data.RAW_CONTACT_ID + "=?",
new String[]{contactId});
}
cursor.close();
}
}

View File

@@ -43,6 +43,7 @@ import static android.app.people.PeopleSpaceTile.SHOW_IMPORTANT_CONVERSATIONS;
import static android.app.people.PeopleSpaceTile.SHOW_STARRED_CONTACTS;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.content.Intent.ACTION_PACKAGES_SUSPENDED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static android.content.PermissionChecker.PERMISSION_GRANTED;
import static android.content.PermissionChecker.PERMISSION_HARD_DENIED;
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE;
@@ -88,7 +89,6 @@ import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.notification.ConversationChannelWrapper;
@@ -1104,7 +1104,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testGetPeopleTileFromPersistentStorageNoConversation() throws RemoteException {
public void testGetPeopleTileFromPersistentStorageNoConversation() throws Exception {
when(mIPeopleManager.getConversation(TEST_PACKAGE_A, 0, SHORTCUT_ID)).thenReturn(null);
PeopleTileKey key = new PeopleTileKey(SHORTCUT_ID, 0, TEST_PACKAGE_A);
PeopleSpaceTile tile = mManager.getTileFromPersistentStorage(key, WIDGET_ID_WITH_SHORTCUT);
@@ -1223,8 +1223,38 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChange() {
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
public void testUpdateWidgetsFromBroadcastInBackgroundBootCompleteWithPackageUninstalled()
throws Exception {
when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt())).thenThrow(
PackageManager.NameNotFoundException.class);
// We should remove widgets if the package is uninstalled at next reboot if we missed the
// package removed broadcast.
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile).isNull();
verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT),
any());
}
@Test
public void testUpdateWidgetsFromBroadcastInBackgroundPackageRemovedWithPackageUninstalled()
throws Exception {
when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt())).thenThrow(
PackageManager.NameNotFoundException.class);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_PACKAGE_REMOVED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile).isNull();
verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT),
any());
}
@Test
public void testUpdateWidgetsFromBroadcastInBackground() {
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.isPackageSuspended()).isFalse();
@@ -1236,10 +1266,10 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeWithUserQuieted() {
public void testUpdateWidgetsFromBroadcastInBackgroundWithUserQuieted() {
when(mUserManager.isQuietModeEnabled(any())).thenReturn(true);
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.isPackageSuspended()).isFalse();
@@ -1248,10 +1278,10 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeWithPackageSuspended() throws Exception {
public void testUpdateWidgetsFromBroadcastInBackgroundWithPackageSuspended() throws Exception {
when(mPackageManager.isPackageSuspended(any())).thenReturn(true);
mManager.updateWidgetsOnStateChange(ACTION_PACKAGES_SUSPENDED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_PACKAGES_SUSPENDED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.isPackageSuspended()).isTrue();
@@ -1260,9 +1290,9 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeNotInDnd() {
public void testUpdateWidgetsFromBroadcastInBackgroundNotInDnd() {
int expected = 0;
mManager.updateWidgetsOnStateChange(NotificationManager
mManager.updateWidgetsFromBroadcastInBackground(NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
@@ -1270,14 +1300,14 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeAllConversations() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllConversations() {
int expected = 0;
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
INTERRUPTION_FILTER_PRIORITY);
when(mNotificationPolicy.allowConversations()).thenReturn(true);
setFinalField("priorityConversationSenders", CONVERSATION_SENDERS_ANYONE);
mManager.updateWidgetsOnStateChange(NotificationManager
mManager.updateWidgetsFromBroadcastInBackground(NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
@@ -1285,7 +1315,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeAllowOnlyImportantConversations() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowOnlyImportantConversations() {
int expected = 0;
// Only allow important conversations.
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
@@ -1293,7 +1323,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
when(mNotificationPolicy.allowConversations()).thenReturn(true);
setFinalField("priorityConversationSenders", CONVERSATION_SENDERS_IMPORTANT);
mManager.updateWidgetsOnStateChange(NotificationManager
mManager.updateWidgetsFromBroadcastInBackground(NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
@@ -1302,13 +1332,13 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeAllowNoConversations() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowNoConversations() {
int expected = 0;
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
INTERRUPTION_FILTER_PRIORITY);
when(mNotificationPolicy.allowConversations()).thenReturn(false);
mManager.updateWidgetsOnStateChange(NotificationManager
mManager.updateWidgetsFromBroadcastInBackground(NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
@@ -1316,7 +1346,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeAllowNoConversationsAllowContactMessages() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowNoConversationsAllowContactMessages() {
int expected = 0;
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
INTERRUPTION_FILTER_PRIORITY);
@@ -1324,14 +1354,14 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
when(mNotificationPolicy.allowMessagesFrom()).thenReturn(ZenModeConfig.SOURCE_CONTACT);
when(mNotificationPolicy.allowMessages()).thenReturn(true);
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONTACTS);
}
@Test
public void testUpdateWidgetsOnStateChangeAllowNoConversationsAllowStarredContactMessages() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowNoConversationsAllowStarredContactMessages() {
int expected = 0;
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
INTERRUPTION_FILTER_PRIORITY);
@@ -1339,26 +1369,26 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
when(mNotificationPolicy.allowMessagesFrom()).thenReturn(ZenModeConfig.SOURCE_STAR);
when(mNotificationPolicy.allowMessages()).thenReturn(true);
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_STARRED_CONTACTS);
setFinalField("suppressedVisualEffects", SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT);
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONVERSATIONS);
}
@Test
public void testUpdateWidgetsOnStateChangeAllowAlarmsOnly() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowAlarmsOnly() {
int expected = 0;
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
INTERRUPTION_FILTER_ALARMS);
mManager.updateWidgetsOnStateChange(NotificationManager
mManager.updateWidgetsFromBroadcastInBackground(NotificationManager
.ACTION_INTERRUPTION_FILTER_CHANGED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
@@ -1366,7 +1396,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
}
@Test
public void testUpdateWidgetsOnStateChangeAllowVisualEffectsAndAllowAlarmsOnly() {
public void testUpdateWidgetsFromBroadcastInBackgroundAllowVisualEffectsAndAllowAlarmsOnly() {
int expected = 0;
// If we show visuals, but just only make sounds for alarms, still show content in tiles.
when(mNotificationManager.getCurrentInterruptionFilter()).thenReturn(
@@ -1374,7 +1404,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
setFinalField("suppressedVisualEffects", SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT);
mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED);
mManager.updateWidgetsFromBroadcastInBackground(ACTION_BOOT_COMPLETED);
PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT);
assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONVERSATIONS);