Merge "Fix handling of work profiles in notification history" into rvc-dev am: 10c0d0d26c
Change-Id: I45aa9eb3b72cc70763a8224d572bd538a2206b59
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +358,9 @@ public class NotificationHistoryManager {
|
||||
false, this, UserHandle.USER_ALL);
|
||||
synchronized (mLock) {
|
||||
for (UserInfo userInfo : mUserManager.getUsers()) {
|
||||
update(null, userInfo.id);
|
||||
if (!userInfo.isProfile()) {
|
||||
update(null, userInfo.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
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(), null);
|
||||
|
||||
for (UserInfo info : mUsers) {
|
||||
Settings.Secure.putIntForUser(getContext().getContentResolver(),
|
||||
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1, info.id);
|
||||
mHistoryManager.mSettingsObserver.update(null, info.id);
|
||||
}
|
||||
|
||||
NotificationHistoryDatabaseFactory.setTestingNotificationHistoryDatabase(mDb);
|
||||
|
||||
mHistoryManager = new NotificationHistoryManager(getContext(), mHandler);
|
||||
mHistoryManager.onBootPhaseAppsCanStart();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mHistoryManager.onDestroy();
|
||||
}
|
||||
|
||||
@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";
|
||||
|
||||
@@ -4394,6 +4394,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
|
||||
verify(mAppUsageStats, times(1)).reportInterruptiveNotification(
|
||||
anyString(), anyString(), anyInt());
|
||||
verify(mHistoryManager, times(1)).addNotification(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user