Have a fallback package name when matching targetPackage.

Bug: 29774397

When figuring out best match package name, we should have a fallback.
Otherwise sometimes we get empty package names, causing problems when
trying to display memory usage for each app.

Change-Id: I9cc4205098bb7c727a3063b2275fb464c8153097
(cherry picked from commit d5ff4c42924d11c32ab591f5cef00694ce035e15)
diff --git a/src/com/android/settings/applications/ProcStatsEntry.java b/src/com/android/settings/applications/ProcStatsEntry.java
index 36d397e..90ef5d7 100644
--- a/src/com/android/settings/applications/ProcStatsEntry.java
+++ b/src/com/android/settings/applications/ProcStatsEntry.java
@@ -20,12 +20,13 @@
 import android.content.pm.PackageManager;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Log;
 import android.util.SparseArray;
 
-import com.android.internal.app.procstats.ProcessStats;
 import com.android.internal.app.procstats.ProcessState;
+import com.android.internal.app.procstats.ProcessStats;
 import com.android.internal.app.procstats.ServiceState;
 
 import java.util.ArrayList;
@@ -33,6 +34,7 @@
 import java.util.Comparator;
 
 public final class ProcStatsEntry implements Parcelable {
+
     private static final String TAG = "ProcStatsEntry";
     private static boolean DEBUG = ProcessStatsUi.DEBUG;
 
@@ -40,7 +42,7 @@
     final int mUid;
     final String mName;
     public CharSequence mLabel;
-    final ArrayList<String> mPackages = new ArrayList<String>();
+    final ArrayList<String> mPackages = new ArrayList<>();
     final long mBgDuration;
     final long mAvgBgMem;
     final long mMaxBgMem;
@@ -52,7 +54,7 @@
 
     String mBestTargetPackage;
 
-    ArrayMap<String, ArrayList<Service>> mServices = new ArrayMap<String, ArrayList<Service>>(1);
+    ArrayMap<String, ArrayList<Service>> mServices = new ArrayMap<>(1);
 
     public ProcStatsEntry(ProcessState proc, String packageName,
             ProcessStats.ProcessDataCollection tmpBgTotals,
@@ -249,6 +251,10 @@
                             + " not as good as last " + bestRunTime);
                 }
             }
+            // Final fallback, just pick the first subProc.
+            if (TextUtils.isEmpty(mBestTargetPackage)) {
+                mBestTargetPackage = subProcs.get(0).mPackage;
+            }
         } else if (subProcs.size() == 1) {
             mBestTargetPackage = subProcs.get(0).mPackage;
         }