Remove unnecessary allocation+unboxing of objects.

Transforming String->int can be done with 0 allocations
using Integer.parseInt.

bug: 28078871
Change-Id: I8d9f322d7154728849dde61ef282046032858d60
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index e5fe03a..40d44b4 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -1747,7 +1747,7 @@
         if(restoreDefaultNetworkDelayStr != null &&
                 restoreDefaultNetworkDelayStr.length() != 0) {
             try {
-                return Integer.valueOf(restoreDefaultNetworkDelayStr);
+                return Integer.parseInt(restoreDefaultNetworkDelayStr);
             } catch (NumberFormatException e) {
             }
         }
diff --git a/services/core/java/com/android/server/DockObserver.java b/services/core/java/com/android/server/DockObserver.java
index 5388f10..07aa5656 100644
--- a/services/core/java/com/android/server/DockObserver.java
+++ b/services/core/java/com/android/server/DockObserver.java
@@ -106,7 +106,7 @@
                 FileReader file = new FileReader(DOCK_STATE_PATH);
                 try {
                     int len = file.read(buffer, 0, 1024);
-                    setActualDockStateLocked(Integer.valueOf((new String(buffer, 0, len)).trim()));
+                    setActualDockStateLocked(Integer.parseInt((new String(buffer, 0, len)).trim()));
                     mPreviousDockState = mActualDockState;
                 } finally {
                     file.close();
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index 544e645..79d16da 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -2473,7 +2473,7 @@
             int subtypeId = NOT_A_SUBTYPE_ID;
             if (lastIme != null && lastImi != null) {
                 final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
-                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
+                final int lastSubtypeHash = Integer.parseInt(lastIme.second);
                 final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
                         : mCurrentSubtype.hashCode();
                 // If the last IME is the same as the current IME and the last subtype is not
@@ -2587,7 +2587,7 @@
             final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
             if (lastImi == null) return null;
             try {
-                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
+                final int lastSubtypeHash = Integer.parseInt(lastIme.second);
                 final int lastSubtypeId =
                         InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
                 if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
@@ -3437,7 +3437,7 @@
             if (subtypeHashCode != null) {
                 try {
                     lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
-                            imi, Integer.valueOf(subtypeHashCode));
+                            imi, Integer.parseInt(subtypeHashCode));
                 } catch (NumberFormatException e) {
                     Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
                 }
@@ -3798,9 +3798,9 @@
                             Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
                             continue;
                         }
-                        final int icon = Integer.valueOf(
+                        final int icon = Integer.parseInt(
                                 parser.getAttributeValue(null, ATTR_ICON));
-                        final int label = Integer.valueOf(
+                        final int label = Integer.parseInt(
                                 parser.getAttributeValue(null, ATTR_LABEL));
                         final String imeSubtypeLocale =
                                 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
@@ -3826,7 +3826,7 @@
                         final String subtypeIdString =
                                 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_ID);
                         if (subtypeIdString != null) {
-                            builder.setSubtypeId(Integer.valueOf(subtypeIdString));
+                            builder.setSubtypeId(Integer.parseInt(subtypeIdString));
                         }
                         tempSubtypesArray.add(builder.build());
                     }
diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java
index 801d6e0..a628747 100644
--- a/services/core/java/com/android/server/TextServicesManagerService.java
+++ b/services/core/java/com/android/server/TextServicesManagerService.java
@@ -1110,7 +1110,7 @@
         private int getInt(final String key, final int defaultValue) {
             if (mCopyOnWrite && mCopyOnWriteDataStore.containsKey(key)) {
                 final String result = mCopyOnWriteDataStore.get(key);
-                return result != null ? Integer.valueOf(result) : 0;
+                return result != null ? Integer.parseInt(result) : 0;
             }
             return Settings.Secure.getIntForUser(mResolver, key, defaultValue, mCurrentUserId);
         }
diff --git a/services/core/java/com/android/server/WiredAccessoryManager.java b/services/core/java/com/android/server/WiredAccessoryManager.java
index e0e6070..fcda83d 100644
--- a/services/core/java/com/android/server/WiredAccessoryManager.java
+++ b/services/core/java/com/android/server/WiredAccessoryManager.java
@@ -330,7 +330,7 @@
                         FileReader file = new FileReader(uei.getSwitchStatePath());
                         int len = file.read(buffer, 0, 1024);
                         file.close();
-                        curState = Integer.valueOf((new String(buffer, 0, len)).trim());
+                        curState = Integer.parseInt((new String(buffer, 0, len)).trim());
 
                         if (curState > 0) {
                             updateStateLocked(uei.getDevPath(), uei.getDevName(), curState);
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 48f87b6..aaf8301 100755
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -1396,7 +1396,7 @@
             if (ATTR_ID.equals(attrName)) {
                 createTime = Long.valueOf(attrValue);
             } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
-                launchedFromUid = Integer.valueOf(attrValue);
+                launchedFromUid = Integer.parseInt(attrValue);
             } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
                 launchedFromPackage = attrValue;
             } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
@@ -1404,7 +1404,7 @@
             } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
                 componentSpecified = Boolean.valueOf(attrValue);
             } else if (ATTR_USERID.equals(attrName)) {
-                userId = Integer.valueOf(attrValue);
+                userId = Integer.parseInt(attrValue);
             } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
                 taskDescription.restoreFromXml(attrName, attrValue);
             } else {
diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java
index ceb7db6..a2472ac 100644
--- a/services/core/java/com/android/server/am/TaskPersister.java
+++ b/services/core/java/com/android/server/am/TaskPersister.java
@@ -529,7 +529,7 @@
             if (taskIdEnd > 0) {
                 final int taskId;
                 try {
-                    taskId = Integer.valueOf(filename.substring(0, taskIdEnd));
+                    taskId = Integer.parseInt(filename.substring(0, taskIdEnd));
                     if (DEBUG) Slog.d(TAG, "removeObsoleteFiles: Found taskId=" + taskId);
                 } catch (Exception e) {
                     Slog.wtf(TAG, "removeObsoleteFiles: Can't parse file=" + file.getName());
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 08d2399..5a5f861 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -1227,7 +1227,7 @@
             if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
                     attrName + " value=" + attrValue);
             if (ATTR_TASKID.equals(attrName)) {
-                if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
+                if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
             } else if (ATTR_REALACTIVITY.equals(attrName)) {
                 realActivity = ComponentName.unflattenFromString(attrValue);
             } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
@@ -1246,13 +1246,13 @@
             } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
                 askedCompatMode = Boolean.valueOf(attrValue);
             } else if (ATTR_USERID.equals(attrName)) {
-                userId = Integer.valueOf(attrValue);
+                userId = Integer.parseInt(attrValue);
             } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
                 userSetupComplete = Boolean.valueOf(attrValue);
             } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
-                effectiveUid = Integer.valueOf(attrValue);
+                effectiveUid = Integer.parseInt(attrValue);
             } else if (ATTR_TASKTYPE.equals(attrName)) {
-                taskType = Integer.valueOf(attrValue);
+                taskType = Integer.parseInt(attrValue);
             } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
                 firstActiveTime = Long.valueOf(attrValue);
             } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
@@ -1268,19 +1268,19 @@
             } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
                 taskDescription.restoreFromXml(attrName, attrValue);
             } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
-                taskAffiliation = Integer.valueOf(attrValue);
+                taskAffiliation = Integer.parseInt(attrValue);
             } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
-                prevTaskId = Integer.valueOf(attrValue);
+                prevTaskId = Integer.parseInt(attrValue);
             } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
-                nextTaskId = Integer.valueOf(attrValue);
+                nextTaskId = Integer.parseInt(attrValue);
             } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
-                taskAffiliationColor = Integer.valueOf(attrValue);
+                taskAffiliationColor = Integer.parseInt(attrValue);
             } else if (ATTR_CALLING_UID.equals(attrName)) {
-                callingUid = Integer.valueOf(attrValue);
+                callingUid = Integer.parseInt(attrValue);
             } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
                 callingPackage = attrValue;
             } else if (ATTR_RESIZE_MODE.equals(attrName)) {
-                resizeMode = Integer.valueOf(attrValue);
+                resizeMode = Integer.parseInt(attrValue);
                 resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
                         ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
             } else if (ATTR_PRIVILEGED.equals(attrName)) {
@@ -1288,9 +1288,9 @@
             } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
                 bounds = Rect.unflattenFromString(attrValue);
             } else if (ATTR_MINIMAL_WIDTH.equals(attrName)) {
-                minimalWidth = Integer.valueOf(attrValue);
+                minimalWidth = Integer.parseInt(attrValue);
             } else if (ATTR_MINIMAL_HEIGHT.equals(attrName)) {
-                minimalHeight = Integer.valueOf(attrValue);
+                minimalHeight = Integer.parseInt(attrValue);
             } else {
                 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
             }
diff --git a/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java b/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java
index dc62609..5f9efe7 100644
--- a/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java
+++ b/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java
@@ -548,8 +548,7 @@
             mMeasurement.description += " src{" + getSocketAddressString() + "}";
 
             // This needs to be fixed length so it can be dropped into the pre-canned packet.
-            final String sixRandomDigits =
-                    Integer.valueOf(mRandom.nextInt(900000) + 100000).toString();
+            final String sixRandomDigits = String.valueOf(mRandom.nextInt(900000) + 100000);
             mMeasurement.description += " qtype{" + mQueryType + "}"
                     + " qname{" + sixRandomDigits + "-android-ds.metric.gstatic.com}";
 
diff --git a/services/core/java/com/android/server/job/JobStore.java b/services/core/java/com/android/server/job/JobStore.java
index 55f37b8..35628a2 100644
--- a/services/core/java/com/android/server/job/JobStore.java
+++ b/services/core/java/com/android/server/job/JobStore.java
@@ -486,7 +486,7 @@
                 final List<JobStatus> jobs = new ArrayList<JobStatus>();
                 // Read in version info.
                 try {
-                    int version = Integer.valueOf(parser.getAttributeValue(null, "version"));
+                    int version = Integer.parseInt(parser.getAttributeValue(null, "version"));
                     if (version != JOBS_FILE_VERSION) {
                         Slog.d(TAG, "Invalid version number, aborting jobs file read.");
                         return null;
@@ -534,14 +534,14 @@
             try {
                 jobBuilder = buildBuilderFromXml(parser);
                 jobBuilder.setPersisted(true);
-                uid = Integer.valueOf(parser.getAttributeValue(null, "uid"));
+                uid = Integer.parseInt(parser.getAttributeValue(null, "uid"));
 
                 String val = parser.getAttributeValue(null, "priority");
                 if (val != null) {
-                    jobBuilder.setPriority(Integer.valueOf(val));
+                    jobBuilder.setPriority(Integer.parseInt(val));
                 }
                 val = parser.getAttributeValue(null, "sourceUserId");
-                sourceUserId = val == null ? -1 : Integer.valueOf(val);
+                sourceUserId = val == null ? -1 : Integer.parseInt(val);
             } catch (NumberFormatException e) {
                 Slog.e(TAG, "Error parsing job's required fields, skipping");
                 return null;
@@ -684,7 +684,7 @@
 
         private JobInfo.Builder buildBuilderFromXml(XmlPullParser parser) throws NumberFormatException {
             // Pull out required fields from <job> attributes.
-            int jobId = Integer.valueOf(parser.getAttributeValue(null, "jobid"));
+            int jobId = Integer.parseInt(parser.getAttributeValue(null, "jobid"));
             String packageName = parser.getAttributeValue(null, "package");
             String className = parser.getAttributeValue(null, "class");
             ComponentName cname = new ComponentName(packageName, className);
@@ -720,7 +720,7 @@
             if (val != null) {
                 long initialBackoff = Long.valueOf(val);
                 val = parser.getAttributeValue(null, "backoff-policy");
-                int backoffPolicy = Integer.valueOf(val);  // Will throw NFE which we catch higher up.
+                int backoffPolicy = Integer.parseInt(val);  // Will throw NFE which we catch higher up.
                 jobBuilder.setBackoffCriteria(initialBackoff, backoffPolicy);
             }
         }
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 4a41705..78b3f41 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -303,7 +303,7 @@
     private static int tryParseInt(String value, int defValue) {
         if (TextUtils.isEmpty(value)) return defValue;
         try {
-            return Integer.valueOf(value);
+            return Integer.parseInt(value);
         } catch (NumberFormatException e) {
             return defValue;
         }
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
index 9c15f2b..0f68cca 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
@@ -252,7 +252,7 @@
         String[] usersStr = text.split(",");
         int[] users = new int[usersStr.length];
         for (int i = 0; i < usersStr.length; i++) {
-            users[i] = Integer.valueOf(usersStr[i]);
+            users[i] = Integer.parseInt(usersStr[i]);
         }
         return users;
     }