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);
}
public void onOpActiveChanged(int code, int uid, String packageName, boolean active) {
mFsc.onAppOpChanged(code, uid, packageName, active);
mPresenter.getHandler().post(() -> {
- mEntryManager.updateNotificationsForAppOps(code, uid, packageName, active);
+ mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active);
});
}
}
}
mGroupManager.onEntryAdded(entry);
- updateAppOps(entry);
-
updateRankingAndSort(mRankingMap);
}
updateRankingAndSort(ranking);
}
- private void updateAppOps(Entry entry) {
- 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) {
+ public void updateAppOp(int appOp, int uid, String pkg, String key, boolean showIcon) {
synchronized (mEntries) {
final int N = mEntries.size();
for (int i = 0; i < N; i++) {
Entry entry = mEntries.valueAt(i);
if (uid == entry.notification.getUid()
- && pkg.equals(entry.notification.getPackageName())) {
+ && pkg.equals(entry.notification.getPackageName())
+ && key.equals(entry.key)) {
if (showIcon) {
entry.mActiveAppOps.add(appOp);
} else {
import android.view.View;
import android.view.ViewGroup;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.NotificationMessagingUtil;
}
// Add the expanded view and icon.
mNotificationData.add(entry);
+ tagForeground(entry.notification);
updateNotifications();
}
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
public void addNotification(StatusBarNotification notification,
NotificationListenerService.RankingMap ranking) {
}
}
- public void updateNotificationsForAppOps(int appOp, int uid, String pkg, boolean showIcon) {
- if (mForegroundServiceController.getStandardLayoutKey(
- UserHandle.getUserId(uid), pkg) != null) {
- mNotificationData.updateAppOp(appOp, uid, pkg, showIcon);
+ public void updateNotificationsForAppOp(int appOp, int uid, String pkg, boolean showIcon) {
+ String foregroundKey = mForegroundServiceController.getStandardLayoutKey(
+ UserHandle.getUserId(uid), pkg);
+ if (foregroundKey != null) {
+ mNotificationData.updateAppOp(appOp, uid, pkg, foregroundKey, showIcon);
updateNotifications();
}
}
mListener.onOpActiveChanged(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
waitForIdleSync(mHandler);
- verify(mEntryManager, times(1)).updateNotificationsForAppOps(
+ verify(mEntryManager, times(1)).updateNotificationsForAppOp(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
}
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
public void testAllRelevantNotisTaggedWithAppOps() throws Exception {
for (int op : expectedOps) {
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) {
assertTrue(mRow.getEntry().key + " doesn't have op " + op,
for (int op : expectedOps) {
mNotificationData.updateAppOp(op, NotificationTestHelper.UID,
- NotificationTestHelper.PKG, true);
+ NotificationTestHelper.PKG, row2.getEntry().key, true);
}
expectedOps.remove(OP_ACCEPT_HANDOVER);
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,
mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(OP_CAMERA));
import android.app.Notification;
import android.app.NotificationManager;
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.Looper;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
-import android.service.notification.NotificationRankingUpdate;
import android.service.notification.StatusBarNotification;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
+import android.util.ArraySet;
import android.widget.FrameLayout;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.ForegroundServiceController;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.UiOffloadThread;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
+import junit.framework.Assert;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
com.android.systemui.util.Assert.isNotMainThread();
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
- .thenReturn("something");
+ .thenReturn(mEntry.key);
mEntry.row = mRow;
mEntryManager.getNotificationData().add(mEntry);
-
mHandler.post(() -> {
- mEntryManager.updateNotificationsForAppOps(
+ mEntryManager.updateNotificationsForAppOp(
AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
mEntry.notification.getPackageName(), true);
});
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
.thenReturn(null);
mHandler.post(() -> {
- mEntryManager.updateNotificationsForAppOps(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
+ mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
});
waitForIdleSync(mHandler);
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());
+ }
}