Don't set the failure extra on split install

Change-Id: I2f836b5ebc9f377ae8fe0a0d4a60541dd1666011
Fixes: 37852108
Test: Manual
Test: Install and run pico blast
Test: Note that the failure extra is set
Test: Click "New" to install a split
Test: Note that the failure extra isn't set
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index 2273452..1a96158 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -534,7 +534,8 @@
                     verificationBundle, userId);
         }
         return InstantAppResolver.buildEphemeralInstallerIntent(originalIntent,
-            callingPackage, verificationBundle, resolvedType, userId, auxiliaryResponse.packageName,
+            auxiliaryResponse.failureIntent, callingPackage, verificationBundle,
+            resolvedType, userId, auxiliaryResponse.packageName,
             auxiliaryResponse.splitName, auxiliaryResponse.versionCode,
             auxiliaryResponse.token, auxiliaryResponse.needsPhaseTwo);
     }
diff --git a/services/core/java/com/android/server/pm/InstantAppResolver.java b/services/core/java/com/android/server/pm/InstantAppResolver.java
index 624d8c9..f3c9cbb 100644
--- a/services/core/java/com/android/server/pm/InstantAppResolver.java
+++ b/services/core/java/com/android/server/pm/InstantAppResolver.java
@@ -125,6 +125,7 @@
                 final String packageName;
                 final String splitName;
                 final int versionCode;
+                final Intent failureIntent;
                 if (instantAppResolveInfoList != null && instantAppResolveInfoList.size() > 0) {
                     final AuxiliaryResolveInfo instantAppIntentInfo =
                             InstantAppResolver.filterInstantAppIntent(
@@ -135,18 +136,22 @@
                         packageName = instantAppIntentInfo.resolveInfo.getPackageName();
                         splitName = instantAppIntentInfo.splitName;
                         versionCode = instantAppIntentInfo.resolveInfo.getVersionCode();
+                        failureIntent = instantAppIntentInfo.failureIntent;
                     } else {
                         packageName = null;
                         splitName = null;
                         versionCode = -1;
+                        failureIntent = null;
                     }
                 } else {
                     packageName = null;
                     splitName = null;
                     versionCode = -1;
+                    failureIntent = null;
                 }
                 final Intent installerIntent = buildEphemeralInstallerIntent(
                         requestObj.origIntent,
+                        failureIntent,
                         requestObj.callingPackage,
                         requestObj.verificationBundle,
                         requestObj.resolvedType,
@@ -172,7 +177,9 @@
     /**
      * Builds and returns an intent to launch the instant installer.
      */
-    public static Intent buildEphemeralInstallerIntent(@NonNull Intent origIntent,
+    public static Intent buildEphemeralInstallerIntent(
+            @NonNull Intent origIntent,
+            @NonNull Intent failureIntent,
             @NonNull String callingPackage,
             @Nullable Bundle verificationBundle,
             @NonNull String resolvedType,
@@ -200,22 +207,21 @@
         // We have all of the data we need; just start the installer without a second phase
         if (!needsPhaseTwo) {
             // Intent that is launched if the package couldn't be installed for any reason.
-            final Intent failureIntent = new Intent(origIntent);
-            failureIntent.setFlags(failureIntent.getFlags() | Intent.FLAG_IGNORE_EPHEMERAL);
-            failureIntent.setLaunchToken(token);
-            try {
-                final IIntentSender failureIntentTarget = ActivityManager.getService()
-                        .getIntentSender(
-                                ActivityManager.INTENT_SENDER_ACTIVITY, callingPackage,
-                                null /*token*/, null /*resultWho*/, 1 /*requestCode*/,
-                                new Intent[] { failureIntent },
-                                new String[] { resolvedType },
-                                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT
-                                        | PendingIntent.FLAG_IMMUTABLE,
-                                null /*bOptions*/, userId);
-                intent.putExtra(Intent.EXTRA_EPHEMERAL_FAILURE,
-                        new IntentSender(failureIntentTarget));
-            } catch (RemoteException ignore) { /* ignore; same process */ }
+            if (failureIntent != null) {
+                try {
+                    final IIntentSender failureIntentTarget = ActivityManager.getService()
+                            .getIntentSender(
+                                    ActivityManager.INTENT_SENDER_ACTIVITY, callingPackage,
+                                    null /*token*/, null /*resultWho*/, 1 /*requestCode*/,
+                                    new Intent[] { failureIntent },
+                                    new String[] { resolvedType },
+                                    PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT
+                                            | PendingIntent.FLAG_IMMUTABLE,
+                                    null /*bOptions*/, userId);
+                    intent.putExtra(Intent.EXTRA_EPHEMERAL_FAILURE,
+                            new IntentSender(failureIntentTarget));
+                } catch (RemoteException ignore) { /* ignore; same process */ }
+            }
 
             // Intent that is launched if the package was installed successfully.
             final Intent successIntent = new Intent(origIntent);
@@ -248,10 +254,13 @@
 
     private static AuxiliaryResolveInfo filterInstantAppIntent(
             List<InstantAppResolveInfo> instantAppResolveInfoList,
-            Intent intent, String resolvedType, int userId, String packageName,
+            Intent origIntent, String resolvedType, int userId, String packageName,
             InstantAppDigest digest, String token) {
         final int[] shaPrefix = digest.getDigestPrefix();
         final byte[][] digestBytes = digest.getDigestBytes();
+        final Intent failureIntent = new Intent(origIntent);
+        failureIntent.setFlags(failureIntent.getFlags() | Intent.FLAG_IGNORE_EPHEMERAL);
+        failureIntent.setLaunchToken(token);
         // Go in reverse order so we match the narrowest scope first.
         for (int i = shaPrefix.length - 1; i >= 0 ; --i) {
             for (InstantAppResolveInfo instantAppInfo : instantAppResolveInfoList) {
@@ -271,7 +280,8 @@
                     }
                     return new AuxiliaryResolveInfo(instantAppInfo,
                             new IntentFilter(Intent.ACTION_VIEW) /*intentFilter*/,
-                            null /*splitName*/, token, true /*needsPhase2*/);
+                            null /*splitName*/, token, true /*needsPhase2*/,
+                            null /*failureIntent*/);
                 }
                 // We have a domain match; resolve the filters to see if anything matches.
                 final PackageManagerService.EphemeralIntentResolver instantAppResolver =
@@ -286,12 +296,12 @@
                         final AuxiliaryResolveInfo intentInfo =
                                 new AuxiliaryResolveInfo(instantAppInfo,
                                         splitFilters.get(k), instantAppFilter.getSplitName(),
-                                        token, false /*needsPhase2*/);
+                                        token, false /*needsPhase2*/, failureIntent);
                         instantAppResolver.addFilter(intentInfo);
                     }
                 }
                 List<AuxiliaryResolveInfo> matchedResolveInfoList = instantAppResolver.queryIntent(
-                        intent, resolvedType, false /*defaultOnly*/, userId);
+                        origIntent, resolvedType, false /*defaultOnly*/, userId);
                 if (!matchedResolveInfoList.isEmpty()) {
                     if (DEBUG_EPHEMERAL) {
                         final AuxiliaryResolveInfo info = matchedResolveInfoList.get(0);
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index cfcd0a5..55d8656 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -6702,7 +6702,7 @@
                     final ResolveInfo installerInfo = new ResolveInfo(mInstantAppInstallerInfo);
                     installerInfo.auxiliaryInfo = new AuxiliaryResolveInfo(
                             info.activityInfo.packageName, info.activityInfo.splitName,
-                            info.activityInfo.applicationInfo.versionCode);
+                            info.activityInfo.applicationInfo.versionCode, null /*failureIntent*/);
                     // make sure this resolver is the default
                     installerInfo.isDefault = true;
                     installerInfo.match = IntentFilter.MATCH_CATEGORY_SCHEME_SPECIFIC_PART
@@ -7375,7 +7375,7 @@
                     final ResolveInfo installerInfo = new ResolveInfo(mInstantAppInstallerInfo);
                     installerInfo.auxiliaryInfo = new AuxiliaryResolveInfo(
                             info.serviceInfo.packageName, info.serviceInfo.splitName,
-                            info.serviceInfo.applicationInfo.versionCode);
+                            info.serviceInfo.applicationInfo.versionCode, null /*failureIntent*/);
                     // make sure this resolver is the default
                     installerInfo.isDefault = true;
                     installerInfo.match = IntentFilter.MATCH_CATEGORY_SCHEME_SPECIFIC_PART
@@ -7496,7 +7496,7 @@
                     final ResolveInfo installerInfo = new ResolveInfo(mInstantAppInstallerInfo);
                     installerInfo.auxiliaryInfo = new AuxiliaryResolveInfo(
                             info.providerInfo.packageName, info.providerInfo.splitName,
-                            info.providerInfo.applicationInfo.versionCode);
+                            info.providerInfo.applicationInfo.versionCode, null /*failureIntent*/);
                     // make sure this resolver is the default
                     installerInfo.isDefault = true;
                     installerInfo.match = IntentFilter.MATCH_CATEGORY_SCHEME_SPECIFIC_PART