OSDN Git Service

resolve merge conflicts of 78120b0 to nyc-mr1-dev-plus-aosp
authorJaewan Kim <jaewan@google.com>
Wed, 13 Jul 2016 01:55:06 +0000 (10:55 +0900)
committerJaewan Kim <jaewan@google.com>
Wed, 13 Jul 2016 01:55:06 +0000 (10:55 +0900)
1  2 
services/core/java/com/android/server/media/MediaSessionService.java

@@@ -227,19 -236,24 +236,25 @@@ public class MediaSessionService extend
      }
  
      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);
              }
          }