diff options
| author | Marcel Dopita <m@rcel.cz> | 2015-10-12 11:30:17 -0700 |
|---|---|---|
| committer | Steve Kondik <shade@chemlab.org> | 2016-03-16 15:50:51 -0700 |
| commit | 19c3a8cd2ac39bd517556c7c63b868e45fd621ef (patch) | |
| tree | 19cf88b5625b506c3d5e8b20e0d14db8f329912c /core | |
| parent | c1fcac6ddfc114e37abe3205cf2f6aba117c4c7a (diff) | |
| download | frameworks_base-19c3a8cd2ac39bd517556c7c63b868e45fd621ef.zip frameworks_base-19c3a8cd2ac39bd517556c7c63b868e45fd621ef.tar.gz frameworks_base-19c3a8cd2ac39bd517556c7c63b868e45fd621ef.tar.bz2 | |
Show icons of only background apps in Toasts
As implemented and discussed in I82bf23664eea134f3b1f89ad5a99f6be73906ba8,
this patch disables the icons in Tosts for already foreground apps. It's
useful, no questions about that but please be aware of:
- Icons in Toasts are also displayed in "tooltips" of ActionBar (when you
press and hold an action). I think that goes agains material design as the
ActionBar component now doesn't even show app icon.
- Toasts from Android OS contain the Green robot. (IMHO: It was never intended
for system Toast to have an icon)
- Toasts are intended "to be as unobtrusive as possible" and this kinds of
break it. (From javadoc)
- Icons should stay as workaround for finding that badly designed/intrusive
app because: "Your app should not create a dialog or toast if it is not
currently on screen." (From notifications design paterns)
- Not that relevant but not all users welcome this aesthetic:
https://www.reddit.com/r/cyanogenmod/comments/3oazh8/does_the_icon_in_the_toast_notification_bother/
https://www.reddit.com/r/cyanogenmod/comments/3jg5c2/icons_on_toasts/
etc.
Change-Id: If748297bd422c7ddbf061da735b8e4ed0a41b425
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 17 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 21 | ||||
| -rw-r--r-- | core/java/android/app/IActivityManager.java | 2 | ||||
| -rw-r--r-- | core/java/android/widget/Toast.java | 19 |
4 files changed, 52 insertions, 7 deletions
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index ad08c23..0ae9187 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -1326,6 +1326,23 @@ public class ActivityManager { } /** + * Check whether the current foreground tasks belongs to a given package. + * + * @param packageName Name of the package to check for + * + * @return Whether the current foreground tasks belongs to the given package + * @hide + */ + public boolean isPackageInForeground(String packageName) { + try { + return ActivityManagerNative.getDefault().isPackageInForeground(packageName); + } catch (RemoteException e) { + // System dead, we will be dead too soon! + return false; + } + } + + /** * Completely remove the given task. * * @param taskId Identifier of the task to be removed. diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index d638de6..ff06b74 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -647,6 +647,15 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } + case IS_PACKAGE_IN_FOREGROUND_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + String packageName = data.readString(); + boolean result = isPackageInForeground(packageName); + reply.writeNoException(); + reply.writeInt(result ? 1 : 0); + return true; + } + case GET_RECENT_TASKS_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); int maxNum = data.readInt(); @@ -3300,6 +3309,18 @@ class ActivityManagerProxy implements IActivityManager reply.recycle(); return list; } + public boolean isPackageInForeground(String packageName) throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeString(packageName); + mRemote.transact(IS_PACKAGE_IN_FOREGROUND_TRANSACTION, data, reply, 0); + reply.readException(); + boolean result = reply.readInt() != 0; + data.recycle(); + reply.recycle(); + return result; + } public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) throws RemoteException { Parcel data = Parcel.obtain(); diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index a27f9c8..6370268 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -129,6 +129,7 @@ public interface IActivityManager extends IInterface { ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException; public Point getAppTaskThumbnailSize() throws RemoteException; public List<RunningTaskInfo> getTasks(int maxNum, int flags) throws RemoteException; + public boolean isPackageInForeground(String packageName) throws RemoteException; public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) throws RemoteException; public ActivityManager.TaskThumbnail getTaskThumbnail(int taskId) throws RemoteException; @@ -870,4 +871,5 @@ public interface IActivityManager extends IInterface { = IBinder.FIRST_CALL_TRANSACTION+299; int SHOW_ASSIST_FROM_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+300; int IS_ROOT_VOICE_INTERACTION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+301; + int IS_PACKAGE_IN_FOREGROUND_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+302; } diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index 4b31af0..e8dccab 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -18,6 +18,7 @@ package android.widget; import android.annotation.IntDef; import android.annotation.StringRes; +import android.app.ActivityManager; import android.app.INotificationManager; import android.app.ITransientNotification; import android.content.Context; @@ -405,14 +406,18 @@ public class Toast { ImageView appIcon = (ImageView) mView.findViewById(android.R.id.icon); if (appIcon != null) { - PackageManager pm = context.getPackageManager(); - Drawable icon = null; - try { - icon = pm.getApplicationIcon(packageName); - } catch (PackageManager.NameNotFoundException e) { - // nothing to do + ActivityManager am = + (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + if (!am.isPackageInForeground(packageName)) { + PackageManager pm = context.getPackageManager(); + Drawable icon = null; + try { + icon = pm.getApplicationIcon(packageName); + } catch (PackageManager.NameNotFoundException e) { + // nothing to do + } + appIcon.setImageDrawable(icon); } - appIcon.setImageDrawable(icon); } mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); // We can resolve the Gravity here by using the Locale for getting |
