Merge "Fixes wildcard intent filter matching logic" into rvc-dev

This commit is contained in:
Patrick Baumann
2020-03-19 20:43:32 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 5 deletions

View File

@@ -274,8 +274,13 @@ public class IntentFilter implements Parcelable {
*/ */
public static final String SCHEME_HTTPS = "https"; public static final String SCHEME_HTTPS = "https";
/** The value to indicate a wildcard for incoming match arguments. */ /**
private static final String WILDCARD = "*"; * The value to indicate a wildcard for incoming match arguments.
* @hide
*/
public static final String WILDCARD = "*";
/** @hide */
public static final String WILDCARD_PATH = "/" + WILDCARD;
private int mPriority; private int mPriority;
@UnsupportedAppUsage @UnsupportedAppUsage
@@ -1439,7 +1444,7 @@ public class IntentFilter implements Parcelable {
if (mDataPaths == null) { if (mDataPaths == null) {
return false; return false;
} }
if (wildcardSupported && WILDCARD.equals(data)) { if (wildcardSupported && WILDCARD_PATH.equals(data)) {
return true; return true;
} }
final int numDataPaths = mDataPaths.size(); final int numDataPaths = mDataPaths.size();

View File

@@ -40,7 +40,6 @@ import android.content.pm.ConfigurationInfo;
import android.content.pm.FeatureGroupInfo; import android.content.pm.FeatureGroupInfo;
import android.content.pm.FeatureInfo; import android.content.pm.FeatureInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageParser; import android.content.pm.PackageParser;
import android.content.pm.PackageParser.PackageParserException; import android.content.pm.PackageParser.PackageParserException;
@@ -1390,7 +1389,7 @@ public class ParsingPackageUtils {
Uri data = null; Uri data = null;
String dataType = null; String dataType = null;
String host = ""; String host = IntentFilter.WILDCARD;
final int numActions = intentInfo.countActions(); final int numActions = intentInfo.countActions();
final int numSchemes = intentInfo.countDataSchemes(); final int numSchemes = intentInfo.countDataSchemes();
final int numTypes = intentInfo.countDataTypes(); final int numTypes = intentInfo.countDataTypes();
@@ -1421,10 +1420,23 @@ public class ParsingPackageUtils {
data = new Uri.Builder() data = new Uri.Builder()
.scheme(intentInfo.getDataScheme(0)) .scheme(intentInfo.getDataScheme(0))
.authority(host) .authority(host)
.path(IntentFilter.WILDCARD_PATH)
.build(); .build();
} }
if (numTypes == 1) { if (numTypes == 1) {
dataType = intentInfo.getDataType(0); dataType = intentInfo.getDataType(0);
// The dataType may have had the '/' removed for the dynamic mimeType feature.
// If we detect that case, we add the * back.
if (!dataType.contains("/")) {
dataType = dataType + "/*";
}
if (data == null) {
data = new Uri.Builder()
.scheme("content")
.authority(IntentFilter.WILDCARD)
.path(IntentFilter.WILDCARD_PATH)
.build();
}
} }
intent.setDataAndType(data, dataType); intent.setDataAndType(data, dataType);
if (numActions == 1) { if (numActions == 1) {