Merge "Add some extra exception catching/logging to readxml" into tm-dev am: 2ca31b10ab

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18094505

Change-Id: I865d3af0d3a42e0eff4c8b7cd825b7b564ea5c54
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-05-03 05:08:18 +00:00
committed by Automerger Merge Worker

View File

@@ -243,9 +243,32 @@ public class PreferencesHelper implements RankingConfig {
mHideSilentStatusBarIcons = parser.getAttributeBoolean(null, mHideSilentStatusBarIcons = parser.getAttributeBoolean(null,
ATT_HIDE_SILENT, DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS); ATT_HIDE_SILENT, DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS);
} else if (TAG_PACKAGE.equals(tag)) { } else if (TAG_PACKAGE.equals(tag)) {
int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
String name = parser.getAttributeValue(null, ATT_NAME); String name = parser.getAttributeValue(null, ATT_NAME);
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
restorePackage(parser, forRestore, userId, name, upgradeForBubbles,
migrateToPermission, pkgPerms);
}
}
}
}
}
if (migrateToPermission) {
for (PackagePermission p : pkgPerms) {
try {
mPermissionHelper.setNotificationPermission(p);
} catch (Exception e) {
Slog.e(TAG, "could not migrate setting for " + p.packageName, e);
}
}
}
}
@GuardedBy("mPackagePreferences")
private void restorePackage(TypedXmlPullParser parser, boolean forRestore,
@UserIdInt int userId, String name, boolean upgradeForBubbles,
boolean migrateToPermission, ArrayList<PermissionHelper.PackagePermission> pkgPerms) {
try {
int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
if (forRestore) { if (forRestore) {
try { try {
uid = mPm.getPackageUidAsUser(name, userId); uid = mPm.getPackageUidAsUser(name, userId);
@@ -263,37 +286,29 @@ public class PreferencesHelper implements RankingConfig {
} }
int bubblePref = hasSAWPermission int bubblePref = hasSAWPermission
? BUBBLE_PREFERENCE_ALL ? BUBBLE_PREFERENCE_ALL
: parser.getAttributeInt( : parser.getAttributeInt(null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE);
null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE); int appImportance = parser.getAttributeInt(null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
int appImportance = parser.getAttributeInt(
null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
PackagePreferences r = getOrCreatePackagePreferencesLocked( PackagePreferences r = getOrCreatePackagePreferencesLocked(
name, userId, uid, name, userId, uid,
appImportance, appImportance,
parser.getAttributeInt( parser.getAttributeInt(null, ATT_PRIORITY, DEFAULT_PRIORITY),
null, ATT_PRIORITY, DEFAULT_PRIORITY), parser.getAttributeInt(null, ATT_VISIBILITY, DEFAULT_VISIBILITY),
parser.getAttributeInt( parser.getAttributeBoolean(null, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE),
null, ATT_VISIBILITY, DEFAULT_VISIBILITY),
parser.getAttributeBoolean(
null, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE),
bubblePref); bubblePref);
r.priority = parser.getAttributeInt( r.priority = parser.getAttributeInt(null, ATT_PRIORITY, DEFAULT_PRIORITY);
null, ATT_PRIORITY, DEFAULT_PRIORITY); r.visibility = parser.getAttributeInt(null, ATT_VISIBILITY, DEFAULT_VISIBILITY);
r.visibility = parser.getAttributeInt( r.showBadge = parser.getAttributeBoolean(null, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE);
null, ATT_VISIBILITY, DEFAULT_VISIBILITY); r.lockedAppFields = parser.getAttributeInt(null,
r.showBadge = parser.getAttributeBoolean( ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS);
null, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE); r.hasSentInvalidMessage = parser.getAttributeBoolean(null, ATT_SENT_INVALID_MESSAGE,
r.lockedAppFields = parser.getAttributeInt( false);
null, ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS); r.hasSentValidMessage = parser.getAttributeBoolean(null, ATT_SENT_VALID_MESSAGE, false);
r.hasSentInvalidMessage = parser.getAttributeBoolean(
null, ATT_SENT_INVALID_MESSAGE, false);
r.hasSentValidMessage = parser.getAttributeBoolean(
null, ATT_SENT_VALID_MESSAGE, false);
r.userDemotedMsgApp = parser.getAttributeBoolean( r.userDemotedMsgApp = parser.getAttributeBoolean(
null, ATT_USER_DEMOTED_INVALID_MSG_APP, false); null, ATT_USER_DEMOTED_INVALID_MSG_APP, false);
final int innerDepth = parser.getDepth(); final int innerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG && (type != XmlPullParser.END_TAG
|| parser.getDepth() > innerDepth)) { || parser.getDepth() > innerDepth)) {
@@ -306,18 +321,16 @@ public class PreferencesHelper implements RankingConfig {
if (TAG_GROUP.equals(tagName)) { if (TAG_GROUP.equals(tagName)) {
if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) { if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) {
if (!skipGroupWarningLogged) { if (!skipGroupWarningLogged) {
Slog.w(TAG, "Skipping further groups for " + r.pkg Slog.w(TAG, "Skipping further groups for " + r.pkg);
+ "; app has too many");
skipGroupWarningLogged = true; skipGroupWarningLogged = true;
} }
continue; continue;
} }
String id = parser.getAttributeValue(null, ATT_ID); String id = parser.getAttributeValue(null, ATT_ID);
CharSequence groupName = parser.getAttributeValue(null, CharSequence groupName = parser.getAttributeValue(null, ATT_NAME);
ATT_NAME);
if (!TextUtils.isEmpty(id)) { if (!TextUtils.isEmpty(id)) {
NotificationChannelGroup group NotificationChannelGroup group =
= new NotificationChannelGroup(id, groupName); new NotificationChannelGroup(id, groupName);
group.populateFromXml(parser); group.populateFromXml(parser);
r.groups.put(id, group); r.groups.put(id, group);
} }
@@ -326,57 +339,25 @@ public class PreferencesHelper implements RankingConfig {
if (TAG_CHANNEL.equals(tagName)) { if (TAG_CHANNEL.equals(tagName)) {
if (r.channels.size() >= NOTIFICATION_CHANNEL_COUNT_LIMIT) { if (r.channels.size() >= NOTIFICATION_CHANNEL_COUNT_LIMIT) {
if (!skipWarningLogged) { if (!skipWarningLogged) {
Slog.w(TAG, "Skipping further channels for " + r.pkg Slog.w(TAG, "Skipping further channels for " + r.pkg);
+ "; app has too many");
skipWarningLogged = true; skipWarningLogged = true;
} }
continue; continue;
} }
String id = parser.getAttributeValue(null, ATT_ID); restoreChannel(parser, forRestore, r);
String channelName = parser.getAttributeValue(null, ATT_NAME);
int channelImportance = parser.getAttributeInt(
null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(channelName)) {
NotificationChannel channel = new NotificationChannel(id,
channelName, channelImportance);
if (forRestore) {
channel.populateFromXmlForRestore(parser, mContext);
} else {
channel.populateFromXml(parser);
}
if (!mPermissionHelper.isMigrationEnabled()) {
channel.setImportanceLockedByCriticalDeviceFunction(
r.defaultAppLockedImportance);
channel.setImportanceLockedByOEM(r.oemLockedImportance);
if (!channel.isImportanceLockedByOEM()) {
if (r.oemLockedChannels.contains(channel.getId())) {
channel.setImportanceLockedByOEM(true);
}
}
}
if (isShortcutOk(channel) && isDeletionOk(channel)) {
r.channels.put(id, channel);
}
}
} }
// Delegate // Delegate
if (TAG_DELEGATE.equals(tagName)) { if (TAG_DELEGATE.equals(tagName)) {
int delegateId = int delegateId = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID); String delegateName = XmlUtils.readStringAttribute(parser, ATT_NAME);
String delegateName =
XmlUtils.readStringAttribute(parser, ATT_NAME);
boolean delegateEnabled = parser.getAttributeBoolean( boolean delegateEnabled = parser.getAttributeBoolean(
null, ATT_ENABLED, Delegate.DEFAULT_ENABLED); null, ATT_ENABLED, Delegate.DEFAULT_ENABLED);
boolean userAllowed = parser.getAttributeBoolean( boolean userAllowed = parser.getAttributeBoolean(
null, ATT_USER_ALLOWED, Delegate.DEFAULT_USER_ALLOWED); null, ATT_USER_ALLOWED, Delegate.DEFAULT_USER_ALLOWED);
Delegate d = null; Delegate d = null;
if (delegateId != UNKNOWN_UID && !TextUtils.isEmpty( if (delegateId != UNKNOWN_UID && !TextUtils.isEmpty(delegateName)) {
delegateName)) { d = new Delegate(delegateName, delegateId, delegateEnabled, userAllowed);
d = new Delegate(
delegateName, delegateId, delegateEnabled,
userAllowed);
} }
r.delegate = d; r.delegate = d;
} }
@@ -403,19 +384,44 @@ public class PreferencesHelper implements RankingConfig {
} else if (!mPermissionHelper.isMigrationEnabled()) { } else if (!mPermissionHelper.isMigrationEnabled()) {
r.importance = appImportance; r.importance = appImportance;
} }
}
}
}
}
}
if (migrateToPermission) {
for (PackagePermission p : pkgPerms) {
try {
mPermissionHelper.setNotificationPermission(p);
} catch (Exception e) { } catch (Exception e) {
Slog.e(TAG, "could not migrate setting for " + p.packageName, e); Slog.w(TAG, "Failed to restore pkg", e);
} }
} }
@GuardedBy("mPackagePreferences")
private void restoreChannel(TypedXmlPullParser parser, boolean forRestore,
PackagePreferences r) {
try {
String id = parser.getAttributeValue(null, ATT_ID);
String channelName = parser.getAttributeValue(null, ATT_NAME);
int channelImportance = parser.getAttributeInt(
null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(channelName)) {
NotificationChannel channel = new NotificationChannel(
id, channelName, channelImportance);
if (forRestore) {
channel.populateFromXmlForRestore(parser, mContext);
} else {
channel.populateFromXml(parser);
}
if (!mPermissionHelper.isMigrationEnabled()) {
channel.setImportanceLockedByCriticalDeviceFunction(
r.defaultAppLockedImportance);
channel.setImportanceLockedByOEM(r.oemLockedImportance);
if (!channel.isImportanceLockedByOEM()) {
if (r.oemLockedChannels.contains(channel.getId())) {
channel.setImportanceLockedByOEM(true);
}
}
}
if (isShortcutOk(channel) && isDeletionOk(channel)) {
r.channels.put(id, channel);
}
}
} catch (Exception e) {
Slog.w(TAG, "could not restore channel for " + r.pkg, e);
} }
} }
@@ -2591,8 +2597,8 @@ public class PreferencesHelper implements RankingConfig {
} }
} }
updated = true; updated = true;
} catch (PackageManager.NameNotFoundException e) { } catch (Exception e) {
// noop Slog.e(TAG, "could not restore " + r.pkg, e);
} }
} }
// Package upgrade // Package upgrade