forked from mirrors/gecko-dev
Bug 1031569 - Don't query for non-exported activities, don't crash if we fail to launch one. r=mfinkle
Tested youtube.com, send tab, sharing menu.
This commit is contained in:
parent
aa3fe5d00a
commit
184191949e
2 changed files with 33 additions and 7 deletions
|
|
@ -961,11 +961,24 @@ public class GeckoAppShell
|
||||||
return getHandlersForIntent(intent);
|
return getHandlersForIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<ResolveInfo> queryIntentActivities(Intent intent) {
|
||||||
|
final PackageManager pm = getContext().getPackageManager();
|
||||||
|
|
||||||
|
// Exclude any non-exported activities: we can't open them even if we want to!
|
||||||
|
// Bug 1031569 has some details.
|
||||||
|
final ArrayList<ResolveInfo> list = new ArrayList<>();
|
||||||
|
for (ResolveInfo ri: pm.queryIntentActivities(intent, 0)) {
|
||||||
|
if (ri.activityInfo.exported) {
|
||||||
|
list.add(ri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
static boolean hasHandlersForIntent(Intent intent) {
|
static boolean hasHandlersForIntent(Intent intent) {
|
||||||
try {
|
try {
|
||||||
PackageManager pm = getContext().getPackageManager();
|
return !queryIntentActivities(intent).isEmpty();
|
||||||
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
|
||||||
return !list.isEmpty();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.e(LOGTAG, "Exception in GeckoAppShell.hasHandlersForIntent");
|
Log.e(LOGTAG, "Exception in GeckoAppShell.hasHandlersForIntent");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -973,11 +986,12 @@ public class GeckoAppShell
|
||||||
}
|
}
|
||||||
|
|
||||||
static String[] getHandlersForIntent(Intent intent) {
|
static String[] getHandlersForIntent(Intent intent) {
|
||||||
|
final PackageManager pm = getContext().getPackageManager();
|
||||||
try {
|
try {
|
||||||
PackageManager pm = getContext().getPackageManager();
|
final List<ResolveInfo> list = queryIntentActivities(intent);
|
||||||
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
|
||||||
int numAttr = 4;
|
int numAttr = 4;
|
||||||
String[] ret = new String[list.size() * numAttr];
|
final String[] ret = new String[list.size() * numAttr];
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
ResolveInfo resolveInfo = list.get(i);
|
ResolveInfo resolveInfo = list.get(i);
|
||||||
ret[i * numAttr] = resolveInfo.loadLabel(pm).toString();
|
ret[i * numAttr] = resolveInfo.loadLabel(pm).toString();
|
||||||
|
|
@ -1098,6 +1112,10 @@ public class GeckoAppShell
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.w(LOGTAG, "Activity not found.", e);
|
||||||
|
return false;
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
Log.w(LOGTAG, "Forbidden to launch activity.", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1174,6 +1192,8 @@ public class GeckoAppShell
|
||||||
final String action,
|
final String action,
|
||||||
final String title) {
|
final String title) {
|
||||||
|
|
||||||
|
// The resultant chooser can return non-exported activities in 4.1 and earlier.
|
||||||
|
// https://code.google.com/p/android/issues/detail?id=29535
|
||||||
final Intent intent = getOpenURIIntentInner(context, targetURI, mimeType, action, title);
|
final Intent intent = getOpenURIIntentInner(context, targetURI, mimeType, action, title);
|
||||||
|
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,13 @@ public final class IntentHelper implements GeckoEventListener {
|
||||||
message.optString("title"));
|
message.optString("title"));
|
||||||
intent.setClassName(message.optString("packageName"), message.optString("className"));
|
intent.setClassName(message.optString("packageName"), message.optString("className"));
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
ActivityHandlerHelper.startIntentForActivity(activity, intent, new ResultHandler(message));
|
|
||||||
|
final ResultHandler handler = new ResultHandler(message);
|
||||||
|
try {
|
||||||
|
ActivityHandlerHelper.startIntentForActivity(activity, intent, handler);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
Log.w(LOGTAG, "Forbidden to launch activity.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue