This is for the multi-user version of bindService, not the original.
Change-Id: Ib2de35941196accf387b1a276a77e6f9af805ec0
public boolean bindService(Intent service, ServiceConnection conn,
int flags) {
warnIfCallingFromSystemProcess();
- return bindService(service, conn, flags, UserHandle.getUserId(Process.myUid()));
+ return bindServiceAsUser(service, conn, flags, Process.myUserHandle());
}
/** @hide */
@Override
- public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
+ UserHandle user) {
IServiceConnection sd;
if (conn == null) {
throw new IllegalArgumentException("connection is null");
int res = ActivityManagerNative.getDefault().bindService(
mMainThread.getApplicationThread(), getActivityToken(),
service, service.resolveTypeIfNeeded(getContentResolver()),
- sd, flags, userHandle);
+ sd, flags, user.getIdentifier());
if (res < 0) {
throw new SecurityException(
"Not allowed to bind to service " + service);
* argument for use by system server and other multi-user aware code.
* @hide
*/
- public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
/** @hide */
@Override
- public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
- return mBase.bindService(service, conn, flags, userHandle);
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
+ UserHandle user) {
+ return mBase.bindServiceAsUser(service, conn, flags, user);
}
@Override
@Override
public void onServiceDisconnected(ComponentName name) {}
};
- if (mContext.bindService(
- intent, conn, Context.BIND_AUTO_CREATE, UserHandle.USER_CURRENT)) {
+ if (mContext.bindServiceAsUser(
+ intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
mScreenshotConnection = conn;
mHandler.postDelayed(mScreenshotTimeout, 10000);
}
if (!mBoundToService) {
Log.d(TAG, "Binding to Face Unlock service for user="
+ mLockPatternUtils.getCurrentUser());
- mContext.bindService(new Intent(IFaceLockInterface.class.getName()),
+ mContext.bindServiceAsUser(new Intent(IFaceLockInterface.class.getName()),
mConnection,
Context.BIND_AUTO_CREATE,
- mLockPatternUtils.getCurrentUser());
+ new UserHandle(mLockPatternUtils.getCurrentUser()));
mBoundToService = true;
} else {
Log.w(TAG, "Attempt to bind to Face Unlock when already bound");
final long token = Binder.clearCallingIdentity();
try {
conn = new ServiceConnectionProxy(key, connection);
- mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE, userId);
+ mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+ new UserHandle(userId));
mBoundRemoteViewsServices.put(key, conn);
} finally {
Binder.restoreCallingIdentity(token);
// RemoteViewsService.
final long token = Binder.clearCallingIdentity();
try {
- mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE, userId);
+ mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+ new UserHandle(userId));
} finally {
Binder.restoreCallingIdentity(token);
}
// Bind to the service and call onDataSetChanged()
final long token = Binder.clearCallingIdentity();
try {
- mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE, userId);
+ mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+ new UserHandle(userId));
} finally {
Binder.restoreCallingIdentity(token);
}
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
if (DEBUG) Slog.v(TAG, "Binding to Google transport");
Intent intent = new Intent().setComponent(transportComponent);
- context.bindService(intent, mGoogleConnection, Context.BIND_AUTO_CREATE,
- UserHandle.USER_OWNER);
+ context.bindServiceAsUser(intent, mGoogleConnection, Context.BIND_AUTO_CREATE,
+ UserHandle.OWNER);
} else {
Slog.w(TAG, "Possible Google transport spoof: ignoring " + info);
}
Message timeoutMsg = mHandler.obtainMessage(MESSAGE_TIMEOUT_BIND);
mHandler.sendMessageDelayed(timeoutMsg,TIMEOUT_BIND_MS);
Intent i = new Intent(IBluetooth.class.getName());
- if (!mContext.bindService(i, mConnection,
- Context.BIND_AUTO_CREATE, UserHandle.USER_CURRENT)) {
+ if (!mContext.bindServiceAsUser(i, mConnection,
+ Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);
Log.e(TAG, "fail to bind to: " + IBluetooth.class.getName());
} else {
mHandler.sendMessageDelayed(timeoutMsg,TIMEOUT_BIND_MS);
mConnection.setGetNameAddressOnly(false);
Intent i = new Intent(IBluetooth.class.getName());
- if (!mContext.bindService(i, mConnection,Context.BIND_AUTO_CREATE,
- UserHandle.USER_CURRENT)) {
+ if (!mContext.bindServiceAsUser(i, mConnection,Context.BIND_AUTO_CREATE,
+ UserHandle.CURRENT)) {
mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);
Log.e(TAG, "Fail to bind to: " + IBluetooth.class.getName());
} else {
Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
return false;
}
- return mContext.bindService(service, conn, flags, mSettings.getCurrentUserId());
+ return mContext.bindServiceAsUser(service, conn, flags,
+ new UserHandle(mSettings.getCurrentUserId()));
}
@Override
mPackageName = packageName;
mVersion = version;
if (D) Log.d(mTag, "binding " + packageName + " (version " + version + ")");
- mContext.bindService(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
- | Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_NOT_VISIBLE, mCurrentUserId);
+ mContext.bindServiceAsUser(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
+ | Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_NOT_VISIBLE,
+ new UserHandle(mCurrentUserId));
}
public static boolean isSignatureMatch(Signature[] signatures,
Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
return false;
}
- return mContext.bindService(service, conn, flags, mSettings.getCurrentUserId());
+ return mContext.bindServiceAsUser(service, conn, flags,
+ new UserHandle(mSettings.getCurrentUserId()));
}
private void unbindServiceLocked() {
Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
0, null, new UserHandle(serviceUserId)));
- if (!mContext.bindService(intent, newConn, Context.BIND_AUTO_CREATE, serviceUserId)) {
+ if (!mContext.bindServiceAsUser(intent, newConn, Context.BIND_AUTO_CREATE,
+ new UserHandle(serviceUserId))) {
String msg = "Unable to bind service: "
+ componentName;
if (fromUser) {
*/
public boolean bind() {
if (!mIsAutomation && mService == null) {
- return mContext.bindService(mIntent, this, Context.BIND_AUTO_CREATE, mUserId);
+ return mContext.bindServiceAsUser(mIntent, this, Context.BIND_AUTO_CREATE,
+ new UserHandle(mUserId));
}
return false;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "performing bindService to " + authenticatorInfo.componentName);
}
- if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE, mAccounts.userId)) {
+ if (!mContext.bindServiceAsUser(intent, this, Context.BIND_AUTO_CREATE,
+ new UserHandle(mAccounts.userId))) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "bindService to " + authenticatorInfo.componentName + " failed");
}
mContext, 0, new Intent(Settings.ACTION_SYNC_SETTINGS), 0,
null, new UserHandle(userId)));
mBound = true;
- final boolean bindResult = mContext.bindService(intent, this,
+ final boolean bindResult = mContext.bindServiceAsUser(intent, this,
Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
| Context.BIND_ALLOW_OOM_MANAGEMENT,
- mSyncOperation.userId);
+ new UserHandle(mSyncOperation.userId));
if (!bindResult) {
mBound = false;
}
intent.setComponent(name);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
try {
- if (!mContext.bindService(intent, mCurrentDream,
- Context.BIND_AUTO_CREATE, userId)) {
+ if (!mContext.bindServiceAsUser(intent, mCurrentDream,
+ Context.BIND_AUTO_CREATE, new UserHandle(userId))) {
Slog.e(TAG, "Unable to bind dream service: " + intent);
stopDream();
return;
" DefaultContainerService");
Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
- if (mContext.bindService(service, mDefContainerConn,
- Context.BIND_AUTO_CREATE, UserHandle.USER_OWNER)) {
+ if (mContext.bindServiceAsUser(service, mDefContainerConn,
+ Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
mBound = true;
return true;
users = new int[] { userId };
}
final ClearStorageConnection conn = new ClearStorageConnection();
- if (mContext.bindService(
- containerIntent, conn, Context.BIND_AUTO_CREATE, UserHandle.USER_OWNER)) {
+ if (mContext.bindServiceAsUser(
+ containerIntent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
try {
for (int curUser : users) {
long timeout = SystemClock.uptimeMillis() + 5000;
/** @hide */
@Override
- public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
+ public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
+ UserHandle user) {
throw new UnsupportedOperationException();
}