IntentForwarderActivity shouldn't crash if intent has no action.

Also don't crash when receiving a chooser intent with no
extra initial intent.

BUG:26445101
Change-Id: Icaf55881a015cf8cc76e5269b9bb67784dbf33c3
This commit is contained in:
Nicolas Prevot
2016-02-03 16:18:03 +00:00
parent 95aaf5d5b0
commit decd9ea263

View File

@@ -85,8 +85,10 @@ public class IntentForwarderActivity extends Activity {
int callingUserId = getUserId();
if (canForward(newIntent, targetUserId)) {
if (newIntent.getAction().equals(Intent.ACTION_CHOOSER)) {
if (Intent.ACTION_CHOOSER.equals(newIntent.getAction())) {
Intent innerIntent = (Intent) newIntent.getParcelableExtra(Intent.EXTRA_INTENT);
// At this point, innerIntent is not null. Otherwise, canForward would have returned
// false.
innerIntent.prepareToLeaveUser(callingUserId);
} else {
newIntent.prepareToLeaveUser(callingUserId);
@@ -124,7 +126,7 @@ public class IntentForwarderActivity extends Activity {
Toast.makeText(this, getString(userMessageId), Toast.LENGTH_LONG).show();
}
} else {
Slog.wtf(TAG, "the intent: " + newIntent + "cannot be forwarded from user "
Slog.wtf(TAG, "the intent: " + newIntent + " cannot be forwarded from user "
+ callingUserId + " to user " + targetUserId);
}
finish();
@@ -132,7 +134,7 @@ public class IntentForwarderActivity extends Activity {
boolean canForward(Intent intent, int targetUserId) {
IPackageManager ipm = AppGlobals.getPackageManager();
if (intent.getAction().equals(Intent.ACTION_CHOOSER)) {
if (Intent.ACTION_CHOOSER.equals(intent.getAction())) {
// The EXTRA_INITIAL_INTENTS may not be allowed to be forwarded.
if (intent.hasExtra(Intent.EXTRA_INITIAL_INTENTS)) {
Slog.wtf(TAG, "An chooser intent with extra initial intents cannot be forwarded to"
@@ -145,6 +147,11 @@ public class IntentForwarderActivity extends Activity {
return false;
}
intent = (Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT);
if (intent == null) {
Slog.wtf(TAG, "Cannot forward a chooser intent with no extra "
+ Intent.EXTRA_INTENT);
return false;
}
}
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
if (intent.getSelector() != null) {