Merge "Only tag foreground notifications" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
59831cbec7
@@ -73,7 +73,7 @@ public interface ForegroundServiceController {
|
|||||||
void onAppOpChanged(int code, int uid, String packageName, boolean active);
|
void onAppOpChanged(int code, int uid, String packageName, boolean active);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets active app ops for this user and package.
|
* Gets active app ops for this user and package
|
||||||
*/
|
*/
|
||||||
@Nullable ArraySet<Integer> getAppOps(int userId, String packageName);
|
@Nullable ArraySet<Integer> getAppOps(int userId, String packageName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class AppOpsListener implements AppOpsManager.OnOpActiveChangedListener {
|
|||||||
public void onOpActiveChanged(int code, int uid, String packageName, boolean active) {
|
public void onOpActiveChanged(int code, int uid, String packageName, boolean active) {
|
||||||
mFsc.onAppOpChanged(code, uid, packageName, active);
|
mFsc.onAppOpChanged(code, uid, packageName, active);
|
||||||
mPresenter.getHandler().post(() -> {
|
mPresenter.getHandler().post(() -> {
|
||||||
mEntryManager.updateNotificationsForAppOps(code, uid, packageName, active);
|
mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,8 +383,6 @@ public class NotificationData {
|
|||||||
}
|
}
|
||||||
mGroupManager.onEntryAdded(entry);
|
mGroupManager.onEntryAdded(entry);
|
||||||
|
|
||||||
updateAppOps(entry);
|
|
||||||
|
|
||||||
updateRankingAndSort(mRankingMap);
|
updateRankingAndSort(mRankingMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,25 +401,14 @@ public class NotificationData {
|
|||||||
updateRankingAndSort(ranking);
|
updateRankingAndSort(ranking);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAppOps(Entry entry) {
|
public void updateAppOp(int appOp, int uid, String pkg, String key, boolean showIcon) {
|
||||||
final int uid = entry.notification.getUid();
|
|
||||||
final String pkg = entry.notification.getPackageName();
|
|
||||||
ArraySet<Integer> activeOps = mFsc.getAppOps(entry.notification.getUserId(), pkg);
|
|
||||||
if (activeOps != null) {
|
|
||||||
int N = activeOps.size();
|
|
||||||
for (int i = 0; i < N; i++) {
|
|
||||||
updateAppOp(activeOps.valueAt(i), uid, pkg, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAppOp(int appOp, int uid, String pkg, boolean showIcon) {
|
|
||||||
synchronized (mEntries) {
|
synchronized (mEntries) {
|
||||||
final int N = mEntries.size();
|
final int N = mEntries.size();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
Entry entry = mEntries.valueAt(i);
|
Entry entry = mEntries.valueAt(i);
|
||||||
if (uid == entry.notification.getUid()
|
if (uid == entry.notification.getUid()
|
||||||
&& pkg.equals(entry.notification.getPackageName())) {
|
&& pkg.equals(entry.notification.getPackageName())
|
||||||
|
&& key.equals(entry.key)) {
|
||||||
if (showIcon) {
|
if (showIcon) {
|
||||||
entry.mActiveAppOps.add(appOp);
|
entry.mActiveAppOps.add(appOp);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.statusbar.IStatusBarService;
|
import com.android.internal.statusbar.IStatusBarService;
|
||||||
import com.android.internal.util.NotificationMessagingUtil;
|
import com.android.internal.util.NotificationMessagingUtil;
|
||||||
@@ -665,6 +666,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
|
|||||||
}
|
}
|
||||||
// Add the expanded view and icon.
|
// Add the expanded view and icon.
|
||||||
mNotificationData.add(entry);
|
mNotificationData.add(entry);
|
||||||
|
tagForeground(entry.notification);
|
||||||
updateNotifications();
|
updateNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,6 +728,19 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
|
|||||||
mPendingNotifications.put(key, shadeEntry);
|
mPendingNotifications.put(key, shadeEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected void tagForeground(StatusBarNotification notification) {
|
||||||
|
ArraySet<Integer> activeOps = mForegroundServiceController.getAppOps(
|
||||||
|
notification.getUserId(), notification.getPackageName());
|
||||||
|
if (activeOps != null) {
|
||||||
|
int N = activeOps.size();
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
updateNotificationsForAppOp(activeOps.valueAt(i), notification.getUid(),
|
||||||
|
notification.getPackageName(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNotification(StatusBarNotification notification,
|
public void addNotification(StatusBarNotification notification,
|
||||||
NotificationListenerService.RankingMap ranking) {
|
NotificationListenerService.RankingMap ranking) {
|
||||||
@@ -736,10 +751,11 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNotificationsForAppOps(int appOp, int uid, String pkg, boolean showIcon) {
|
public void updateNotificationsForAppOp(int appOp, int uid, String pkg, boolean showIcon) {
|
||||||
if (mForegroundServiceController.getStandardLayoutKey(
|
String foregroundKey = mForegroundServiceController.getStandardLayoutKey(
|
||||||
UserHandle.getUserId(uid), pkg) != null) {
|
UserHandle.getUserId(uid), pkg);
|
||||||
mNotificationData.updateAppOp(appOp, uid, pkg, showIcon);
|
if (foregroundKey != null) {
|
||||||
|
mNotificationData.updateAppOp(appOp, uid, pkg, foregroundKey, showIcon);
|
||||||
updateNotifications();
|
updateNotifications();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class AppOpsListenerTest extends SysuiTestCase {
|
|||||||
mListener.onOpActiveChanged(
|
mListener.onOpActiveChanged(
|
||||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||||
waitForIdleSync(mHandler);
|
waitForIdleSync(mHandler);
|
||||||
verify(mEntryManager, times(1)).updateNotificationsForAppOps(
|
verify(mEntryManager, times(1)).updateNotificationsForAppOp(
|
||||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,32 +139,7 @@ public class NotificationDataTest extends SysuiTestCase {
|
|||||||
Assert.assertTrue(mRow.getEntry().channel != null);
|
Assert.assertTrue(mRow.getEntry().channel != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAdd_appOpsAdded() {
|
|
||||||
ArraySet<Integer> expected = new ArraySet<>();
|
|
||||||
expected.add(3);
|
|
||||||
expected.add(235);
|
|
||||||
expected.add(1);
|
|
||||||
when(mFsc.getAppOps(mRow.getEntry().notification.getUserId(),
|
|
||||||
mRow.getEntry().notification.getPackageName())).thenReturn(expected);
|
|
||||||
|
|
||||||
mNotificationData.add(mRow.getEntry());
|
|
||||||
assertEquals(expected.size(),
|
|
||||||
mNotificationData.get(mRow.getEntry().key).mActiveAppOps.size());
|
|
||||||
for (int op : expected) {
|
|
||||||
assertTrue(" entry missing op " + op,
|
|
||||||
mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(op));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAdd_noExistingAppOps() {
|
|
||||||
when(mFsc.getAppOps(mRow.getEntry().notification.getUserId(),
|
|
||||||
mRow.getEntry().notification.getPackageName())).thenReturn(null);
|
|
||||||
|
|
||||||
mNotificationData.add(mRow.getEntry());
|
|
||||||
assertEquals(0, mNotificationData.get(mRow.getEntry().key).mActiveAppOps.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllRelevantNotisTaggedWithAppOps() throws Exception {
|
public void testAllRelevantNotisTaggedWithAppOps() throws Exception {
|
||||||
@@ -181,7 +156,9 @@ public class NotificationDataTest extends SysuiTestCase {
|
|||||||
|
|
||||||
for (int op : expectedOps) {
|
for (int op : expectedOps) {
|
||||||
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
|
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
|
||||||
NotificationTestHelper.PKG, true);
|
NotificationTestHelper.PKG, mRow.getEntry().key, true);
|
||||||
|
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
|
||||||
|
NotificationTestHelper.PKG, row2.getEntry().key, true);
|
||||||
}
|
}
|
||||||
for (int op : expectedOps) {
|
for (int op : expectedOps) {
|
||||||
assertTrue(mRow.getEntry().key + " doesn't have op " + op,
|
assertTrue(mRow.getEntry().key + " doesn't have op " + op,
|
||||||
@@ -205,12 +182,12 @@ public class NotificationDataTest extends SysuiTestCase {
|
|||||||
|
|
||||||
for (int op : expectedOps) {
|
for (int op : expectedOps) {
|
||||||
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
|
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
|
||||||
NotificationTestHelper.PKG, true);
|
NotificationTestHelper.PKG, row2.getEntry().key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedOps.remove(OP_ACCEPT_HANDOVER);
|
expectedOps.remove(OP_ACCEPT_HANDOVER);
|
||||||
mNotificationData.updateAppOp(OP_ACCEPT_HANDOVER, NotificationTestHelper.UID,
|
mNotificationData.updateAppOp(OP_ACCEPT_HANDOVER, NotificationTestHelper.UID,
|
||||||
NotificationTestHelper.PKG, false);
|
NotificationTestHelper.PKG, row2.getEntry().key, false);
|
||||||
|
|
||||||
assertTrue(mRow.getEntry().key + " doesn't have op " + OP_CAMERA,
|
assertTrue(mRow.getEntry().key + " doesn't have op " + OP_CAMERA,
|
||||||
mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(OP_CAMERA));
|
mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(OP_CAMERA));
|
||||||
|
|||||||
@@ -37,18 +37,15 @@ import android.app.AppOpsManager;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.NotificationRankingUpdate;
|
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.support.test.filters.SmallTest;
|
import android.support.test.filters.SmallTest;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
|
import android.util.ArraySet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
@@ -56,12 +53,13 @@ import com.android.internal.statusbar.IStatusBarService;
|
|||||||
import com.android.systemui.ForegroundServiceController;
|
import com.android.systemui.ForegroundServiceController;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.systemui.UiOffloadThread;
|
|
||||||
import com.android.systemui.statusbar.notification.VisualStabilityManager;
|
import com.android.systemui.statusbar.notification.VisualStabilityManager;
|
||||||
import com.android.systemui.statusbar.phone.NotificationGroupManager;
|
import com.android.systemui.statusbar.phone.NotificationGroupManager;
|
||||||
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
|
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
|
||||||
import com.android.systemui.statusbar.policy.HeadsUpManager;
|
import com.android.systemui.statusbar.policy.HeadsUpManager;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -285,13 +283,12 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
|||||||
com.android.systemui.util.Assert.isNotMainThread();
|
com.android.systemui.util.Assert.isNotMainThread();
|
||||||
|
|
||||||
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
|
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
|
||||||
.thenReturn("something");
|
.thenReturn(mEntry.key);
|
||||||
mEntry.row = mRow;
|
mEntry.row = mRow;
|
||||||
mEntryManager.getNotificationData().add(mEntry);
|
mEntryManager.getNotificationData().add(mEntry);
|
||||||
|
|
||||||
|
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
mEntryManager.updateNotificationsForAppOps(
|
mEntryManager.updateNotificationsForAppOp(
|
||||||
AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
|
AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
|
||||||
mEntry.notification.getPackageName(), true);
|
mEntry.notification.getPackageName(), true);
|
||||||
});
|
});
|
||||||
@@ -309,10 +306,65 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
|||||||
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
|
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
mEntryManager.updateNotificationsForAppOps(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
|
mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
|
||||||
});
|
});
|
||||||
waitForIdleSync(mHandler);
|
waitForIdleSync(mHandler);
|
||||||
|
|
||||||
verify(mPresenter, never()).updateNotificationViews();
|
verify(mPresenter, never()).updateNotificationViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddNotificationExistingAppOps() {
|
||||||
|
mEntry.row = mRow;
|
||||||
|
mEntryManager.getNotificationData().add(mEntry);
|
||||||
|
ArraySet<Integer> expected = new ArraySet<>();
|
||||||
|
expected.add(3);
|
||||||
|
expected.add(235);
|
||||||
|
expected.add(1);
|
||||||
|
|
||||||
|
when(mForegroundServiceController.getAppOps(mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn(expected);
|
||||||
|
when(mForegroundServiceController.getStandardLayoutKey(
|
||||||
|
mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn(mEntry.key);
|
||||||
|
|
||||||
|
mEntryManager.tagForeground(mEntry.notification);
|
||||||
|
|
||||||
|
Assert.assertEquals(expected.size(), mEntry.mActiveAppOps.size());
|
||||||
|
for (int op : expected) {
|
||||||
|
assertTrue("Entry missing op " + op, mEntry.mActiveAppOps.contains(op));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdd_noExistingAppOps() {
|
||||||
|
mEntry.row = mRow;
|
||||||
|
mEntryManager.getNotificationData().add(mEntry);
|
||||||
|
when(mForegroundServiceController.getStandardLayoutKey(
|
||||||
|
mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn(mEntry.key);
|
||||||
|
when(mForegroundServiceController.getAppOps(mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn(null);
|
||||||
|
|
||||||
|
mEntryManager.tagForeground(mEntry.notification);
|
||||||
|
Assert.assertEquals(0, mEntry.mActiveAppOps.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdd_existingAppOpsNotForegroundNoti() {
|
||||||
|
mEntry.row = mRow;
|
||||||
|
mEntryManager.getNotificationData().add(mEntry);
|
||||||
|
ArraySet<Integer> ops = new ArraySet<>();
|
||||||
|
ops.add(3);
|
||||||
|
ops.add(235);
|
||||||
|
ops.add(1);
|
||||||
|
when(mForegroundServiceController.getAppOps(mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn(ops);
|
||||||
|
when(mForegroundServiceController.getStandardLayoutKey(
|
||||||
|
mEntry.notification.getUserId(),
|
||||||
|
mEntry.notification.getPackageName())).thenReturn("something else");
|
||||||
|
|
||||||
|
mEntryManager.tagForeground(mEntry.notification);
|
||||||
|
Assert.assertEquals(0, mEntry.mActiveAppOps.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user