Merge "Log errors on history load" into rvc-dev am: d27d2b375e
am: f77db13ff8
Change-Id: I2c921a91564d672b6705668251486ff0b700e198
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
@@ -33,6 +34,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HistoryLoader {
|
public class HistoryLoader {
|
||||||
|
private static final String TAG = "HistoryLoader";
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final NotificationBackend mBackend;
|
private final NotificationBackend mBackend;
|
||||||
private final PackageManager mPm;
|
private final PackageManager mPm;
|
||||||
@@ -45,45 +47,48 @@ public class HistoryLoader {
|
|||||||
|
|
||||||
public void load(OnHistoryLoaderListener listener) {
|
public void load(OnHistoryLoaderListener listener) {
|
||||||
ThreadUtils.postOnBackgroundThread(() -> {
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
Map<String, NotificationHistoryPackage> historicalNotifications = new HashMap<>();
|
try {
|
||||||
NotificationHistory history =
|
Map<String, NotificationHistoryPackage> historicalNotifications = new HashMap<>();
|
||||||
mBackend.getNotificationHistory(mContext.getPackageName());
|
NotificationHistory history =
|
||||||
|
mBackend.getNotificationHistory(mContext.getPackageName());
|
||||||
|
while (history.hasNextNotification()) {
|
||||||
|
HistoricalNotification hn = history.getNextNotification();
|
||||||
|
|
||||||
while (history.hasNextNotification()) {
|
String key = hn.getPackage() + "|" + hn.getUid();
|
||||||
HistoricalNotification hn = history.getNextNotification();
|
NotificationHistoryPackage hnsForPackage = historicalNotifications.getOrDefault(
|
||||||
|
key,
|
||||||
String key = hn.getPackage() + "|" + hn.getUid();
|
new NotificationHistoryPackage(hn.getPackage(), hn.getUid()));
|
||||||
NotificationHistoryPackage hnsForPackage = historicalNotifications.getOrDefault(
|
hnsForPackage.notifications.add(hn);
|
||||||
key,
|
historicalNotifications.put(key, hnsForPackage);
|
||||||
new NotificationHistoryPackage(hn.getPackage(), hn.getUid()));
|
|
||||||
hnsForPackage.notifications.add(hn);
|
|
||||||
historicalNotifications.put(key, hnsForPackage);
|
|
||||||
}
|
|
||||||
List<NotificationHistoryPackage> packages =
|
|
||||||
new ArrayList<>(historicalNotifications.values());
|
|
||||||
Collections.sort(packages,
|
|
||||||
(o1, o2) -> -1 * Long.compare(o1.getMostRecent(), o2.getMostRecent()));
|
|
||||||
for (NotificationHistoryPackage nhp : packages) {
|
|
||||||
ApplicationInfo info;
|
|
||||||
try {
|
|
||||||
info = mPm.getApplicationInfoAsUser(
|
|
||||||
nhp.pkgName,
|
|
||||||
PackageManager.MATCH_UNINSTALLED_PACKAGES
|
|
||||||
| PackageManager.MATCH_DISABLED_COMPONENTS
|
|
||||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
|
||||||
| PackageManager.MATCH_DIRECT_BOOT_AWARE,
|
|
||||||
UserHandle.getUserId(nhp.uid));
|
|
||||||
if (info != null) {
|
|
||||||
nhp.label = String.valueOf(mPm.getApplicationLabel(info));
|
|
||||||
nhp.icon = mPm.getUserBadgedIcon(mPm.getApplicationIcon(info),
|
|
||||||
UserHandle.of(UserHandle.getUserId(nhp.uid)));
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
// app is gone, just show package name and generic icon
|
|
||||||
nhp.icon = mPm.getDefaultActivityIcon();
|
|
||||||
}
|
}
|
||||||
|
List<NotificationHistoryPackage> packages =
|
||||||
|
new ArrayList<>(historicalNotifications.values());
|
||||||
|
Collections.sort(packages,
|
||||||
|
(o1, o2) -> -1 * Long.compare(o1.getMostRecent(), o2.getMostRecent()));
|
||||||
|
for (NotificationHistoryPackage nhp : packages) {
|
||||||
|
ApplicationInfo info;
|
||||||
|
try {
|
||||||
|
info = mPm.getApplicationInfoAsUser(
|
||||||
|
nhp.pkgName,
|
||||||
|
PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
|
| PackageManager.MATCH_DISABLED_COMPONENTS
|
||||||
|
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
||||||
|
| PackageManager.MATCH_DIRECT_BOOT_AWARE,
|
||||||
|
UserHandle.getUserId(nhp.uid));
|
||||||
|
if (info != null) {
|
||||||
|
nhp.label = String.valueOf(mPm.getApplicationLabel(info));
|
||||||
|
nhp.icon = mPm.getUserBadgedIcon(mPm.getApplicationIcon(info),
|
||||||
|
UserHandle.of(UserHandle.getUserId(nhp.uid)));
|
||||||
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
// app is gone, just show package name and generic icon
|
||||||
|
nhp.icon = mPm.getDefaultActivityIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ThreadUtils.postOnMainThread(() -> listener.onHistoryLoaded(packages));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Slog.e(TAG, "Error loading history", e);
|
||||||
}
|
}
|
||||||
ThreadUtils.postOnMainThread(() -> listener.onHistoryLoaded(packages));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user