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

Commit d00a5e18 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Fix handling of work profiles in notification history" into rvc-dev am:...

Merge "Fix handling of work profiles in notification history" into rvc-dev am: 10c0d0d2 am: 2e2dbfb8

Change-Id: I356dc3b2080d4510d86e68772cdbc1f9dd36c505
parents ffe87417 2e2dbfb8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Slog;

import java.util.ArrayList;
import java.util.Arrays;
@@ -107,9 +108,11 @@ public final class NotificationHistory implements Parcelable {
                    ", mChannelName='" + mChannelName + '\'' +
                    ", mChannelId='" + mChannelId + '\'' +
                    ", mUserId=" + mUserId +
                    ", mUid=" + mUid +
                    ", mTitle='" + mTitle + '\'' +
                    ", mText='" + mText + '\'' +
                    ", mIcon=" + mIcon +
                    ", mPostedTimeMs=" + mPostedTimeMs +
                    ", mConversationId=" + mConversationId +
                    '}';
        }
@@ -285,9 +288,7 @@ public final class NotificationHistory implements Parcelable {
        if (!hasNextNotification()) {
            return null;
        }

        HistoricalNotification n = readNotificationFromParcel(mParcel);

        mIndex++;
        if (!hasNextNotification()) {
            mParcel.recycle();
+2 −0
Original line number Diff line number Diff line
@@ -351,5 +351,7 @@ public class NotificationHistoryTest {
            HistoricalNotification postParcelNotification = parceledHistory.getNextNotification();
            assertThat(postParcelNotification).isEqualTo(expectedEntries.get(i));
        }
        assertThat(parceledHistory.hasNextNotification()).isFalse();
        assertThat(parceledHistory.getNextNotification()).isNull();
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -358,10 +358,12 @@ public class NotificationHistoryManager {
                    false, this, UserHandle.USER_ALL);
            synchronized (mLock) {
                for (UserInfo userInfo : mUserManager.getUsers()) {
                    if (!userInfo.isProfile()) {
                        update(null, userInfo.id);
                    }
                }
            }
        }

        void stopObserving() {
            ContentResolver resolver = mContext.getContentResolver();
@@ -379,7 +381,10 @@ public class NotificationHistoryManager {
                boolean historyEnabled = Settings.Secure.getIntForUser(resolver,
                        Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, userId)
                        != 0;
                onHistoryEnabledChanged(userId, historyEnabled);
                int[] profiles = mUserManager.getProfileIds(userId, true);
                for (int profileId : profiles) {
                    onHistoryEnabledChanged(profileId, historyEnabled);
                }
            }
        }
    }
+1 −0
Original line number Diff line number Diff line
@@ -2684,6 +2684,7 @@ public class NotificationManagerService extends SystemService {
                mHistoryManager.addNotification(new HistoricalNotification.Builder()
                        .setPackage(r.getSbn().getPackageName())
                        .setUid(r.getSbn().getUid())
                        .setUserId(r.getUserId())
                        .setChannelId(r.getChannel().getId())
                        .setChannelName(r.getChannel().getName().toString())
                        .setPostedTimeMs(System.currentTimeMillis())
+78 −18
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.app.NotificationHistory;
import android.app.NotificationHistory.HistoricalNotification;
import android.content.pm.UserInfo;
import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.UserManager;
import android.provider.Settings;

@@ -40,7 +39,6 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.server.UiServiceTestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,9 +56,9 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase {
    UserManager mUserManager;
    @Mock
    NotificationHistoryDatabase mDb;
    @Mock
    Handler mHandler;
    List<UserInfo> mUsers;
    int[] mProfiles;
    int mProfileId = 11;

    NotificationHistoryManager mHistoryManager;

@@ -98,26 +96,32 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase {
        UserInfo userSystem = new UserInfo();
        userSystem.id = USER_SYSTEM;
        mUsers.add(userSystem);
        UserInfo userAll = new UserInfo();
        userAll.id = MIN_SECONDARY_USER_ID;
        mUsers.add(userAll);
        mUsers.add(userAll);
        UserInfo userFullSecondary = new UserInfo();
        userFullSecondary.id = MIN_SECONDARY_USER_ID;
        mUsers.add(userFullSecondary);
        UserInfo userProfile = new UserInfo();
        userProfile.id = mProfileId;
        mUsers.add(userProfile);
        when(mUserManager.getUsers()).thenReturn(mUsers);

        for (UserInfo info : mUsers) {
            Settings.Secure.putIntForUser(getContext().getContentResolver(),
                    Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, info.id);
        }
        mProfiles = new int[] {userSystem.id, userProfile.id};
        when(mUserManager.getProfileIds(userSystem.id, true)).thenReturn(mProfiles);
        when(mUserManager.getProfileIds(userFullSecondary.id, true))
                .thenReturn(new int[] {userFullSecondary.id});
        when(mUserManager.getProfileIds(userProfile.id, true))
                .thenReturn(new int[] {userProfile.id});

        when(mUserManager.getProfileParent(userProfile.id)).thenReturn(userSystem);

        NotificationHistoryDatabaseFactory.setTestingNotificationHistoryDatabase(mDb);

        mHistoryManager = new NotificationHistoryManager(getContext(), mHandler);
        mHistoryManager.onBootPhaseAppsCanStart();
    }
        mHistoryManager = new NotificationHistoryManager(getContext(), null);

    @After
    public void tearDown() {
        mHistoryManager.onDestroy();
        for (UserInfo info : mUsers) {
            Settings.Secure.putIntForUser(getContext().getContentResolver(),
                    Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, info.id);
            mHistoryManager.mSettingsObserver.update(null, info.id);
        }
    }

    @Test
@@ -150,6 +154,31 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase {
        verify(mDb, times(1)).disableHistory();
    }

    @Test
    public void testOnUserUnlocked_historyDisabled_withProfile() {
        // create a history
        mHistoryManager.onUserUnlocked(USER_SYSTEM);
        assertThat(mHistoryManager.doesHistoryExistForUser(USER_SYSTEM)).isTrue();
        mHistoryManager.onUserUnlocked(mProfileId);
        assertThat(mHistoryManager.doesHistoryExistForUser(mProfileId)).isTrue();
        // lock user
        mHistoryManager.onUserStopped(USER_SYSTEM);
        mHistoryManager.onUserStopped(mProfileId);

        // turn off history
        Settings.Secure.putIntForUser(getContext().getContentResolver(),
                Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, USER_SYSTEM);
        mHistoryManager.mSettingsObserver.update(null, USER_SYSTEM);

        // unlock user, verify that history is disabled for self and profile
        mHistoryManager.onUserUnlocked(USER_SYSTEM);
        mHistoryManager.onUserUnlocked(mProfileId);

        assertThat(mHistoryManager.doesHistoryExistForUser(USER_SYSTEM)).isFalse();
        assertThat(mHistoryManager.doesHistoryExistForUser(mProfileId)).isFalse();
        verify(mDb, times(2)).disableHistory();
    }

    @Test
    public void testOnUserUnlocked_historyDisabledThenEnabled() {
        // create a history
@@ -176,6 +205,37 @@ public class NotificationHistoryManagerTest extends UiServiceTestCase {
        verify(mDb, never()).disableHistory();
    }

    @Test
    public void testOnUserUnlocked_historyDisabledThenEnabled_multiProfile() {
        // create a history
        mHistoryManager.onUserUnlocked(USER_SYSTEM);
        assertThat(mHistoryManager.doesHistoryExistForUser(USER_SYSTEM)).isTrue();
        mHistoryManager.onUserUnlocked(mProfileId);
        assertThat(mHistoryManager.doesHistoryExistForUser(mProfileId)).isTrue();

        // lock user
        mHistoryManager.onUserStopped(USER_SYSTEM);
        mHistoryManager.onUserStopped(mProfileId);

        // turn off history
        Settings.Secure.putIntForUser(getContext().getContentResolver(),
                Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, USER_SYSTEM);
        mHistoryManager.mSettingsObserver.update(null, USER_SYSTEM);

        // turn on history
        Settings.Secure.putIntForUser(getContext().getContentResolver(),
                Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, USER_SYSTEM);
        mHistoryManager.mSettingsObserver.update(null, USER_SYSTEM);

        // unlock user, verify that history is NOT disabled
        mHistoryManager.onUserUnlocked(USER_SYSTEM);
        mHistoryManager.onUserUnlocked(mProfileId);

        assertThat(mHistoryManager.doesHistoryExistForUser(USER_SYSTEM)).isTrue();
        assertThat(mHistoryManager.doesHistoryExistForUser(mProfileId)).isTrue();
        verify(mDb, never()).disableHistory();
    }

    @Test
    public void testOnUserUnlocked_cleansUpRemovedPackages() {
        String pkg = "pkg";
Loading