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

Commit cb7c43e2 authored by Jin Seok Park's avatar Jin Seok Park
Browse files

Remove using hidden UserHandle APIs

Replace with equivalent SystemApis.

Bug: 160833463
Test: build
Change-Id: I12c8a9b3ba7e77a8e7435e122efe0594c059a456
parent 907c76ba
Loading
Loading
Loading
Loading
+22 −19
Original line number Original line Diff line number Diff line
@@ -16,7 +16,8 @@


package com.android.server.media;
package com.android.server.media;


import static android.os.UserHandle.USER_ALL;
import static android.os.UserHandle.ALL;
import static android.os.UserHandle.CURRENT;


import static com.android.server.media.MediaKeyDispatcher.KEY_EVENT_LONG_PRESS;
import static com.android.server.media.MediaKeyDispatcher.KEY_EVENT_LONG_PRESS;
import static com.android.server.media.MediaKeyDispatcher.isDoubleTapOverridden;
import static com.android.server.media.MediaKeyDispatcher.isDoubleTapOverridden;
@@ -252,7 +253,7 @@ public class MediaSessionService extends SystemService implements Monitor {


    private List<MediaSessionRecord> getActiveSessionsLocked(int userId) {
    private List<MediaSessionRecord> getActiveSessionsLocked(int userId) {
        List<MediaSessionRecord> records = new ArrayList<>();
        List<MediaSessionRecord> records = new ArrayList<>();
        if (userId == USER_ALL) {
        if (userId == ALL.getIdentifier()) {
            int size = mUserRecords.size();
            int size = mUserRecords.size();
            for (int i = 0; i < size; i++) {
            for (int i = 0; i < size; i++) {
                records.addAll(mUserRecords.valueAt(i).mPriorityStack.getActiveSessions(userId));
                records.addAll(mUserRecords.valueAt(i).mPriorityStack.getActiveSessions(userId));
@@ -268,7 +269,8 @@ public class MediaSessionService extends SystemService implements Monitor {


        // Return global priority session at the first whenever it's asked.
        // Return global priority session at the first whenever it's asked.
        if (isGlobalPriorityActiveLocked()
        if (isGlobalPriorityActiveLocked()
                && (userId == USER_ALL || userId == mGlobalPrioritySession.getUserId())) {
                && (userId == ALL.getIdentifier()
                        || userId == mGlobalPrioritySession.getUserId())) {
            records.add(0, mGlobalPrioritySession);
            records.add(0, mGlobalPrioritySession);
        }
        }
        return records;
        return records;
@@ -276,7 +278,7 @@ public class MediaSessionService extends SystemService implements Monitor {


    List<Session2Token> getSession2TokensLocked(int userId) {
    List<Session2Token> getSession2TokensLocked(int userId) {
        List<Session2Token> list = new ArrayList<>();
        List<Session2Token> list = new ArrayList<>();
        if (userId == USER_ALL) {
        if (userId == ALL.getIdentifier()) {
            int size = mUserRecords.size();
            int size = mUserRecords.size();
            for (int i = 0; i < size; i++) {
            for (int i = 0; i < size; i++) {
                list.addAll(mUserRecords.valueAt(i).mPriorityStack.getSession2Tokens(userId));
                list.addAll(mUserRecords.valueAt(i).mPriorityStack.getSession2Tokens(userId));
@@ -352,7 +354,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            FullUserRecord user = getFullUserRecordLocked(userId);
            FullUserRecord user = getFullUserRecordLocked(userId);
            if (user != null) {
            if (user != null) {
                if (user.mFullUserId == userId) {
                if (user.mFullUserId == userId) {
                    user.destroySessionsForUserLocked(USER_ALL);
                    user.destroySessionsForUserLocked(ALL.getIdentifier());
                    mUserRecords.remove(userId);
                    mUserRecords.remove(userId);
                } else {
                } else {
                    user.destroySessionsForUserLocked(userId);
                    user.destroySessionsForUserLocked(userId);
@@ -654,7 +656,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            pushRemoteVolumeUpdateLocked(userId);
            pushRemoteVolumeUpdateLocked(userId);
            for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
            for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
                SessionsListenerRecord record = mSessionsListeners.get(i);
                SessionsListenerRecord record = mSessionsListeners.get(i);
                if (record.userId == USER_ALL || record.userId == userId) {
                if (record.userId == ALL.getIdentifier() || record.userId == userId) {
                    try {
                    try {
                        record.listener.onActiveSessionsChanged(tokens);
                        record.listener.onActiveSessionsChanged(tokens);
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
@@ -669,13 +671,13 @@ public class MediaSessionService extends SystemService implements Monitor {


    void pushSession2Changed(int userId) {
    void pushSession2Changed(int userId) {
        synchronized (mLock) {
        synchronized (mLock) {
            List<Session2Token> allSession2Tokens = getSession2TokensLocked(USER_ALL);
            List<Session2Token> allSession2Tokens = getSession2TokensLocked(ALL.getIdentifier());
            List<Session2Token> session2Tokens = getSession2TokensLocked(userId);
            List<Session2Token> session2Tokens = getSession2TokensLocked(userId);


            for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
            for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
                Session2TokensListenerRecord listenerRecord = mSession2TokensListenerRecords.get(i);
                Session2TokensListenerRecord listenerRecord = mSession2TokensListenerRecords.get(i);
                try {
                try {
                    if (listenerRecord.userId == USER_ALL) {
                    if (listenerRecord.userId == ALL.getIdentifier()) {
                        listenerRecord.listener.onSession2TokensChanged(allSession2Tokens);
                        listenerRecord.listener.onSession2TokensChanged(allSession2Tokens);
                    } else if (listenerRecord.userId == userId) {
                    } else if (listenerRecord.userId == userId) {
                        listenerRecord.listener.onSession2TokensChanged(session2Tokens);
                        listenerRecord.listener.onSession2TokensChanged(session2Tokens);
@@ -761,7 +763,8 @@ public class MediaSessionService extends SystemService implements Monitor {
    }
    }


    private MediaSessionRecord getMediaSessionRecordLocked(MediaSession.Token sessionToken) {
    private MediaSessionRecord getMediaSessionRecordLocked(MediaSession.Token sessionToken) {
        FullUserRecord user = getFullUserRecordLocked(UserHandle.getUserId(sessionToken.getUid()));
        FullUserRecord user = getFullUserRecordLocked(
                UserHandle.getUserHandleForUid(sessionToken.getUid()).getIdentifier());
        if (user != null) {
        if (user != null) {
            return user.mPriorityStack.getMediaSessionRecord(sessionToken);
            return user.mPriorityStack.getMediaSessionRecord(sessionToken);
        }
        }
@@ -1090,7 +1093,7 @@ public class MediaSessionService extends SystemService implements Monitor {


        private void observe() {
        private void observe() {
            mContentResolver.registerContentObserver(mSecureSettingsUri,
            mContentResolver.registerContentObserver(mSecureSettingsUri,
                    false, this, USER_ALL);
                    false, this, ALL.getIdentifier());
        }
        }


        @Override
        @Override
@@ -1436,7 +1439,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                final IOnMediaKeyEventDispatchedListener listener) {
                final IOnMediaKeyEventDispatchedListener listener) {
            final int pid = Binder.getCallingPid();
            final int pid = Binder.getCallingPid();
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                if (!hasMediaControlPermission(pid, uid)) {
                if (!hasMediaControlPermission(pid, uid)) {
@@ -1464,7 +1467,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                final IOnMediaKeyEventDispatchedListener listener) {
                final IOnMediaKeyEventDispatchedListener listener) {
            final int pid = Binder.getCallingPid();
            final int pid = Binder.getCallingPid();
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                if (!hasMediaControlPermission(pid, uid)) {
                if (!hasMediaControlPermission(pid, uid)) {
@@ -1492,7 +1495,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                final IOnMediaKeyEventSessionChangedListener listener) {
                final IOnMediaKeyEventSessionChangedListener listener) {
            final int pid = Binder.getCallingPid();
            final int pid = Binder.getCallingPid();
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                if (!hasMediaControlPermission(pid, uid)) {
                if (!hasMediaControlPermission(pid, uid)) {
@@ -1520,7 +1523,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                final IOnMediaKeyEventSessionChangedListener listener) {
                final IOnMediaKeyEventSessionChangedListener listener) {
            final int pid = Binder.getCallingPid();
            final int pid = Binder.getCallingPid();
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                if (!hasMediaControlPermission(pid, uid)) {
                if (!hasMediaControlPermission(pid, uid)) {
@@ -1558,7 +1561,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                }
                }


                synchronized (mLock) {
                synchronized (mLock) {
                    int userId = UserHandle.getUserId(uid);
                    int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
                    FullUserRecord user = getFullUserRecordLocked(userId);
                    FullUserRecord user = getFullUserRecordLocked(userId);
                    if (user == null || user.mFullUserId != userId) {
                    if (user == null || user.mFullUserId != userId) {
                        Log.w(TAG, "Only the full user can set the volume key long-press listener"
                        Log.w(TAG, "Only the full user can set the volume key long-press listener"
@@ -1617,7 +1620,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                }
                }


                synchronized (mLock) {
                synchronized (mLock) {
                    int userId = UserHandle.getUserId(uid);
                    int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
                    FullUserRecord user = getFullUserRecordLocked(userId);
                    FullUserRecord user = getFullUserRecordLocked(userId);
                    if (user == null || user.mFullUserId != userId) {
                    if (user == null || user.mFullUserId != userId) {
                        Log.w(TAG, "Only the full user can set the media key listener"
                        Log.w(TAG, "Only the full user can set the media key listener"
@@ -1925,7 +1928,7 @@ public class MediaSessionService extends SystemService implements Monitor {
        public boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid)
        public boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid)
                throws RemoteException {
                throws RemoteException {
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                // Don't perform sanity check between controllerPackageName and controllerUid.
                // Don't perform sanity check between controllerPackageName and controllerUid.
@@ -2004,7 +2007,7 @@ public class MediaSessionService extends SystemService implements Monitor {
        private boolean hasEnabledNotificationListener(int resolvedUserId, String packageName)
        private boolean hasEnabledNotificationListener(int resolvedUserId, String packageName)
                throws RemoteException {
                throws RemoteException {
            // You may not access another user's content as an enabled listener.
            // You may not access another user's content as an enabled listener.
            final int userId = UserHandle.getUserId(resolvedUserId);
            final int userId = UserHandle.getUserHandleForUid(resolvedUserId).getIdentifier();
            if (resolvedUserId != userId) {
            if (resolvedUserId != userId) {
                return false;
                return false;
            }
            }
@@ -2221,7 +2224,7 @@ public class MediaSessionService extends SystemService implements Monitor {


        private boolean isUserSetupComplete() {
        private boolean isUserSetupComplete() {
            return Settings.Secure.getIntForUser(mContext.getContentResolver(),
            return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
                    Settings.Secure.USER_SETUP_COMPLETE, 0, CURRENT.getIdentifier()) != 0;
        }
        }


        // we only handle public stream types, which are 0-5
        // we only handle public stream types, which are 0-5