Merge "Handle if the printing app is killed while saving to PDF." into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index 09497a5..953cfe0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -22333,7 +22333,6 @@
     field public static final java.lang.String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
     field public static final java.lang.String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
     field public static final java.lang.String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
-    field public static final java.lang.String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
     field public static final java.lang.String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
     field public static final java.lang.String DISALLOW_REMOVE_USER = "no_remove_user";
     field public static final java.lang.String DISALLOW_SHARE_LOCATION = "no_share_location";
diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java
index 841bd16..49ab7c1 100644
--- a/core/java/android/app/ApplicationErrorReport.java
+++ b/core/java/android/app/ApplicationErrorReport.java
@@ -388,7 +388,7 @@
             dest.writeInt(throwLineNumber);
             dest.writeString(stackTrace);
             int total = dest.dataPosition()-start;
-            if (total > 10*1024) {
+            if (total > 20*1024) {
                 Slog.d("Error", "ERR: exClass=" + exceptionClassName);
                 Slog.d("Error", "ERR: exMsg=" + exceptionMessage);
                 Slog.d("Error", "ERR: file=" + throwFileName);
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 1368f39..3234e77 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -367,6 +367,7 @@
      * <p/>Type: Boolean
      * @see #setUserRestrictions(Bundle)
      * @see #getUserRestrictions()
+     * @hide
      */
     public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
 
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 0b253f5..f02a815 100755
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -69,6 +69,7 @@
     static final boolean DEBUG_DELAYED_SERVICE = ActivityManagerService.DEBUG_SERVICE;
     static final boolean DEBUG_DELAYED_STARTS = DEBUG_DELAYED_SERVICE;
     static final boolean DEBUG_MU = ActivityManagerService.DEBUG_MU;
+    static final boolean LOG_SERVICE_START_STOP = false;
     static final String TAG = ActivityManagerService.TAG;
     static final String TAG_MU = ActivityManagerService.TAG_MU;
 
@@ -1447,8 +1448,10 @@
             String nameTerm;
             int lastPeriod = r.shortName.lastIndexOf('.');
             nameTerm = lastPeriod >= 0 ? r.shortName.substring(lastPeriod) : r.shortName;
-            EventLogTags.writeAmCreateService(
-                    r.userId, System.identityHashCode(r), nameTerm, r.app.uid, r.app.pid);
+            if (LOG_SERVICE_START_STOP) {
+                EventLogTags.writeAmCreateService(
+                        r.userId, System.identityHashCode(r), nameTerm, r.app.uid, r.app.pid);
+            }
             synchronized (r.stats.getBatteryStats()) {
                 r.stats.startLaunchedLocked();
             }
@@ -1632,8 +1635,10 @@
         }
 
         if (DEBUG_SERVICE) Slog.v(TAG, "Bringing down " + r + " " + r.intent);
-        EventLogTags.writeAmDestroyService(
-                r.userId, System.identityHashCode(r), (r.app != null) ? r.app.pid : -1);
+        if (LOG_SERVICE_START_STOP) {
+            EventLogTags.writeAmDestroyService(
+                    r.userId, System.identityHashCode(r), (r.app != null) ? r.app.pid : -1);
+        }
 
         final ServiceMap smap = getServiceMap(r.userId);
         smap.mServicesByName.remove(r.name);
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 9473495..7de56c8 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -2371,7 +2371,8 @@
                 intent.getType(), flags, 0);
         if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
                 + " results: " + ri);
-        int match = 0;
+        int systemMatch = 0;
+        int thirdPartyMatch = 0;
         if (ri != null && ri.size() > 1) {
             boolean haveAct = false;
             ComponentName haveNonSys = null;
@@ -2380,13 +2381,10 @@
                 ActivityInfo ai = ri.get(i).activityInfo;
                 set[i] = new ComponentName(ai.packageName, ai.name);
                 if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-                    if (ri.get(i).match >= match) {
-                        // If any of the matches are not system apps, then
-                        // there is a third party app that is now an option...
-                        // so don't set a default since we don't want to hide it.
-                        // Only do this if the match of this one is at least as good
-                        // as what we have found as the built-in app; if it isn't
-                        // as good, the user won't want it anyway, right?
+                    if (ri.get(i).match >= thirdPartyMatch) {
+                        // Keep track of the best match we find of all third
+                        // party apps, for use later to determine if we actually
+                        // want to set a preferred app for this intent.
                         if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                                 + ai.packageName + "/" + ai.name + ": non-system!");
                         haveNonSys = set[i];
@@ -2397,12 +2395,19 @@
                     if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                             + ai.packageName + "/" + ai.name + ": default!");
                     haveAct = true;
-                    match = ri.get(i).match;
+                    systemMatch = ri.get(i).match;
                 } else {
                     if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                             + ai.packageName + "/" + ai.name + ": skipped");
                 }
             }
+            if (haveNonSys != null && thirdPartyMatch < systemMatch) {
+                // If we have a matching third party app, but its match is not as
+                // good as the built-in system app, then we don't want to actually
+                // consider it a match because presumably the built-in app is still
+                // the thing we want users to see by default.
+                haveNonSys = null;
+            }
             if (haveAct && haveNonSys == null) {
                 IntentFilter filter = new IntentFilter();
                 if (intent.getAction() != null) {
@@ -2435,7 +2440,7 @@
                         Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
                     }
                 }
-                PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
+                PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true);
                 editPreferredActivitiesLPw(userId).addFilter(pa);
             } else if (haveNonSys == null) {
                 StringBuilder sb = new StringBuilder();