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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,4 +885,12 @@ public class ContextWrapper extends Context {
|
||||
public IApplicationThread getIApplicationThread() {
|
||||
return mBase.getIApplicationThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
public Handler getMainThreadHandler() {
|
||||
return mBase.getMainThreadHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,4 +780,10 @@ public class MockContext extends Context {
|
||||
public IApplicationThread getIApplicationThread() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@Override
|
||||
public Handler getMainThreadHandler() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user