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

Commit 8473a2c1 authored by Alan Stokes's avatar Alan Stokes
Browse files

Fix for client tracking on bind to service.

We were not correctly updating the bound client UIDs when binding to a
service with an already-running process. This could result in a
background activity start by the app hosting the service being
incorrectly blocked.

(Also includes a drive-by fix of a potential NPE.)

Bug: 131468397
Test: Manually verified YouTube VR problem is fixed.
Test: atest BackgroundActivityLaunchTest
Test: atest RootWindowContainerTests
Test: atest WmTests:ActivityStarterTests
Test: atest CtsWindowManagerDeviceTestCases:ActivityStarterTests
Test: atest CtsAppTestCases:.ServiceTest
Change-Id: I153cf3678f10439075af39a8bd88ff8d492e1ffe
parent 7abba0a4
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -1768,12 +1768,7 @@ public final class ActiveServices {
                    callerApp.uid, callerApp.processName, callingPackage);

            IBinder binder = connection.asBinder();
            ArrayList<ConnectionRecord> clist = s.getConnections().get(binder);
            if (clist == null) {
                clist = new ArrayList<ConnectionRecord>();
                s.putConnection(binder, clist);
            }
            clist.add(c);
            s.addConnection(binder, c);
            b.connections.add(c);
            if (activity != null) {
                activity.addConnection(c);
@@ -1792,9 +1787,9 @@ public final class ActiveServices {
            if (s.app != null) {
                updateServiceClientActivitiesLocked(s.app, c, true);
            }
            clist = mServiceConnections.get(binder);
            ArrayList<ConnectionRecord> clist = mServiceConnections.get(binder);
            if (clist == null) {
                clist = new ArrayList<ConnectionRecord>();
                clist = new ArrayList<>();
                mServiceConnections.put(binder, clist);
            }
            clist.add(c);
@@ -3828,8 +3823,8 @@ public final class ActiveServices {
    public PendingIntent getRunningServiceControlPanelLocked(ComponentName name) {
        int userId = UserHandle.getUserId(Binder.getCallingUid());
        ServiceRecord r = getServiceByNameLocked(name, userId);
        ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections = r.getConnections();
        if (r != null) {
            ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections = r.getConnections();
            for (int conni = connections.size() - 1; conni >= 0; conni--) {
                ArrayList<ConnectionRecord> conn = connections.valueAt(conni);
                for (int i=0; i<conn.size(); i++) {
+2 −2
Original line number Diff line number Diff line
@@ -1186,8 +1186,8 @@ class ProcessRecord implements WindowProcessListener {
                !mAllowBackgroundActivityStartsTokens.isEmpty());
    }

    void addBoundClientUids(ArraySet<Integer> clientUids) {
        mBoundClientUids.addAll(clientUids);
    void addBoundClientUid(int clientUid) {
        mBoundClientUids.add(clientUid);
        mWindowProcessController.setBoundClientUids(mBoundClientUids);
    }

+10 −9
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;
@@ -580,15 +579,17 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
        return connections;
    }

    void putConnection(IBinder binder, ArrayList<ConnectionRecord> clist) {
    void addConnection(IBinder binder, ConnectionRecord c) {
        ArrayList<ConnectionRecord> clist = connections.get(binder);
        if (clist == null) {
            clist = new ArrayList<>();
            connections.put(binder, clist);
        // if we have a process attached, add bound client uids of this connection to it
        if (app != null) {
            ArraySet<Integer> boundClientUids = new ArraySet<>();
            for (int i = 0; i < clist.size(); i++) {
                boundClientUids.add(clist.get(i).clientUid);
        }
            app.addBoundClientUids(boundClientUids);
        clist.add(c);

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