Merge "Catch SecurityException from NoMan to workaround possible race condition" into tm-dev am: 1cd4d369a2
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17775689 Change-Id: Iace994dce515e3b3699f97dac1d4706458eb646f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
a2e7ca746f
1 file changed
+17
-12
@@ -35,6 +35,7 @@ import android.util.Log;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.annotation.AnyThread;
|
import androidx.annotation.AnyThread;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
@@ -154,14 +155,9 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
case MSG_NOTIFICATION_FULL_REFRESH:
|
case MSG_NOTIFICATION_FULL_REFRESH:
|
||||||
List<StatusBarNotification> activeNotifications = null;
|
List<StatusBarNotification> activeNotifications = null;
|
||||||
if (sIsConnected) {
|
if (sIsConnected) {
|
||||||
try {
|
activeNotifications = Arrays.stream(getActiveNotificationsSafely(null))
|
||||||
activeNotifications = Arrays.stream(getActiveNotifications())
|
.filter(this::notificationIsValidForUI)
|
||||||
.filter(this::notificationIsValidForUI)
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
} catch (SecurityException ex) {
|
|
||||||
Log.e(TAG, "SecurityException: failed to fetch notifications");
|
|
||||||
activeNotifications = new ArrayList<>();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
activeNotifications = new ArrayList<>();
|
activeNotifications = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -175,7 +171,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
}
|
}
|
||||||
case MSG_RANKING_UPDATE: {
|
case MSG_RANKING_UPDATE: {
|
||||||
String[] keys = ((RankingMap) message.obj).getOrderedKeys();
|
String[] keys = ((RankingMap) message.obj).getOrderedKeys();
|
||||||
for (StatusBarNotification sbn : getActiveNotifications(keys)) {
|
for (StatusBarNotification sbn : getActiveNotificationsSafely(keys)) {
|
||||||
updateGroupKeyIfNecessary(sbn);
|
updateGroupKeyIfNecessary(sbn);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -214,6 +210,16 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NonNull StatusBarNotification[] getActiveNotificationsSafely(@Nullable String[] keys) {
|
||||||
|
StatusBarNotification[] result = null;
|
||||||
|
try {
|
||||||
|
result = getActiveNotifications(keys);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
Log.e(TAG, "SecurityException: failed to fetch notifications");
|
||||||
|
}
|
||||||
|
return result == null ? new StatusBarNotification[0] : result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListenerConnected() {
|
public void onListenerConnected() {
|
||||||
super.onListenerConnected();
|
super.onListenerConnected();
|
||||||
@@ -313,9 +319,8 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public List<StatusBarNotification> getNotificationsForKeys(List<NotificationKeyData> keys) {
|
public List<StatusBarNotification> getNotificationsForKeys(List<NotificationKeyData> keys) {
|
||||||
StatusBarNotification[] notifications = getActiveNotifications(
|
return Arrays.asList(getActiveNotificationsSafely(
|
||||||
keys.stream().map(n -> n.notificationKey).toArray(String[]::new));
|
keys.stream().map(n -> n.notificationKey).toArray(String[]::new)));
|
||||||
return notifications == null ? Collections.emptyList() : Arrays.asList(notifications);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user