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

Commit bb4ca527 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #7649590: Background windows sometimes not being hidden for secondary users

There are two things going on here:

(1) In secondary users, some times theme information such as whether
the window is full screen opaque was not being retrieved, so the window
manager didn't know that it could hide the windows behind the app.
This would just be a performance problem, except that:

(2) There appear to be a number of applications that declare that they
are full screen opaque, when in fact they are not.  Instead they are
using window surfaces with an alpha channel, and setting some pixels
in their window to a non-opaque alpha level.  This will allow you to
see whatever is behind the app.  If the system happens to completely
remove the windows behind the app, and somebody is filling the frame
buffer with black, then you will see what the app intends -- those
parts of its UI blended with black.  If one of those cases doesn't
hold (and though we have never guaranteed they would, in practice this
is generally what happens), then you will see something else.

At any rate, if nothing else than for performance reasons, we need to
fix issue #1.

It turns out what is happening here is that the AttributeCache used
by the activity manager and window manager to retreive theme and other
information about applications has not yet been updated for multi-user.

One of the things we retrieve from this is the theme information telling
the window manager whether an application's window should be treated
as full screen opaque, allowing it to hide any windows behind it.  In
the current implementation, the AttributeCache always retrieves this
information about the application as the primary user (user 0).

So, if you have an application that is installed on a secondary user but
not installed on the primary user, when the AttributeCache tries to retrieve
the requested information for it, then from the perspective of the primary user
it considers the application not installed, and is not able to retrieve that
info.

The change here makes AttributeCache multi-user aware, keeping all of its
data separately per-user, and requiring that callers now provide the user
they want to retrieve information for.  Activity manager and window manager
are updated to be able to pass in the user when needed.  This required some
fiddling of the window manager to have that information available -- in
particular it needs to be associated with the AppWindowToken.

Change-Id: I4b50b4b3a41bab9d4689e61f3584778e451343c8
parent f8748809
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ interface IWindowManager
    void setEventDispatching(boolean enabled);
    void addWindowToken(IBinder token, int type);
    void removeWindowToken(IBinder token);
    void addAppToken(int addPos, IApplicationToken token,
    void addAppToken(int addPos, int userId, IApplicationToken token,
            int groupId, int requestedOrientation, boolean fullscreen, boolean showWhenLocked);
    void setAppGroupId(IBinder token, int groupId);
    void setAppOrientation(IApplicationToken token, int requestedOrientation);
+33 −18
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.UserHandle;
import android.util.SparseArray;

import java.util.HashMap;
@@ -36,8 +37,8 @@ public final class AttributeCache {
    private static AttributeCache sInstance = null;

    private final Context mContext;
    private final WeakHashMap<String, Package> mPackages =
            new WeakHashMap<String, Package>();
    private final SparseArray<WeakHashMap<String, Package>> mPackages =
            new SparseArray<WeakHashMap<String, Package>>();
    private final Configuration mConfiguration = new Configuration();

    public final static class Package {
@@ -76,7 +77,9 @@ public final class AttributeCache {

    public void removePackage(String packageName) {
        synchronized (this) {
            mPackages.remove(packageName);
            for (int i=0; i<mPackages.size(); i++) {
                mPackages.valueAt(i).remove(packageName);
            }
        }
    }

@@ -94,9 +97,20 @@ public final class AttributeCache {
        }
    }

    public Entry get(String packageName, int resId, int[] styleable) {
    public void removeUser(int userId) {
        synchronized (this) {
            mPackages.remove(userId);
        }
    }

    public Entry get(int userId, String packageName, int resId, int[] styleable) {
        synchronized (this) {
            Package pkg = mPackages.get(packageName);
            WeakHashMap<String, Package> packages = mPackages.get(userId);
            if (packages == null) {
                packages = new WeakHashMap<String, Package>();
                mPackages.put(userId, packages);
            }
            Package pkg = packages.get(packageName);
            HashMap<int[], Entry> map = null;
            Entry ent = null;
            if (pkg != null) {
@@ -110,7 +124,8 @@ public final class AttributeCache {
            } else {
                Context context;
                try {
                    context = mContext.createPackageContext(packageName, 0);
                    context = mContext.createPackageContextAsUser(packageName, 0,
                            new UserHandle(userId));
                    if (context == null) {
                        return null;
                    }
@@ -118,7 +133,7 @@ public final class AttributeCache {
                    return null;
                }
                pkg = new Package(context);
                mPackages.put(packageName, pkg);
                packages.put(packageName, pkg);
            }
            
            if (map == null) {
+4 −0
Original line number Diff line number Diff line
@@ -14551,6 +14551,10 @@ public final class ActivityManagerService extends ActivityManagerNative
                // Clean up all state and processes associated with the user.
                // Kill all the processes for the user.
                forceStopUserLocked(userId);
                AttributeCache ac = AttributeCache.instance();
                if (ac != null) {
                    ac.removeUser(userId);
                }
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -407,7 +407,7 @@ final class ActivityRecord {
            packageName = aInfo.applicationInfo.packageName;
            launchMode = aInfo.launchMode;
            
            AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
            AttributeCache.Entry ent = AttributeCache.instance().get(userId, packageName,
                    realTheme, com.android.internal.R.styleable.Window);
            fullscreen = ent != null && !ent.array.getBoolean(
                    com.android.internal.R.styleable.Window_windowIsFloating, false)
+6 −6
Original line number Diff line number Diff line
@@ -1810,8 +1810,8 @@ final class ActivityStack {
                        }
                        mHistory.add(addPos, r);
                        r.putInHistory();
                        mService.mWindowManager.addAppToken(addPos, r.appToken, r.task.taskId,
                                r.info.screenOrientation, r.fullscreen,
                        mService.mWindowManager.addAppToken(addPos, r.userId, r.appToken,
                                r.task.taskId, r.info.screenOrientation, r.fullscreen,
                                (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
                        if (VALIDATE_TOKENS) {
                            validateAppTokensLocked();
@@ -1875,8 +1875,8 @@ final class ActivityStack {
                mNoAnimActivities.remove(r);
            }
            r.updateOptionsLocked(options);
            mService.mWindowManager.addAppToken(
                    addPos, r.appToken, r.task.taskId, r.info.screenOrientation, r.fullscreen,
            mService.mWindowManager.addAppToken(addPos, r.userId, r.appToken,
                    r.task.taskId, r.info.screenOrientation, r.fullscreen,
                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
            boolean doShow = true;
            if (newTask) {
@@ -1914,8 +1914,8 @@ final class ActivityStack {
        } else {
            // If this is the first activity, don't do any fancy animations,
            // because there is nothing for it to animate on top of.
            mService.mWindowManager.addAppToken(addPos, r.appToken, r.task.taskId,
                    r.info.screenOrientation, r.fullscreen,
            mService.mWindowManager.addAppToken(addPos, r.userId, r.appToken,
                    r.task.taskId, r.info.screenOrientation, r.fullscreen,
                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0);
            ActivityOptions.abort(options);
        }
Loading