diff options
19 files changed, 98 insertions, 222 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java index 14abbdb6d33f..9c63d56d74da 100644 --- a/core/java/android/view/inputmethod/InputMethodSubtype.java +++ b/core/java/android/view/inputmethod/InputMethodSubtype.java @@ -71,7 +71,8 @@ public final class InputMethodSubtype implements Parcelable { // TODO: remove this private static final String EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME = "UntranslatableReplacementStringInSubtypeName"; - private static final int SUBTYPE_ID_NONE = 0; + /** {@hide} */ + public static final int SUBTYPE_ID_NONE = 0; private final boolean mIsAuxiliary; private final boolean mOverridesImplicitlyEnabledSubtype; diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 3463ed361516..1a915848e56c 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -40,11 +40,7 @@ import static android.os.storage.OnObbStateChangeListener.MOUNTED; import static android.os.storage.OnObbStateChangeListener.UNMOUNTED; import static android.os.storage.StorageManager.PROP_FORCED_SCOPED_STORAGE_WHITELIST; -import static com.android.internal.util.XmlUtils.readIntAttribute; -import static com.android.internal.util.XmlUtils.readLongAttribute; import static com.android.internal.util.XmlUtils.readStringAttribute; -import static com.android.internal.util.XmlUtils.writeIntAttribute; -import static com.android.internal.util.XmlUtils.writeLongAttribute; import static com.android.internal.util.XmlUtils.writeStringAttribute; import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; @@ -144,7 +140,6 @@ import com.android.internal.os.Zygote; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.DumpUtils; -import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.HexDump; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.Preconditions; @@ -160,9 +155,7 @@ import com.android.server.wm.ActivityTaskManagerInternal.ScreenObserver; import libcore.io.IoUtils; import libcore.util.EmptyArray; -import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileDescriptor; @@ -172,7 +165,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.math.BigInteger; -import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.spec.KeySpec; import java.util.ArrayList; @@ -2085,7 +2077,8 @@ class StorageManagerService extends IStorageManager.Stub } } - public static VolumeRecord readVolumeRecord(TypedXmlPullParser in) throws IOException { + public static VolumeRecord readVolumeRecord(TypedXmlPullParser in) + throws IOException, XmlPullParserException { final int type = in.getAttributeInt(null, ATTR_TYPE); final String fsUuid = readStringAttribute(in, ATTR_FS_UUID); final VolumeRecord meta = new VolumeRecord(type, fsUuid); diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 874495b0f48d..8e3597570a7b 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -4285,10 +4285,7 @@ public class AppOpsService extends IAppOpsService.Stub { throw new IllegalStateException("no start tag found"); } - final String versionString = parser.getAttributeValue(null, "v"); - if (versionString != null) { - oldVersion = Integer.parseInt(versionString); - } + oldVersion = parser.getAttributeInt(null, "v", NO_VERSION); int outerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT @@ -4458,7 +4455,8 @@ public class AppOpsService extends IAppOpsService.Stub { } private void readAttributionOp(TypedXmlPullParser parser, @NonNull Op parent, - @Nullable String attribution) throws NumberFormatException, IOException { + @Nullable String attribution) + throws NumberFormatException, IOException, XmlPullParserException { final AttributedOp attributedOp = parent.getOrCreateAttribution(parent, attribution); final long key = parser.getAttributeLong(null, "n"); diff --git a/services/core/java/com/android/server/appop/HistoricalRegistry.java b/services/core/java/com/android/server/appop/HistoricalRegistry.java index 45a347cb8ca2..676fcd0bdc87 100644 --- a/services/core/java/com/android/server/appop/HistoricalRegistry.java +++ b/services/core/java/com/android/server/appop/HistoricalRegistry.java @@ -1385,7 +1385,7 @@ final class HistoricalRegistry { private @Nullable HistoricalOps readStateDLocked(@Nullable HistoricalOps ops, int uid, @NonNull String packageName, @Nullable String attributionTag, int op, @NonNull TypedXmlPullParser parser, @OpFlags int filterFlags, double filterScale) - throws IOException { + throws IOException, XmlPullParserException { final long key = parser.getAttributeLong(null, ATTR_NAME); final int flags = AppOpsManager.extractFlagsFromKey(key) & filterFlags; if (flags == 0) { diff --git a/services/core/java/com/android/server/biometrics/sensors/face/FaceUserState.java b/services/core/java/com/android/server/biometrics/sensors/face/FaceUserState.java index 16b45610ae06..78e875b864f4 100644 --- a/services/core/java/com/android/server/biometrics/sensors/face/FaceUserState.java +++ b/services/core/java/com/android/server/biometrics/sensors/face/FaceUserState.java @@ -132,9 +132,9 @@ public class FaceUserState extends BiometricUserState<Face> { String tagName = parser.getName(); if (tagName.equals(TAG_FACE)) { String name = parser.getAttributeValue(null, ATTR_NAME); - String faceId = parser.getAttributeValue(null, ATTR_FACE_ID); - String deviceId = parser.getAttributeValue(null, ATTR_DEVICE_ID); - mBiometrics.add(new Face(name, Integer.parseInt(faceId), Integer.parseInt(deviceId))); + int faceId = parser.getAttributeInt(null, ATTR_FACE_ID); + int deviceId = parser.getAttributeInt(null, ATTR_DEVICE_ID); + mBiometrics.add(new Face(name, faceId, deviceId)); } } } diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintUserState.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintUserState.java index 54881594f41e..671e08bd8c56 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintUserState.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintUserState.java @@ -135,11 +135,10 @@ public class FingerprintUserState extends BiometricUserState<Fingerprint> { String tagName = parser.getName(); if (tagName.equals(TAG_FINGERPRINT)) { String name = parser.getAttributeValue(null, ATTR_NAME); - String groupId = parser.getAttributeValue(null, ATTR_GROUP_ID); - String fingerId = parser.getAttributeValue(null, ATTR_FINGER_ID); - String deviceId = parser.getAttributeValue(null, ATTR_DEVICE_ID); - mBiometrics.add(new Fingerprint(name, Integer.parseInt(groupId), - Integer.parseInt(fingerId), Long.parseLong(deviceId))); + int groupId = parser.getAttributeInt(null, ATTR_GROUP_ID); + int fingerId = parser.getAttributeInt(null, ATTR_FINGER_ID); + long deviceId = parser.getAttributeLong(null, ATTR_DEVICE_ID); + mBiometrics.add(new Fingerprint(name, groupId, fingerId, deviceId)); } } } diff --git a/services/core/java/com/android/server/content/SyncStorageEngine.java b/services/core/java/com/android/server/content/SyncStorageEngine.java index 24c60c164dc6..d27cb16ecc51 100644 --- a/services/core/java/com/android/server/content/SyncStorageEngine.java +++ b/services/core/java/com/android/server/content/SyncStorageEngine.java @@ -58,12 +58,10 @@ import android.util.proto.ProtoOutputStream; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; -import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.IntPair; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileInputStream; @@ -71,7 +69,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; @@ -1650,37 +1647,23 @@ public class SyncStorageEngine { String tagName = parser.getName(); if ("accounts".equals(tagName)) { - String listen = parser.getAttributeValue(null, XML_ATTR_LISTEN_FOR_TICKLES); - String versionString = parser.getAttributeValue(null, "version"); - int version; - try { - version = (versionString == null) ? 0 : Integer.parseInt(versionString); - } catch (NumberFormatException e) { - version = 0; - } + boolean listen = parser.getAttributeBoolean( + null, XML_ATTR_LISTEN_FOR_TICKLES, true); + int version = parser.getAttributeInt(null, "version", 0); if (version < 3) { mGrantSyncAdaptersAccountAccess = true; } - String nextIdString = parser.getAttributeValue(null, XML_ATTR_NEXT_AUTHORITY_ID); - try { - int id = (nextIdString == null) ? 0 : Integer.parseInt(nextIdString); - mNextAuthorityId = Math.max(mNextAuthorityId, id); - } catch (NumberFormatException e) { - // don't care - } - String offsetString = parser.getAttributeValue(null, XML_ATTR_SYNC_RANDOM_OFFSET); - try { - mSyncRandomOffset = (offsetString == null) ? 0 : Integer.parseInt(offsetString); - } catch (NumberFormatException e) { - mSyncRandomOffset = 0; - } + int nextId = parser.getAttributeInt(null, XML_ATTR_NEXT_AUTHORITY_ID, 0); + mNextAuthorityId = Math.max(mNextAuthorityId, nextId); + + mSyncRandomOffset = parser.getAttributeInt(null, XML_ATTR_SYNC_RANDOM_OFFSET, 0); if (mSyncRandomOffset == 0) { Random random = new Random(System.currentTimeMillis()); mSyncRandomOffset = random.nextInt(86400); } - mMasterSyncAutomatically.put(0, listen == null || Boolean.parseBoolean(listen)); + mMasterSyncAutomatically.put(0, listen); eventType = parser.next(); AuthorityInfo authority = null; PeriodicSync periodicSync = null; @@ -1805,22 +1788,18 @@ public class SyncStorageEngine { } private void parseListenForTickles(TypedXmlPullParser parser) { - String user = parser.getAttributeValue(null, XML_ATTR_USER); int userId = 0; try { - userId = Integer.parseInt(user); - } catch (NumberFormatException e) { + parser.getAttributeInt(null, XML_ATTR_USER); + } catch (XmlPullParserException e) { Slog.e(TAG, "error parsing the user for listen-for-tickles", e); - } catch (NullPointerException e) { - Slog.e(TAG, "the user in listen-for-tickles is null", e); } - String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED); - boolean listen = enabled == null || Boolean.parseBoolean(enabled); + boolean listen = parser.getAttributeBoolean(null, XML_ATTR_ENABLED, true); mMasterSyncAutomatically.put(userId, listen); } private AuthorityInfo parseAuthority(TypedXmlPullParser parser, int version, - AccountAuthorityValidator validator) { + AccountAuthorityValidator validator) throws XmlPullParserException { AuthorityInfo authority = null; int id = -1; try { @@ -1832,14 +1811,13 @@ public class SyncStorageEngine { } if (id >= 0) { String authorityName = parser.getAttributeValue(null, "authority"); - String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED); + boolean enabled = parser.getAttributeBoolean(null, XML_ATTR_ENABLED, true); String syncable = parser.getAttributeValue(null, "syncable"); String accountName = parser.getAttributeValue(null, "account"); String accountType = parser.getAttributeValue(null, "type"); - String user = parser.getAttributeValue(null, XML_ATTR_USER); + int userId = parser.getAttributeInt(null, XML_ATTR_USER, 0); String packageName = parser.getAttributeValue(null, "package"); String className = parser.getAttributeValue(null, "class"); - int userId = user == null ? 0 : Integer.parseInt(user); if (accountType == null && packageName == null) { accountType = "com.google"; syncable = String.valueOf(AuthorityInfo.NOT_INITIALIZED); @@ -1884,7 +1862,7 @@ public class SyncStorageEngine { } } if (authority != null) { - authority.enabled = enabled == null || Boolean.parseBoolean(enabled); + authority.enabled = enabled; try { authority.syncable = (syncable == null) ? AuthorityInfo.NOT_INITIALIZED : Integer.parseInt(syncable); @@ -1914,30 +1892,20 @@ public class SyncStorageEngine { */ private PeriodicSync parsePeriodicSync(TypedXmlPullParser parser, AuthorityInfo authorityInfo) { Bundle extras = new Bundle(); // Gets filled in later. - String periodValue = parser.getAttributeValue(null, "period"); - String flexValue = parser.getAttributeValue(null, "flex"); - final long period; + long period; long flextime; try { - period = Long.parseLong(periodValue); - } catch (NumberFormatException e) { + period = parser.getAttributeLong(null, "period"); + } catch (XmlPullParserException e) { Slog.e(TAG, "error parsing the period of a periodic sync", e); return null; - } catch (NullPointerException e) { - Slog.e(TAG, "the period of a periodic sync is null", e); - return null; } try { - flextime = Long.parseLong(flexValue); - } catch (NumberFormatException e) { - flextime = calculateDefaultFlexTime(period); - Slog.e(TAG, "Error formatting value parsed for periodic sync flex: " + flexValue - + ", using default: " - + flextime); - } catch (NullPointerException expected) { + flextime = parser.getAttributeLong(null, "flex"); + } catch (XmlPullParserException e) { flextime = calculateDefaultFlexTime(period); - Slog.d(TAG, "No flex time specified for this sync, using a default. period: " - + period + " flex: " + flextime); + Slog.e(TAG, "Error formatting value parsed for periodic sync flex, using default: " + + flextime, e); } PeriodicSync periodicSync; periodicSync = diff --git a/services/core/java/com/android/server/display/AmbientBrightnessStatsTracker.java b/services/core/java/com/android/server/display/AmbientBrightnessStatsTracker.java index 0bda26dacd65..0f1e6668ceec 100644 --- a/services/core/java/com/android/server/display/AmbientBrightnessStatsTracker.java +++ b/services/core/java/com/android/server/display/AmbientBrightnessStatsTracker.java @@ -27,17 +27,14 @@ import android.util.TypedXmlSerializer; import android.util.Xml; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.FastXmlSerializer; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.format.DateTimeParseException; import java.util.ArrayDeque; @@ -229,7 +226,7 @@ public class AmbientBrightnessStatsTracker { } tag = parser.getName(); if (TAG_AMBIENT_BRIGHTNESS_DAY_STATS.equals(tag)) { - String userSerialNumber = parser.getAttributeValue(null, ATTR_USER); + int userSerialNumber = parser.getAttributeInt(null, ATTR_USER); LocalDate localDate = LocalDate.parse( parser.getAttributeValue(null, ATTR_LOCAL_DATE)); String[] bucketBoundaries = parser.getAttributeValue(null, @@ -246,8 +243,7 @@ public class AmbientBrightnessStatsTracker { parsedBucketBoundaries[i] = Float.parseFloat(bucketBoundaries[i]); parsedBucketStats[i] = Float.parseFloat(bucketStats[i]); } - int userId = mInjector.getUserId(mUserManager, - Integer.parseInt(userSerialNumber)); + int userId = mInjector.getUserId(mUserManager, userSerialNumber); if (userId != -1 && localDate.isAfter(cutOffDate)) { Deque<AmbientBrightnessDayStats> userStats = getOrCreateUserStats( parsedStats, userId); diff --git a/services/core/java/com/android/server/display/BrightnessTracker.java b/services/core/java/com/android/server/display/BrightnessTracker.java index 049c8ab1c7be..2a0e21919704 100644 --- a/services/core/java/com/android/server/display/BrightnessTracker.java +++ b/services/core/java/com/android/server/display/BrightnessTracker.java @@ -633,22 +633,16 @@ public class BrightnessTracker { if (TAG_EVENT.equals(tag)) { BrightnessChangeEvent.Builder builder = new BrightnessChangeEvent.Builder(); - String brightness = parser.getAttributeValue(null, ATTR_NITS); - builder.setBrightness(Float.parseFloat(brightness)); - String timestamp = parser.getAttributeValue(null, ATTR_TIMESTAMP); - builder.setTimeStamp(Long.parseLong(timestamp)); + builder.setBrightness(parser.getAttributeFloat(null, ATTR_NITS)); + builder.setTimeStamp(parser.getAttributeLong(null, ATTR_TIMESTAMP)); builder.setPackageName(parser.getAttributeValue(null, ATTR_PACKAGE_NAME)); - String user = parser.getAttributeValue(null, ATTR_USER); - builder.setUserId(mInjector.getUserId(mUserManager, Integer.parseInt(user))); - String batteryLevel = parser.getAttributeValue(null, ATTR_BATTERY_LEVEL); - builder.setBatteryLevel(Float.parseFloat(batteryLevel)); - String nightMode = parser.getAttributeValue(null, ATTR_NIGHT_MODE); - builder.setNightMode(Boolean.parseBoolean(nightMode)); - String colorTemperature = - parser.getAttributeValue(null, ATTR_COLOR_TEMPERATURE); - builder.setColorTemperature(Integer.parseInt(colorTemperature)); - String lastBrightness = parser.getAttributeValue(null, ATTR_LAST_NITS); - builder.setLastBrightness(Float.parseFloat(lastBrightness)); + builder.setUserId(mInjector.getUserId(mUserManager, + parser.getAttributeInt(null, ATTR_USER))); + builder.setBatteryLevel(parser.getAttributeFloat(null, ATTR_BATTERY_LEVEL)); + builder.setNightMode(parser.getAttributeBoolean(null, ATTR_NIGHT_MODE)); + builder.setColorTemperature( + parser.getAttributeInt(null, ATTR_COLOR_TEMPERATURE)); + builder.setLastBrightness(parser.getAttributeFloat(null, ATTR_LAST_NITS)); String luxValue = parser.getAttributeValue(null, ATTR_LUX); String luxTimestamp = parser.getAttributeValue(null, ATTR_LUX_TIMESTAMPS); @@ -667,20 +661,12 @@ public class BrightnessTracker { builder.setLuxValues(luxValues); builder.setLuxTimestamps(luxTimestamps); - String defaultConfig = parser.getAttributeValue(null, ATTR_DEFAULT_CONFIG); - if (defaultConfig != null) { - builder.setIsDefaultBrightnessConfig(Boolean.parseBoolean(defaultConfig)); - } - String powerSave = parser.getAttributeValue(null, ATTR_POWER_SAVE); - if (powerSave != null) { - builder.setPowerBrightnessFactor(Float.parseFloat(powerSave)); - } else { - builder.setPowerBrightnessFactor(1.0f); - } - String userPoint = parser.getAttributeValue(null, ATTR_USER_POINT); - if (userPoint != null) { - builder.setUserBrightnessPoint(Boolean.parseBoolean(userPoint)); - } + builder.setIsDefaultBrightnessConfig( + parser.getAttributeBoolean(null, ATTR_DEFAULT_CONFIG, false)); + builder.setPowerBrightnessFactor( + parser.getAttributeFloat(null, ATTR_POWER_SAVE, 1.0f)); + builder.setUserBrightnessPoint( + parser.getAttributeBoolean(null, ATTR_USER_POINT, false)); String colorSampleDurationString = parser.getAttributeValue(null, ATTR_COLOR_SAMPLE_DURATION); diff --git a/services/core/java/com/android/server/inputmethod/AdditionalSubtypeUtils.java b/services/core/java/com/android/server/inputmethod/AdditionalSubtypeUtils.java index 8129401300a2..24b8e340dee9 100644 --- a/services/core/java/com/android/server/inputmethod/AdditionalSubtypeUtils.java +++ b/services/core/java/com/android/server/inputmethod/AdditionalSubtypeUtils.java @@ -31,17 +31,13 @@ import android.util.Xml; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; -import com.android.internal.util.FastXmlSerializer; - import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -264,10 +260,10 @@ final class AdditionalSubtypeUtils { .setSubtypeExtraValue(imeSubtypeExtraValue) .setIsAuxiliary(isAuxiliary) .setIsAsciiCapable(isAsciiCapable); - final String subtypeIdString = - parser.getAttributeValue(null, ATTR_IME_SUBTYPE_ID); - if (subtypeIdString != null) { - builder.setSubtypeId(Integer.parseInt(subtypeIdString)); + final int subtypeId = parser.getAttributeInt(null, ATTR_IME_SUBTYPE_ID, + InputMethodSubtype.SUBTYPE_ID_NONE); + if (subtypeId != InputMethodSubtype.SUBTYPE_ID_NONE) { + builder.setSubtypeId(subtypeId); } tempSubtypesArray.add(builder.build()); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index f3b1f2beae57..76b9c8619cfc 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -788,9 +788,8 @@ public class NotificationManagerService extends SystemService { if (forRestore && userId != UserHandle.USER_SYSTEM) { continue; } - mLockScreenAllowSecureNotifications = - safeBoolean(parser.getAttributeValue(null, - LOCKSCREEN_ALLOW_SECURE_NOTIFICATIONS_VALUE), true); + mLockScreenAllowSecureNotifications = parser.getAttributeBoolean(null, + LOCKSCREEN_ALLOW_SECURE_NOTIFICATIONS_VALUE, true); } } @@ -10125,11 +10124,6 @@ public class NotificationManagerService extends SystemService { out.endTag(null, LOCKSCREEN_ALLOW_SECURE_NOTIFICATIONS_TAG); } - private static boolean safeBoolean(String val, boolean defValue) { - if (TextUtils.isEmpty(val)) return defValue; - return Boolean.parseBoolean(val); - } - /** * Shows a warning on logcat. Shows the toast only once per package. This is to avoid being too * aggressive and annoying the user. diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index b549f3aabd47..1c0349d1b51f 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -204,14 +204,8 @@ public class PreferencesHelper implements RankingConfig { String tag = parser.getName(); if (!TAG_RANKING.equals(tag)) return; - boolean upgradeForBubbles = false; - if (parser.getAttributeCount() > 0) { - String attribute = parser.getAttributeName(0); - if (ATT_VERSION.equals(attribute)) { - int xmlVersion = Integer.parseInt(parser.getAttributeValue(0)); - upgradeForBubbles = xmlVersion == XML_VERSION_BUBBLES_UPGRADE; - } - } + final int xmlVersion = parser.getAttributeInt(null, ATT_VERSION, -1); + boolean upgradeForBubbles = xmlVersion == XML_VERSION_BUBBLES_UPGRADE; synchronized (mPackagePreferences) { while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { tag = parser.getName(); diff --git a/services/core/java/com/android/server/notification/SnoozeHelper.java b/services/core/java/com/android/server/notification/SnoozeHelper.java index aa8f3d5b6871..b5ca2abf8afe 100644 --- a/services/core/java/com/android/server/notification/SnoozeHelper.java +++ b/services/core/java/com/android/server/notification/SnoozeHelper.java @@ -59,7 +59,7 @@ import java.util.Set; * NotificationManagerService helper for handling snoozed notifications. */ public class SnoozeHelper { - public static final String XML_SNOOZED_NOTIFICATION_VERSION = "1"; + public static final int XML_SNOOZED_NOTIFICATION_VERSION = 1; protected static final String XML_TAG_NAME = "snoozed-notifications"; @@ -598,14 +598,11 @@ public class SnoozeHelper { attributeInserter.insert(value); - out.attribute(null, XML_SNOOZED_NOTIFICATION_VERSION_LABEL, + out.attributeInt(null, XML_SNOOZED_NOTIFICATION_VERSION_LABEL, XML_SNOOZED_NOTIFICATION_VERSION); out.attribute(null, XML_SNOOZED_NOTIFICATION_KEY, key); - - out.attribute(null, XML_SNOOZED_NOTIFICATION_PKG, pkg); - out.attribute(null, XML_SNOOZED_NOTIFICATION_USER_ID, - String.valueOf(userId)); + out.attributeInt(null, XML_SNOOZED_NOTIFICATION_USER_ID, userId); out.endTag(null, tag); } @@ -624,8 +621,8 @@ public class SnoozeHelper { if (type == XmlPullParser.START_TAG && (XML_SNOOZED_NOTIFICATION.equals(tag) || tag.equals(XML_SNOOZED_NOTIFICATION_CONTEXT)) - && parser.getAttributeValue(null, XML_SNOOZED_NOTIFICATION_VERSION_LABEL) - .equals(XML_SNOOZED_NOTIFICATION_VERSION)) { + && parser.getAttributeInt(null, XML_SNOOZED_NOTIFICATION_VERSION_LABEL, -1) + == XML_SNOOZED_NOTIFICATION_VERSION) { try { final String key = parser.getAttributeValue(null, XML_SNOOZED_NOTIFICATION_KEY); final String pkg = parser.getAttributeValue(null, XML_SNOOZED_NOTIFICATION_PKG); diff --git a/services/core/java/com/android/server/om/OverlayManagerSettings.java b/services/core/java/com/android/server/om/OverlayManagerSettings.java index 83a97b124649..0613dff31da5 100644 --- a/services/core/java/com/android/server/om/OverlayManagerSettings.java +++ b/services/core/java/com/android/server/om/OverlayManagerSettings.java @@ -446,7 +446,7 @@ final class OverlayManagerSettings { } private static SettingsItem restoreRow(@NonNull final TypedXmlPullParser parser, - final int depth) throws IOException { + final int depth) throws IOException, XmlPullParserException { final String packageName = XmlUtils.readStringAttribute(parser, ATTR_PACKAGE_NAME); final int userId = parser.getAttributeInt(null, ATTR_USER_ID); final String targetPackageName = XmlUtils.readStringAttribute(parser, diff --git a/services/core/java/com/android/server/storage/CacheQuotaStrategy.java b/services/core/java/com/android/server/storage/CacheQuotaStrategy.java index cea7fd395796..4f3101dc318c 100644 --- a/services/core/java/com/android/server/storage/CacheQuotaStrategy.java +++ b/services/core/java/com/android/server/storage/CacheQuotaStrategy.java @@ -51,13 +51,10 @@ import android.util.TypedXmlSerializer; import android.util.Xml; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.FastXmlSerializer; -import com.android.internal.util.Preconditions; import com.android.server.pm.Installer; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileInputStream; @@ -65,7 +62,6 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -395,7 +391,7 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { long bytes = parser.getAttributeLong(null, ATTR_QUOTA_IN_BYTES); return new CacheQuotaHint.Builder() .setVolumeUuid(uuid).setUid(uid).setQuota(bytes).build(); - } catch (NumberFormatException e) { + } catch (XmlPullParserException e) { Slog.e(TAG, "Invalid cache quota request, skipping."); return null; } diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index d07aaaa8ecaa..bbe86beceb82 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -3025,11 +3025,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } private int getAttributeInt(TypedXmlPullParser parser, String name, int defValue) { - String value = parser.getAttributeValue(null, name); - if (value == null) { - return defValue; - } - return Integer.parseInt(value); + return parser.getAttributeInt(null, name, defValue); } /** @@ -3210,10 +3206,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } private void parseWallpaperAttributes(TypedXmlPullParser parser, WallpaperData wallpaper, - boolean keepDimensionHints) { - final String idString = parser.getAttributeValue(null, "id"); - if (idString != null) { - final int id = wallpaper.wallpaperId = Integer.parseInt(idString); + boolean keepDimensionHints) throws XmlPullParserException { + final int id = parser.getAttributeInt(null, "id", -1); + if (id != -1) { + wallpaper.wallpaperId = id; if (id > mWallpaperId) { mWallpaperId = id; } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 1b0d92bf7f5b..05e7ba2edd0d 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -18,7 +18,6 @@ package com.android.server.wm; import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; import static android.app.ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; -import static android.app.ActivityManager.TaskDescription.ATTR_TASKDESCRIPTION_PREFIX; import static android.app.ActivityOptions.ANIM_CLIP_REVEAL; import static android.app.ActivityOptions.ANIM_CUSTOM; import static android.app.ActivityOptions.ANIM_NONE; @@ -96,18 +95,18 @@ import static android.view.Display.COLOR_MODE_DEFAULT; import static android.view.Display.INVALID_DISPLAY; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; +import static android.view.WindowManager.TRANSIT_CLOSE; +import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE; +import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE; +import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN_BEHIND; +import static android.view.WindowManager.TRANSIT_OLD_UNSET; import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; -import static android.view.WindowManager.TRANSIT_CLOSE; import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND; -import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE; -import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE; -import static android.view.WindowManager.TRANSIT_OLD_UNSET; -import static android.view.WindowManager.TransitionOldType; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; @@ -183,6 +182,7 @@ import static com.android.server.wm.IdentifierProto.USER_ID; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION; +import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE; import static com.android.server.wm.Task.ActivityState.DESTROYED; import static com.android.server.wm.Task.ActivityState.DESTROYING; import static com.android.server.wm.Task.ActivityState.FINISHING; @@ -194,7 +194,6 @@ import static com.android.server.wm.Task.ActivityState.RESUMED; import static com.android.server.wm.Task.ActivityState.STARTED; import static com.android.server.wm.Task.ActivityState.STOPPED; import static com.android.server.wm.Task.ActivityState.STOPPING; -import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE; import static com.android.server.wm.TaskPersister.DEBUG; import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; @@ -293,6 +292,7 @@ import android.view.SurfaceControl.Transaction; import android.view.WindowInsets.Type; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; +import android.view.WindowManager.TransitionOldType; import android.view.animation.Animation; import android.window.WindowContainerToken; @@ -322,9 +322,7 @@ import com.android.server.wm.utils.InsetUtils; import com.google.android.collect.Sets; -import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.IOException; @@ -7500,39 +7498,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A ActivityTaskSupervisor taskSupervisor) throws IOException, XmlPullParserException { Intent intent = null; PersistableBundle persistentState = null; - int launchedFromUid = 0; - String launchedFromPackage = null; - String launchedFromFeature = null; - String resolvedType = null; - boolean componentSpecified = false; - int userId = 0; - long createTime = -1; + int launchedFromUid = in.getAttributeInt(null, ATTR_LAUNCHEDFROMUID, 0); + String launchedFromPackage = in.getAttributeValue(null, ATTR_LAUNCHEDFROMPACKAGE); + String launchedFromFeature = in.getAttributeValue(null, ATTR_LAUNCHEDFROMFEATURE); + String resolvedType = in.getAttributeValue(null, ATTR_RESOLVEDTYPE); + boolean componentSpecified = in.getAttributeBoolean(null, ATTR_COMPONENTSPECIFIED, false); + int userId = in.getAttributeInt(null, ATTR_USERID, 0); + long createTime = in.getAttributeLong(null, ATTR_ID, -1); final int outerDepth = in.getDepth(); - TaskDescription taskDescription = new TaskDescription(); - for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { - final String attrName = in.getAttributeName(attrNdx); - final String attrValue = in.getAttributeValue(attrNdx); - if (DEBUG) Slog.d(TaskPersister.TAG, - "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); - if (ATTR_ID.equals(attrName)) { - createTime = Long.parseLong(attrValue); - } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { - launchedFromUid = Integer.parseInt(attrValue); - } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { - launchedFromPackage = attrValue; - } else if (ATTR_LAUNCHEDFROMFEATURE.equals(attrName)) { - launchedFromFeature = attrValue; - } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { - resolvedType = attrValue; - } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { - componentSpecified = Boolean.parseBoolean(attrValue); - } else if (ATTR_USERID.equals(attrName)) { - userId = Integer.parseInt(attrValue); - } else if (!attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) { - Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); - } - } + TaskDescription taskDescription = new TaskDescription(); taskDescription.restoreFromXml(in); int event; diff --git a/services/core/java/com/android/server/wm/CompatModePackages.java b/services/core/java/com/android/server/wm/CompatModePackages.java index f4409727d7da..4b349542e347 100644 --- a/services/core/java/com/android/server/wm/CompatModePackages.java +++ b/services/core/java/com/android/server/wm/CompatModePackages.java @@ -43,7 +43,6 @@ import com.android.internal.protolog.common.ProtoLog; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; import java.io.File; import java.io.FileInputStream; @@ -113,14 +112,7 @@ public final class CompatModePackages { if ("pkg".equals(tagName)) { String pkg = parser.getAttributeValue(null, "name"); if (pkg != null) { - String mode = parser.getAttributeValue(null, "mode"); - int modeInt = 0; - if (mode != null) { - try { - modeInt = Integer.parseInt(mode); - } catch (NumberFormatException e) { - } - } + int modeInt = parser.getAttributeInt(null, "mode", 0); mPackages.put(pkg, modeInt); } } diff --git a/services/core/java/com/android/server/wm/DisplayWindowSettingsProvider.java b/services/core/java/com/android/server/wm/DisplayWindowSettingsProvider.java index a5a6b4dc6950..aa603aba0f78 100644 --- a/services/core/java/com/android/server/wm/DisplayWindowSettingsProvider.java +++ b/services/core/java/com/android/server/wm/DisplayWindowSettingsProvider.java @@ -336,23 +336,15 @@ class DisplayWindowSettingsProvider implements SettingsProvider { } private static int getIntAttribute(TypedXmlPullParser parser, String name, int defaultValue) { - try { - final String str = parser.getAttributeValue(null, name); - return str != null ? Integer.parseInt(str) : defaultValue; - } catch (NumberFormatException e) { - Slog.w(TAG, "Failed to parse display window settings attribute: " + name, e); - return defaultValue; - } + return parser.getAttributeInt(null, name, defaultValue); } @Nullable private static Integer getIntegerAttribute(TypedXmlPullParser parser, String name, @Nullable Integer defaultValue) { try { - final String str = parser.getAttributeValue(null, name); - return str != null ? Integer.valueOf(str) : defaultValue; - } catch (NumberFormatException e) { - Slog.w(TAG, "Failed to parse display window settings attribute: " + name, e); + return parser.getAttributeInt(null, name); + } catch (Exception ignored) { return defaultValue; } } @@ -360,8 +352,11 @@ class DisplayWindowSettingsProvider implements SettingsProvider { @Nullable private static Boolean getBooleanAttribute(TypedXmlPullParser parser, String name, @Nullable Boolean defaultValue) { - final String str = parser.getAttributeValue(null, name); - return str != null ? Boolean.valueOf(str) : defaultValue; + try { + return parser.getAttributeBoolean(null, name); + } catch (Exception ignored) { + return defaultValue; + } } private static void readDisplay(TypedXmlPullParser parser, FileData fileData) |