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

Commit bf9928de authored by Tony Mak's avatar Tony Mak
Browse files

Make sure ServiceConnection callback is called in main thread

Fix: 33568999

Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases
--test com.android.cts.devicepolicy.DeviceOwnerPlusManagedProfileTest

Change-Id: I14c8b5b1f78192429e68a3057430406245a909c8
parent 5394fd04
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1470,6 +1470,12 @@ class ContextImpl extends Context {
        return mMainThread.getApplicationThread();
    }

    /** @hide */
    @Override
    public Handler getMainThreadHandler() {
        return mMainThread.getHandler();
    }

    private boolean bindServiceCommon(Intent service, ServiceConnection conn, int flags, Handler
            handler, UserHandle user) {
        // Keep this in sync with DevicePolicyManager.bindDeviceAdminServiceAsUser.
+4 −3
Original line number Diff line number Diff line
@@ -7111,8 +7111,8 @@ public class DevicePolicyManager {
     * @param serviceIntent Identifies the service to connect to.  The Intent must specify either an
     *        explicit component name or a package name to match an
     *        {@link IntentFilter} published by a service.
     * @param conn Receives information as the service is started and stopped. This must be a
     *        valid {@link ServiceConnection} object; it must not be {@code null}.
     * @param conn Receives information as the service is started and stopped in main thread. This
     *        must be a valid {@link ServiceConnection} object; it must not be {@code null}.
     * @param flags Operation options for the binding operation. See
     *        {@link Context#bindService(Intent, ServiceConnection, int)}.
     * @param targetUser Which user to bind to. Must be one of the users returned by
@@ -7131,7 +7131,8 @@ public class DevicePolicyManager {
        throwIfParentInstance("bindDeviceAdminServiceAsUser");
        // Keep this in sync with ContextImpl.bindServiceCommon.
        try {
            final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
            final IServiceConnection sd = mContext.getServiceDispatcher(
                    conn, mContext.getMainThreadHandler(), flags);
            serviceIntent.prepareToLeaveProcess(mContext);
            return mService.bindDeviceAdminServiceAsUser(admin,
                    mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
+7 −0
Original line number Diff line number Diff line
@@ -4403,4 +4403,11 @@ public abstract class Context {
    public IApplicationThread getIApplicationThread() {
        throw new RuntimeException("Not implemented. Must override in a subclass.");
    }

    /**
     * @hide
     */
    public Handler getMainThreadHandler() {
        throw new RuntimeException("Not implemented. Must override in a subclass.");
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -885,4 +885,12 @@ public class ContextWrapper extends Context {
    public IApplicationThread getIApplicationThread() {
        return mBase.getIApplicationThread();
    }

    /**
     * @hide
     */
    @Override
    public Handler getMainThreadHandler() {
        return mBase.getMainThreadHandler();
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -780,4 +780,10 @@ public class MockContext extends Context {
    public IApplicationThread getIApplicationThread() {
        throw new UnsupportedOperationException();
    }

    /** {@hide} */
    @Override
    public Handler getMainThreadHandler() {
        throw new UnsupportedOperationException();
    }
}