Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19c3a8cd authored by Marcel Dopita's avatar Marcel Dopita Committed by Steve Kondik
Browse files

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
parent c1fcac6d
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1325,6 +1325,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.
     *
+21 −0
Original line number Diff line number Diff line
@@ -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();
+2 −0
Original line number Diff line number Diff line
@@ -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;
}
+12 −7
Original line number Diff line number Diff line
@@ -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,6 +406,9 @@ public class Toast {

                ImageView appIcon = (ImageView) mView.findViewById(android.R.id.icon);
                if (appIcon != null) {
                    ActivityManager am =
                            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
                    if (!am.isPackageInForeground(packageName)) {
                        PackageManager pm = context.getPackageManager();
                        Drawable icon = null;
                        try {
@@ -414,6 +418,7 @@ public class Toast {
                        }
                        appIcon.setImageDrawable(icon);
                    }
                }
                mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
                // We can resolve the Gravity here by using the Locale for getting
                // the layout direction
+8 −0
Original line number Diff line number Diff line
@@ -8605,6 +8605,14 @@ public final class ActivityManagerService extends ActivityManagerNative
        return list;
    }
    @Override
    public boolean isPackageInForeground(String packageName) {
        synchronized (this) {
            ActivityRecord activity = mStackSupervisor.topRunningActivityLocked();
            return activity != null && activity.packageName.equals(packageName);
        }
    }
    /**
     * Creates a new RecentTaskInfo from a TaskRecord.
     */