From f07af7b77de0319355e228e8630824d924522d78 Mon Sep 17 00:00:00 2001 From: Kenny Guy Date: Thu, 31 Jul 2014 11:39:16 +0100 Subject: [PATCH] Launch app details for correct profile. Support showing app details for apps in other profiles. Bug: 16371359 Change-Id: I1cabcd9f74f2a6ea6c4202a7d58af3ff3b458fd2 --- src/com/android/launcher3/InfoDropTarget.java | 11 ++++++++++- src/com/android/launcher3/Launcher.java | 18 ++++++++++++------ .../launcher3/compat/LauncherAppsCompat.java | 1 + .../compat/LauncherAppsCompatV16.java | 16 ++++++++++++++++ .../launcher3/compat/LauncherAppsCompatVL.java | 4 ++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index c8541a92a4..7e55af2286 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -26,6 +26,8 @@ import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; +import com.android.launcher3.compat.UserHandleCompat; + public class InfoDropTarget extends ButtonDropTarget { private ColorStateList mOriginalTextColor; @@ -82,8 +84,15 @@ public class InfoDropTarget extends ButtonDropTarget { } else if (d.dragInfo instanceof PendingAddItemInfo) { componentName = ((PendingAddItemInfo) d.dragInfo).componentName; } + final UserHandleCompat user; + if (d.dragInfo instanceof ItemInfo) { + user = ((ItemInfo) d.dragInfo).user; + } else { + user = UserHandleCompat.myUserHandle(); + } + if (componentName != null) { - mLauncher.startApplicationDetailsActivity(componentName); + mLauncher.startApplicationDetailsActivity(componentName, user); } // There is no post-drop animation, so clean up the DragView now diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index b5bed4cdfc..0ab665d748 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2726,13 +2726,19 @@ public class Launcher extends Activity */ protected void onInteractionBegin() {} - void startApplicationDetailsActivity(ComponentName componentName) { + void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { String packageName = componentName.getPackageName(); - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, - Uri.fromParts("package", packageName, null)); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | - Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - startActivitySafely(null, intent, "startApplicationDetailsActivity"); + try { + LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); + UserManagerCompat userManager = UserManagerCompat.getInstance(this); + launcherApps.showAppDetailsForProfile(componentName, user); + } catch (SecurityException e) { + Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); + Log.e(TAG, "Launcher does not have permission to launch settings"); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); + Log.e(TAG, "Unable to launch settings"); + } } // returns true if the activity was started diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java index cc0203d27f..0f8444b7a0 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompat.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java @@ -66,6 +66,7 @@ public abstract class LauncherAppsCompat { UserHandleCompat user); public abstract void startActivityForProfile(ComponentName component, UserHandleCompat user, Rect sourceBounds, Bundle opts); + public abstract void showAppDetailsForProfile(ComponentName component, UserHandleCompat user); public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java index de9f3a0322..c47f223f36 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java @@ -27,14 +27,21 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageInfo; import android.content.pm.ResolveInfo; import android.graphics.Rect; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.UserHandle; +import android.provider.Settings; import java.util.ArrayList; import java.util.Collections; import java.util.List; +/** + * Version of {@link LauncherAppsCompat} for devices with API level 16. + * Devices Pre-L don't support multiple profiles in one launcher so + * user parameters are ignored and all methods operate on the current user. + */ public class LauncherAppsCompatV16 extends LauncherAppsCompat { private PackageManager mPm; @@ -81,6 +88,15 @@ public class LauncherAppsCompatV16 extends LauncherAppsCompat { mContext.startActivity(launchIntent, opts); } + public void showAppDetailsForProfile(ComponentName component, UserHandleCompat user) { + String packageName = component.getPackageName(); + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + Uri.fromParts("package", packageName, null)); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | + Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + mContext.startActivity(intent, null); + } + public synchronized void addOnAppsChangedCallback(OnAppsChangedCallbackCompat callback) { if (callback != null && !mCallbacks.contains(callback)) { mCallbacks.add(callback); diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java index ca9b671460..e7de99cc0a 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java @@ -73,6 +73,10 @@ public class LauncherAppsCompatVL extends LauncherAppsCompat { mLauncherApps.startActivityForProfile(component, user.getUser(), sourceBounds, opts); } + public void showAppDetailsForProfile(ComponentName component, UserHandleCompat user) { + mLauncherApps.showAppDetailsForProfile(component, user.getUser(), null, null); + } + public void addOnAppsChangedCallback(LauncherAppsCompat.OnAppsChangedCallbackCompat callback) { WrappedCallback wrappedCallback = new WrappedCallback(callback); synchronized (mCallbacks) {