Volume prototypes: Allow delegate volume UI to set remote controller.
Allow the blessed component (stored in secure settings) to replace the remote volume controller (for media sessions) in addition to the volume controller - needed in order to properly support cast etc. Bug: 19260237 Change-Id: I7ecc79cb4249744e8d4ffedcab737a35331e220f
This commit is contained in:
@@ -31,6 +31,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioManagerInternal;
|
||||
import android.media.AudioSystem;
|
||||
import android.media.IAudioService;
|
||||
import android.media.IRemoteVolumeController;
|
||||
@@ -59,6 +60,7 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.SystemService;
|
||||
import com.android.server.Watchdog;
|
||||
import com.android.server.Watchdog.Monitor;
|
||||
@@ -94,6 +96,7 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
private KeyguardManager mKeyguardManager;
|
||||
private IAudioService mAudioService;
|
||||
private AudioManager mAudioManager;
|
||||
private AudioManagerInternal mAudioManagerInternal;
|
||||
private ContentResolver mContentResolver;
|
||||
private SettingsObserver mSettingsObserver;
|
||||
|
||||
@@ -121,6 +124,7 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
(KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
|
||||
mAudioService = getAudioService();
|
||||
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
|
||||
mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
|
||||
mContentResolver = getContext().getContentResolver();
|
||||
mSettingsObserver = new SettingsObserver();
|
||||
mSettingsObserver.observe();
|
||||
@@ -343,7 +347,13 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void enforceStatusBarPermission(String action, int pid, int uid) {
|
||||
private void enforceSystemUiPermission(String action, int pid, int uid) {
|
||||
if (mAudioManagerInternal != null) {
|
||||
final int vcuid = mAudioManagerInternal.getVolumeControllerUid();
|
||||
if (vcuid > 0 && uid == vcuid) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (getContext().checkPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
|
||||
pid, uid) != PackageManager.PERMISSION_GRANTED) {
|
||||
throw new SecurityException("Only system ui may " + action);
|
||||
@@ -789,7 +799,7 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
final int uid = Binder.getCallingUid();
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
enforceStatusBarPermission("listen for volume changes", pid, uid);
|
||||
enforceSystemUiPermission("listen for volume changes", pid, uid);
|
||||
mRvc = rvc;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
|
||||
Reference in New Issue
Block a user