Merge "Don't set the failure extra on split install" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-05 14:21:14 +00:00
committed by Android (Google) Code Review
4 changed files with 44 additions and 27 deletions

View File

@@ -43,13 +43,16 @@ public final class AuxiliaryResolveInfo extends IntentFilter {
public final String token;
/** The version code of the package */
public final int versionCode;
/** An intent to start upon failure to install */
public final Intent failureIntent;
/** Create a response for installing an instant application. */
public AuxiliaryResolveInfo(@NonNull InstantAppResolveInfo resolveInfo,
@NonNull IntentFilter orig,
@Nullable String splitName,
@NonNull String token,
boolean needsPhase2) {
boolean needsPhase2,
@Nullable Intent failureIntent) {
super(orig);
this.resolveInfo = resolveInfo;
this.packageName = resolveInfo.getPackageName();
@@ -57,12 +60,14 @@ public final class AuxiliaryResolveInfo extends IntentFilter {
this.token = token;
this.needsPhaseTwo = needsPhase2;
this.versionCode = resolveInfo.getVersionCode();
this.failureIntent = failureIntent;
}
/** Create a response for installing a split on demand. */
public AuxiliaryResolveInfo(@NonNull String packageName,
@Nullable String splitName,
int versionCode) {
int versionCode,
@Nullable Intent failureIntent) {
super();
this.packageName = packageName;
this.splitName = splitName;
@@ -70,5 +75,6 @@ public final class AuxiliaryResolveInfo extends IntentFilter {
this.resolveInfo = null;
this.token = null;
this.needsPhaseTwo = false;
this.failureIntent = failureIntent;
}
}

View File

@@ -534,7 +534,8 @@ class ActivityStarter {
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);
}

View File

@@ -125,6 +125,7 @@ public abstract class InstantAppResolver {
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 @@ public abstract class InstantAppResolver {
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 @@ public abstract class InstantAppResolver {
/**
* 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 @@ public abstract class InstantAppResolver {
// 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 @@ public abstract class InstantAppResolver {
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 @@ public abstract class InstantAppResolver {
}
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 @@ public abstract class InstantAppResolver {
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);

View File

@@ -6715,7 +6715,7 @@ public class PackageManagerService extends IPackageManager.Stub
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
@@ -7388,7 +7388,7 @@ public class PackageManagerService extends IPackageManager.Stub
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
@@ -7509,7 +7509,7 @@ public class PackageManagerService extends IPackageManager.Stub
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