}
private void updateUser() {
+ int userId = ActivityManager.getCurrentUser();
synchronized (mLock) {
- if (mCurrentUserId != userId) {
- final int oldUserId = mCurrentUserId;
- mCurrentUserId = userId; // do this first
-
- UserRecord oldUser = mUserRecords.get(oldUserId);
- if (oldUser != null) {
- oldUser.stopLocked();
+ UserManager manager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
+ int currentUser = ActivityManager.getCurrentUser();
+ int[] userIds = manager.getEnabledProfileIds(currentUser);
+ mCurrentUserIdList.clear();
+ if (userIds != null && userIds.length > 0) {
+ for (int userId : userIds) {
+ mCurrentUserIdList.add(userId);
+ }
+ } else {
+ // This shouldn't happen.
+ Log.w(TAG, "Failed to get enabled profiles.");
+ mCurrentUserIdList.add(currentUser);
+ }
+ for (int userId : mCurrentUserIdList) {
+ if (mUserRecords.get(userId) == null) {
+ mUserRecords.put(userId, new UserRecord(getContext(), userId));
}
-
- UserRecord newUser = getOrCreateUser(userId);
- newUser.startLocked();
}
}
}
}
return;
}
- try {
- String packageName = getContext().getOpPackageName();
- mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
- flags, packageName, TAG);
- } catch (RemoteException e) {
- Log.e(TAG, "Error adjusting default volume.", e);
- }
+
+ // Execute mAudioService.adjustSuggestedStreamVolume() on
+ // handler thread of MediaSessionService.
+ // This will release the MediaSessionService.mLock sooner and avoid
+ // a potential deadlock between MediaSessionService.mLock and
+ // ActivityManagerService lock.
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ String packageName = getContext().getOpPackageName();
+ mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
+ flags, packageName, TAG);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error adjusting default volume.", e);
+ }
+ }
+ });
} else {
session.adjustVolume(direction, flags, getContext().getPackageName(),
- UserHandle.myUserId(), true);
+ Process.SYSTEM_UID, true);
}
}