Extend Intent/Uri conversion for use by Browser
This introduces a new Uri form of Intent with an "intent:" scheme, and a corresponding update to the parser to handle these, so that the browser can use this generic facility for starting activities based on the links that are clicked and allow for web pages to link to arbitrary intents. There is also a new "package" field on Intent which allows you to limit the components it finds to a given package. This replaces the new method that was added to PackageManger for doing this when resolving activities, and implements it for all Intent queries against the package manager.
This commit is contained in:
@@ -1269,28 +1269,6 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
return chooseBestActivity(intent, resolvedType, flags, query);
|
||||
}
|
||||
|
||||
public ResolveInfo resolveIntentForPackage(Intent intent, String resolvedType,
|
||||
int flags, String packageName) {
|
||||
ComponentName comp = intent.getComponent();
|
||||
if (comp != null) {
|
||||
// if this is an explicit intent, it must have the same the packageName
|
||||
if (packageName.equals(comp.getPackageName())) {
|
||||
return resolveIntent(intent, resolvedType, flags);
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
List<ResolveInfo> query = null;
|
||||
synchronized (mPackages) {
|
||||
PackageParser.Package pkg = mPackages.get(packageName);
|
||||
if (pkg != null) {
|
||||
query = (List<ResolveInfo>) mActivities.
|
||||
queryIntentForPackage(intent, resolvedType, flags, pkg.activities);
|
||||
}
|
||||
}
|
||||
return chooseBestActivity(intent, resolvedType, flags, query);
|
||||
}
|
||||
}
|
||||
|
||||
private ResolveInfo chooseBestActivity(Intent intent, String resolvedType,
|
||||
int flags, List<ResolveInfo> query) {
|
||||
if (query != null) {
|
||||
@@ -1409,8 +1387,17 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
}
|
||||
|
||||
synchronized (mPackages) {
|
||||
return (List<ResolveInfo>)mActivities.
|
||||
queryIntent(intent, resolvedType, flags);
|
||||
String pkgName = intent.getPackage();
|
||||
if (pkgName == null) {
|
||||
return (List<ResolveInfo>)mActivities.queryIntent(intent,
|
||||
resolvedType, flags);
|
||||
}
|
||||
PackageParser.Package pkg = mPackages.get(pkgName);
|
||||
if (pkg != null) {
|
||||
return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent,
|
||||
resolvedType, flags, pkg.activities);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1577,9 +1564,30 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
|
||||
public List<ResolveInfo> queryIntentReceivers(Intent intent,
|
||||
String resolvedType, int flags) {
|
||||
ComponentName comp = intent.getComponent();
|
||||
if (comp != null) {
|
||||
List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
|
||||
ActivityInfo ai = getReceiverInfo(comp, flags);
|
||||
if (ai != null) {
|
||||
ResolveInfo ri = new ResolveInfo();
|
||||
ri.activityInfo = ai;
|
||||
list.add(ri);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
synchronized (mPackages) {
|
||||
return (List<ResolveInfo>)mReceivers.
|
||||
queryIntent(intent, resolvedType, flags);
|
||||
String pkgName = intent.getPackage();
|
||||
if (pkgName == null) {
|
||||
return (List<ResolveInfo>)mReceivers.queryIntent(intent,
|
||||
resolvedType, flags);
|
||||
}
|
||||
PackageParser.Package pkg = mPackages.get(pkgName);
|
||||
if (pkg != null) {
|
||||
return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent,
|
||||
resolvedType, flags, pkg.receivers);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1612,7 +1620,17 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
}
|
||||
|
||||
synchronized (mPackages) {
|
||||
return (List<ResolveInfo>)mServices.queryIntent(intent, resolvedType, flags);
|
||||
String pkgName = intent.getPackage();
|
||||
if (pkgName == null) {
|
||||
return (List<ResolveInfo>)mServices.queryIntent(intent,
|
||||
resolvedType, flags);
|
||||
}
|
||||
PackageParser.Package pkg = mPackages.get(pkgName);
|
||||
if (pkg != null) {
|
||||
return (List<ResolveInfo>)mServices.queryIntentForPackage(intent,
|
||||
resolvedType, flags, pkg.services);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3106,6 +3124,27 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
(flags&PackageManager.MATCH_DEFAULT_ONLY) != 0);
|
||||
}
|
||||
|
||||
public List queryIntentForPackage(Intent intent, String resolvedType, int flags,
|
||||
ArrayList<PackageParser.Service> packageServices) {
|
||||
if (packageServices == null) {
|
||||
return null;
|
||||
}
|
||||
mFlags = flags;
|
||||
final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
|
||||
int N = packageServices.size();
|
||||
ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut =
|
||||
new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N);
|
||||
|
||||
ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
intentFilters = packageServices.get(i).intents;
|
||||
if (intentFilters != null && intentFilters.size() > 0) {
|
||||
listCut.add(intentFilters);
|
||||
}
|
||||
}
|
||||
return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut);
|
||||
}
|
||||
|
||||
public final void addService(PackageParser.Service s) {
|
||||
mServices.put(s.component, s);
|
||||
if (SHOW_INFO || Config.LOGV) Log.v(
|
||||
|
||||
Reference in New Issue
Block a user