Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a770ec9b authored by Priyanka Advani's avatar Priyanka Advani Committed by Android (Google) Code Review
Browse files

Revert "Add support for generated previews to People Space widget"

This reverts commit b3a44252.

Reason for revert: Droid-monitored triggered revert for breakages in b/329679427. Will be running through ABTD for verification and before submitting the revert.

Change-Id: If24e0a5a9d025b8bdd492a9562fabb8b892d7314
parent b3a44252
Loading
Loading
Loading
Loading
+2 −47
Original line number Original line Diff line number Diff line
@@ -21,9 +21,6 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_ALARMS;
import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN;
import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
import static android.appwidget.flags.Flags.generatedPreviews;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
@@ -83,15 +80,12 @@ import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.widget.RemoteViews;
import android.widget.RemoteViews;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.Dumpable;
import com.android.systemui.Dumpable;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.SysUISingleton;
@@ -102,8 +96,6 @@ import com.android.systemui.people.PeopleBackupFollowUpJob;
import com.android.systemui.people.PeopleSpaceUtils;
import com.android.systemui.people.PeopleSpaceUtils;
import com.android.systemui.people.PeopleTileViewHelper;
import com.android.systemui.people.PeopleTileViewHelper;
import com.android.systemui.people.SharedPreferencesHelper;
import com.android.systemui.people.SharedPreferencesHelper;
import com.android.systemui.res.R;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -168,27 +160,13 @@ public class PeopleSpaceWidgetManager implements Dumpable {
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>();
    public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>();


    @NonNull private final UserTracker mUserTracker;
    @NonNull private final SparseBooleanArray mUpdatedPreviews = new SparseBooleanArray();
    @NonNull private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
            new KeyguardUpdateMonitorCallback() {
                @Override
                public void onUserUnlocked() {
                    if (DEBUG) {
                        Log.d(TAG, "onUserUnlocked " + mUserTracker.getUserId());
                    }
                    updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
                }
            };

    @Inject
    @Inject
    public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps,
    public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps,
            CommonNotifCollection notifCollection,
            CommonNotifCollection notifCollection,
            PackageManager packageManager, Optional<Bubbles> bubblesOptional,
            PackageManager packageManager, Optional<Bubbles> bubblesOptional,
            UserManager userManager, NotificationManager notificationManager,
            UserManager userManager, NotificationManager notificationManager,
            BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor,
            BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor,
            DumpManager dumpManager, @NonNull UserTracker userTracker,
            DumpManager dumpManager) {
            @NonNull KeyguardUpdateMonitor keyguardUpdateMonitor) {
        if (DEBUG) Log.d(TAG, "constructor");
        if (DEBUG) Log.d(TAG, "constructor");
        mContext = context;
        mContext = context;
        mAppWidgetManager = AppWidgetManager.getInstance(context);
        mAppWidgetManager = AppWidgetManager.getInstance(context);
@@ -209,8 +187,6 @@ public class PeopleSpaceWidgetManager implements Dumpable {
        mBroadcastDispatcher = broadcastDispatcher;
        mBroadcastDispatcher = broadcastDispatcher;
        mBgExecutor = bgExecutor;
        mBgExecutor = bgExecutor;
        dumpManager.registerNormalDumpable(TAG, this);
        dumpManager.registerNormalDumpable(TAG, this);
        mUserTracker = userTracker;
        keyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
    }
    }


    /** Initializes {@PeopleSpaceWidgetManager}. */
    /** Initializes {@PeopleSpaceWidgetManager}. */
@@ -270,7 +246,7 @@ public class PeopleSpaceWidgetManager implements Dumpable {
            CommonNotifCollection notifCollection, PackageManager packageManager,
            CommonNotifCollection notifCollection, PackageManager packageManager,
            Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager,
            Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager,
            INotificationManager iNotificationManager, NotificationManager notificationManager,
            INotificationManager iNotificationManager, NotificationManager notificationManager,
            @Background Executor executor, UserTracker userTracker) {
            @Background Executor executor) {
        mContext = context;
        mContext = context;
        mAppWidgetManager = appWidgetManager;
        mAppWidgetManager = appWidgetManager;
        mIPeopleManager = iPeopleManager;
        mIPeopleManager = iPeopleManager;
@@ -286,7 +262,6 @@ public class PeopleSpaceWidgetManager implements Dumpable {
        mManager = this;
        mManager = this;
        mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        mBgExecutor = executor;
        mBgExecutor = executor;
        mUserTracker = userTracker;
    }
    }


    /**
    /**
@@ -1432,24 +1407,4 @@ public class PeopleSpaceWidgetManager implements Dumpable {


        Trace.traceEnd(Trace.TRACE_TAG_APP);
        Trace.traceEnd(Trace.TRACE_TAG_APP);
    }
    }

    @VisibleForTesting
    void updateGeneratedPreviewForUser(UserHandle user) {
        if (!generatedPreviews() || mUpdatedPreviews.get(user.getIdentifier())
                || !mUserManager.isUserUnlocked(user)) {
            return;
        }
        if (DEBUG) {
            Log.d(TAG, "Updating People Space widget preview for user " + user.getIdentifier());
        }
        boolean success = mAppWidgetManager.setWidgetPreview(
                new ComponentName(mContext, PeopleSpaceWidgetProvider.class),
                WIDGET_CATEGORY_HOME_SCREEN | WIDGET_CATEGORY_KEYGUARD,
                new RemoteViews(mContext.getPackageName(),
                        R.layout.people_space_placeholder_layout));
        if (DEBUG && !success) {
            Log.d(TAG, "Failed to update generated preview for user " + user.getIdentifier());
        }
        mUpdatedPreviews.put(user.getIdentifier(), success);
    }
}
}
+2 −42
Original line number Original line Diff line number Diff line
@@ -101,12 +101,11 @@ import android.text.TextUtils;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.systemui.res.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.people.PeopleBackupFollowUpJob;
import com.android.systemui.people.PeopleBackupFollowUpJob;
import com.android.systemui.people.PeopleSpaceUtils;
import com.android.systemui.people.PeopleSpaceUtils;
import com.android.systemui.people.SharedPreferencesHelper;
import com.android.systemui.people.SharedPreferencesHelper;
import com.android.systemui.res.R;
import com.android.systemui.settings.FakeUserTracker;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.SbnBuilder;
import com.android.systemui.statusbar.SbnBuilder;
@@ -266,8 +265,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {


    private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock);
    private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock);


    private final FakeUserTracker mUserTracker = new FakeUserTracker();

    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
@@ -275,7 +272,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
        mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager,
        mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager,
                mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager,
                mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager,
                Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager,
                Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager,
                mNotificationManager, mFakeExecutor, mUserTracker);
                mNotificationManager, mFakeExecutor);
        mManager.attach(mListenerService);
        mManager.attach(mListenerService);


        verify(mListenerService).addNotificationHandler(mListenerCaptor.capture());
        verify(mListenerService).addNotificationHandler(mListenerCaptor.capture());
@@ -1565,43 +1562,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
                String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS));
                String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS));
    }
    }


    @Test
    public void testUpdateGeneratedPreview_flagDisabled() {
        mSetFlagsRule.disableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS);
        mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
        verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any());
    }

    @Test
    public void testUpdateGeneratedPreview_userLocked() {
        mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS);
        when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(false);

        mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
        verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any());
    }

    @Test
    public void testUpdateGeneratedPreview_userUnlocked() {
        mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS);
        when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true);
        when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true);

        mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
        verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any());
    }

    @Test
    public void testUpdateGeneratedPreview_doesNotSetTwice() {
        mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS);
        when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true);
        when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true);

        mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
        mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle());
        verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any());
    }

    private void setFinalField(String fieldName, int value) {
    private void setFinalField(String fieldName, int value) {
        try {
        try {
            Field field = NotificationManager.Policy.class.getDeclaredField(fieldName);
            Field field = NotificationManager.Policy.class.getDeclaredField(fieldName);