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

Commit 8efec2c0 authored by Nan Wu's avatar Nan Wu
Browse files

DO NOT MERGE Disallow Wallpaper service to launch activity from background.

Add a flag so that when a foreground client binds to a service,
disallow the bound service to launch activity from background.
Modify the WallpaperManagerService to take advantage of the new flag.

Test: atest BackgroundActivityLaunchTest WallpaperManagerServiceTests
Bug: 298094386
Change-Id: Id4e4cb6144597cf3638f2aaa34ea455a239fa1a7
parent 5233950a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -272,6 +272,7 @@ public abstract class Context {
            BIND_IMPORTANT,
            BIND_ADJUST_WITH_ACTIVITY,
            BIND_NOT_PERCEPTIBLE,
            BIND_DENY_ACTIVITY_STARTS_PRE_34,
            BIND_INCLUDE_CAPABILITIES
    })
    @Retention(RetentionPolicy.SOURCE)
@@ -392,6 +393,14 @@ public abstract class Context {
    /***********    Public flags above this line ***********/
    /***********    Hidden flags below this line ***********/

    /**
     * Flag for {@link #bindService}: If binding from an app that is visible, the bound service is
     * allowed to start an activity from background. Add a flag so that this behavior can be opted
     * out.
     * @hide
     */
    public static final int BIND_DENY_ACTIVITY_STARTS_PRE_34 = 0X000004000;

    /**
     * Flag for {@link #bindService}: This flag is only intended to be used by the system to
     * indicate that a service binding is not considered as real package component usage and should
+1 −0
Original line number Diff line number Diff line
@@ -524,6 +524,7 @@ message ConnectionRecordProto {
        DEAD = 15;
        NOT_PERCEPTIBLE = 16;
        INCLUDE_CAPABILITIES = 17;
        DENY_ACTIVITY_STARTS_PRE_34 = 18;
    }
    repeated Flag flags = 3;
    optional string service_name = 4;
+5 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ final class ConnectionRecord {
            Context.BIND_NOT_VISIBLE,
            Context.BIND_NOT_PERCEPTIBLE,
            Context.BIND_INCLUDE_CAPABILITIES,
            Context.BIND_DENY_ACTIVITY_STARTS_PRE_34,
    };
    private static final int[] BIND_PROTO_ENUMS = new int[] {
            ConnectionRecordProto.AUTO_CREATE,
@@ -96,6 +97,7 @@ final class ConnectionRecord {
            ConnectionRecordProto.NOT_VISIBLE,
            ConnectionRecordProto.NOT_PERCEPTIBLE,
            ConnectionRecordProto.INCLUDE_CAPABILITIES,
            ConnectionRecordProto.DENY_ACTIVITY_STARTS_PRE_34,
    };

    void dump(PrintWriter pw, String prefix) {
@@ -237,6 +239,9 @@ final class ConnectionRecord {
        if ((flags & Context.BIND_NOT_PERCEPTIBLE) != 0) {
            sb.append("!PRCP ");
        }
        if ((flags & Context.BIND_DENY_ACTIVITY_STARTS_PRE_34) != 0) {
            sb.append("BALFD ");
        }
        if ((flags & Context.BIND_INCLUDE_CAPABILITIES) != 0) {
            sb.append("CAPS ");
        }
+15 −8
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.internal.annotations.GuardedBy;
import com.android.server.wm.WindowProcessController;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -414,19 +415,21 @@ final class ProcessServiceRecord {
        return mConnections.size();
    }

    void addBoundClientUid(int clientUid) {
    void addBoundClientUid(int clientUid, String clientPackageName, int bindFlags) {
        mBoundClientUids.add(clientUid);
        mApp.getWindowProcessController().setBoundClientUids(mBoundClientUids);
        mApp.getWindowProcessController()
                .addBoundClientUid(clientUid, clientPackageName, bindFlags);
    }

    void updateBoundClientUids() {
        if (mServices.isEmpty()) {
        clearBoundClientUids();
        if (mServices.isEmpty()) {
            return;
        }
        // grab a set of clientUids of all mConnections of all services
        final ArraySet<Integer> boundClientUids = new ArraySet<>();
        final int serviceCount = mServices.size();
        WindowProcessController controller = mApp.getWindowProcessController();
        for (int j = 0; j < serviceCount; j++) {
            final ArrayMap<IBinder, ArrayList<ConnectionRecord>> conns =
                    mServices.valueAt(j).getConnections();
@@ -434,12 +437,13 @@ final class ProcessServiceRecord {
            for (int conni = 0; conni < size; conni++) {
                ArrayList<ConnectionRecord> c = conns.valueAt(conni);
                for (int i = 0; i < c.size(); i++) {
                    boundClientUids.add(c.get(i).clientUid);
                    ConnectionRecord cr = c.get(i);
                    boundClientUids.add(cr.clientUid);
                    controller.addBoundClientUid(cr.clientUid, cr.clientPackageName, cr.flags);
                }
            }
        }
        mBoundClientUids = boundClientUids;
        mApp.getWindowProcessController().setBoundClientUids(mBoundClientUids);
    }

    void addBoundClientUidsOfNewService(ServiceRecord sr) {
@@ -450,15 +454,18 @@ final class ProcessServiceRecord {
        for (int conni = conns.size() - 1; conni >= 0; conni--) {
            ArrayList<ConnectionRecord> c = conns.valueAt(conni);
            for (int i = 0; i < c.size(); i++) {
                mBoundClientUids.add(c.get(i).clientUid);
                ConnectionRecord cr = c.get(i);
                mBoundClientUids.add(cr.clientUid);
                mApp.getWindowProcessController()
                        .addBoundClientUid(cr.clientUid, cr.clientPackageName, cr.flags);

            }
        }
        mApp.getWindowProcessController().setBoundClientUids(mBoundClientUids);
    }

    void clearBoundClientUids() {
        mBoundClientUids.clear();
        mApp.getWindowProcessController().setBoundClientUids(mBoundClientUids);
        mApp.getWindowProcessController().clearBoundClientUids();
    }

    @GuardedBy("mService")
+1 −1
Original line number Diff line number Diff line
@@ -738,7 +738,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN

        // if we have a process attached, add bound client uid of this connection to it
        if (app != null) {
            app.mServices.addBoundClientUid(c.clientUid);
            app.mServices.addBoundClientUid(c.clientUid, c.clientPackageName, c.flags);
            app.mProfile.addHostingComponentType(HOSTING_COMPONENT_TYPE_BOUND_SERVICE);
        }
    }
Loading