diff options
author | Sudheer Shanka <sudheersai@google.com> | 2022-07-26 20:11:27 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-07-26 20:11:27 +0000 |
commit | 67eccb9aeb7084fafac3a2d0efc9abca9ad7ae39 (patch) | |
tree | 287e00e38ab937aff6753472060778b2019d6fb0 | |
parent | 99f9addc90ac669a363f2f10462d264287c25caa (diff) | |
parent | 9c7d593ccff5f74fb3ca4972e122309d967fb845 (diff) | |
download | base-android12L-dev.tar.gz |
Merge changes I2867a158,I98de12b5 into android12L-devandroid12L-dev
* changes:
Allow shell uid without checking the package name.
Allow apps receiving MediaSession callbacks to start FGS from BG.
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionRecord.java | 66 | ||||
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 21 |
2 files changed, 80 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java index 4822d6a62ac7..20b0c650cea8 100644 --- a/services/core/java/com/android/server/media/MediaSessionRecord.java +++ b/services/core/java/com/android/server/media/MediaSessionRecord.java @@ -1155,6 +1155,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void sendCommand(String packageName, int pid, int uid, String command, Bundle args, ResultReceiver cb) { try { + final String reason = TAG + ":" + command; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onCommand(packageName, pid, uid, command, args, cb); } catch (RemoteException e) { Log.e(TAG, "Remote failure in sendCommand.", e); @@ -1164,6 +1167,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void sendCustomAction(String packageName, int pid, int uid, String action, Bundle args) { try { + final String reason = TAG + ":custom-" + action; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onCustomAction(packageName, pid, uid, action, args); } catch (RemoteException e) { Log.e(TAG, "Remote failure in sendCustomAction.", e); @@ -1172,6 +1178,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void prepare(String packageName, int pid, int uid) { try { + final String reason = TAG + ":prepare"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPrepare(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in prepare.", e); @@ -1181,6 +1190,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void prepareFromMediaId(String packageName, int pid, int uid, String mediaId, Bundle extras) { try { + final String reason = TAG + ":prepareFromMediaId"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPrepareFromMediaId(packageName, pid, uid, mediaId, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in prepareFromMediaId.", e); @@ -1190,6 +1202,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void prepareFromSearch(String packageName, int pid, int uid, String query, Bundle extras) { try { + final String reason = TAG + ":prepareFromSearch"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPrepareFromSearch(packageName, pid, uid, query, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in prepareFromSearch.", e); @@ -1198,6 +1213,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void prepareFromUri(String packageName, int pid, int uid, Uri uri, Bundle extras) { try { + final String reason = TAG + ":prepareFromUri"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPrepareFromUri(packageName, pid, uid, uri, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in prepareFromUri.", e); @@ -1206,6 +1224,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void play(String packageName, int pid, int uid) { try { + final String reason = TAG + ":play"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPlay(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in play.", e); @@ -1215,6 +1236,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void playFromMediaId(String packageName, int pid, int uid, String mediaId, Bundle extras) { try { + final String reason = TAG + ":playFromMediaId"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPlayFromMediaId(packageName, pid, uid, mediaId, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in playFromMediaId.", e); @@ -1224,6 +1248,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void playFromSearch(String packageName, int pid, int uid, String query, Bundle extras) { try { + final String reason = TAG + ":playFromSearch"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPlayFromSearch(packageName, pid, uid, query, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in playFromSearch.", e); @@ -1232,6 +1259,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void playFromUri(String packageName, int pid, int uid, Uri uri, Bundle extras) { try { + final String reason = TAG + ":playFromUri"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPlayFromUri(packageName, pid, uid, uri, extras); } catch (RemoteException e) { Log.e(TAG, "Remote failure in playFromUri.", e); @@ -1240,6 +1270,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void skipToTrack(String packageName, int pid, int uid, long id) { try { + final String reason = TAG + ":skipToTrack"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onSkipToTrack(packageName, pid, uid, id); } catch (RemoteException e) { Log.e(TAG, "Remote failure in skipToTrack", e); @@ -1248,6 +1281,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void pause(String packageName, int pid, int uid) { try { + final String reason = TAG + ":pause"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPause(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in pause.", e); @@ -1256,6 +1292,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void stop(String packageName, int pid, int uid) { try { + final String reason = TAG + ":stop"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onStop(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in stop.", e); @@ -1264,6 +1303,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void next(String packageName, int pid, int uid) { try { + final String reason = TAG + ":next"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onNext(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in next.", e); @@ -1272,6 +1314,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void previous(String packageName, int pid, int uid) { try { + final String reason = TAG + ":previous"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onPrevious(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in previous.", e); @@ -1280,6 +1325,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void fastForward(String packageName, int pid, int uid) { try { + final String reason = TAG + ":fastForward"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onFastForward(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in fastForward.", e); @@ -1288,6 +1336,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void rewind(String packageName, int pid, int uid) { try { + final String reason = TAG + ":rewind"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onRewind(packageName, pid, uid); } catch (RemoteException e) { Log.e(TAG, "Remote failure in rewind.", e); @@ -1296,6 +1347,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void seekTo(String packageName, int pid, int uid, long pos) { try { + final String reason = TAG + ":seekTo"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onSeekTo(packageName, pid, uid, pos); } catch (RemoteException e) { Log.e(TAG, "Remote failure in seekTo.", e); @@ -1304,6 +1358,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void rate(String packageName, int pid, int uid, Rating rating) { try { + final String reason = TAG + ":rate"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onRate(packageName, pid, uid, rating); } catch (RemoteException e) { Log.e(TAG, "Remote failure in rate.", e); @@ -1312,6 +1369,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void setPlaybackSpeed(String packageName, int pid, int uid, float speed) { try { + final String reason = TAG + ":setPlaybackSpeed"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onSetPlaybackSpeed(packageName, pid, uid, speed); } catch (RemoteException e) { Log.e(TAG, "Remote failure in setPlaybackSpeed.", e); @@ -1321,6 +1381,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void adjustVolume(String packageName, int pid, int uid, boolean asSystemService, int direction) { try { + final String reason = TAG + ":adjustVolume"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); if (asSystemService) { mCb.onAdjustVolume(mContext.getPackageName(), Process.myPid(), Process.SYSTEM_UID, direction); @@ -1334,6 +1397,9 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR public void setVolumeTo(String packageName, int pid, int uid, int value) { try { + final String reason = TAG + ":setVolumeTo"; + mService.tempAllowlistTargetPkgIfPossible(getUid(), getPackageName(), + pid, uid, packageName, reason); mCb.onSetVolumeTo(packageName, pid, uid, value); } catch (RemoteException e) { Log.e(TAG, "Remote failure in setVolumeTo.", e); diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 29a5469367cd..65d9f995ae00 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -40,6 +40,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.pm.PackageManagerInternal; import android.media.AudioManager; import android.media.AudioPlaybackConfiguration; import android.media.AudioSystem; @@ -85,6 +86,7 @@ import android.view.ViewConfiguration; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.LocalManagerRegistry; +import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.Watchdog; import com.android.server.Watchdog.Monitor; @@ -538,14 +540,19 @@ public class MediaSessionService extends SystemService implements Monitor { if (TextUtils.isEmpty(packageName)) { throw new IllegalArgumentException("packageName may not be empty"); } - String[] packages = mContext.getPackageManager().getPackagesForUid(uid); - final int packageCount = packages.length; - for (int i = 0; i < packageCount; i++) { - if (packageName.equals(packages[i])) { - return; - } + if (uid == Process.ROOT_UID || uid == Process.SHELL_UID) { + // If the caller is shell, then trust the packageName given and allow it + // to proceed. + return; + } + final PackageManagerInternal packageManagerInternal = + LocalServices.getService(PackageManagerInternal.class); + final int actualUid = packageManagerInternal.getPackageUid( + packageName, 0 /* flags */, UserHandle.getUserId(uid)); + if (!UserHandle.isSameApp(uid, actualUid)) { + throw new IllegalArgumentException("packageName does not belong to the calling uid; " + + "pkg=" + packageName + ", uid=" + uid); } - throw new IllegalArgumentException("packageName is not owned by the calling process"); } void tempAllowlistTargetPkgIfPossible(int targetUid, String targetPackage, |