From b3781d934ffb55a282a2567de55a23fb92b71856 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 27 Jan 2011 15:21:41 -0800 Subject: [PATCH] Adding check to prevent NPE when we get a badly encoded install-shortcut intent. (3398526) Change-Id: I49c00ff290b126539247f4345e638460040c6ac5 --- .../launcher2/InstallShortcutReceiver.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java index ac50f66051..c67e90ecf4 100644 --- a/src/com/android/launcher2/InstallShortcutReceiver.java +++ b/src/com/android/launcher2/InstallShortcutReceiver.java @@ -55,25 +55,27 @@ public class InstallShortcutReceiver extends BroadcastReceiver { if (findEmptyCell(context, mCoordinates, screen)) { Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); + if (intent != null) { + if (intent.getAction() == null) { + intent.setAction(Intent.ACTION_VIEW); + } - if (intent.getAction() == null) { - intent.setAction(Intent.ACTION_VIEW); + // By default, we allow for duplicate entries (located in + // different places) + boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); + if (duplicate || !LauncherModel.shortcutExists(context, name, intent)) { + LauncherApplication app = (LauncherApplication) context.getApplicationContext(); + app.getModel().addShortcut(context, data, screen, mCoordinates[0], + mCoordinates[1], true); + Toast.makeText(context, context.getString(R.string.shortcut_installed, name), + Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name), + Toast.LENGTH_SHORT).show(); + } + + return true; } - - // By default, we allow for duplicate entries (located in - // different places) - boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); - if (duplicate || !LauncherModel.shortcutExists(context, name, intent)) { - ((LauncherApplication)context.getApplicationContext()).getModel() - .addShortcut(context, data, screen, mCoordinates[0], mCoordinates[1], true); - Toast.makeText(context, context.getString(R.string.shortcut_installed, name), - Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name), - Toast.LENGTH_SHORT).show(); - } - - return true; } else { Toast.makeText(context, context.getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();