Fix bug with user of shortcut not being remembered over restart.

Intent extra was being set as int rather than long so being
missed.
Also use LauncherApps if neccessary in case where launching
without launch animation.
Unregister for package notifications when terminating.

Bug: 14636181
Change-Id: I1575f6eed806446782092dffe8c01afe7b6507fe
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index bf2a02d..01b1cde 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2638,23 +2638,26 @@
                     !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
             LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
             UserManagerCompat userManager = UserManagerCompat.getInstance(this);
-            long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, 0);
-            UserHandleCompat user = serialNumber == 0 ? null :
-                    userManager.getUserForSerialNumber(serialNumber);
 
+            UserHandleCompat user = null;
+            if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
+                long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
+                user = userManager.getUserForSerialNumber(serialNumber);
+            }
+
+            Bundle optsBundle = null;
             if (useLaunchAnimation) {
                 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
                         v.getMeasuredWidth(), v.getMeasuredHeight());
-                if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
-                    // Could be launching some bookkeeping activity
-                    startActivity(intent, opts.toBundle());
-                } else {
-                    launcherApps.startActivityForProfile(intent.getComponent(),
-                            intent.getSourceBounds(),
-                            opts.toBundle(), user);
-                }
+                optsBundle = opts.toBundle();
+            }
+
+            if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
+                // Could be launching some bookkeeping activity
+                startActivity(intent, optsBundle);
             } else {
-                startActivity(intent);
+                launcherApps.startActivityForProfile(intent.getComponent(),
+                        intent.getSourceBounds(), optsBundle, user);
             }
             return true;
         } catch (SecurityException e) {