Skip to content

Commit

Permalink
DO NOT MERGE Check caller for sending media key to telephony service
Browse files Browse the repository at this point in the history
Prevent sending media key events from the non-system app to the
telephony service through the AudioManager.dispatchMediaKeyEvent()
or sending media key broadcast directly.

Bug: 29833954
Tested: Installed malicious apps and confirmed that they don't work.
Tested: Run CtsTelecomTestCases and CtsMediaTestCases
Change-Id: I2a9e78196ba7455324e485f098f095d03b47ee15
(cherry picked from commit d1641e8)
  • Loading branch information
jaewan-github authored and andi34 committed Nov 20, 2016
1 parent 50e6269 commit 7c3f662
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion media/java/android/media/MediaFocusControl.java
Expand Up @@ -40,6 +40,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.IBinder.DeathRecipient;
Expand Down Expand Up @@ -750,7 +751,13 @@ private void filterMediaKeyEvent(KeyEvent keyEvent, boolean needWakeLock) {
synchronized(mRCStack) {
if ((mMediaReceiverForCalls != null) &&
(mIsRinging || (mAudioService.getMode() == AudioSystem.MODE_IN_CALL))) {
dispatchMediaKeyEventForCalls(keyEvent, needWakeLock);
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
// Prevent dispatching key event to the global priority session.
Slog.i(TAG, "Only the system can dispatch media key event "
+ "to the global priority session.");
} else {
dispatchMediaKeyEventForCalls(keyEvent, needWakeLock);
}
return;
}
}
Expand Down
Expand Up @@ -4044,6 +4044,18 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean i
case KeyEvent.KEYCODE_MEDIA_RECORD:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
ITelephony telephonyService = getTelephonyService();
if (telephonyService != null) {
try {
if (!telephonyService.isIdle()) {
// When phone is ringing or in-call, pass all media keys to it.
result &= ~ACTION_PASS_TO_USER;
}
} catch (RemoteException ex) {
Log.w(TAG, "ITelephony threw RemoteException", ex);
}
}

if ((result & ACTION_PASS_TO_USER) == 0) {
// Only do this if we would otherwise not pass it to the user. In that
// case, the PhoneWindow class will do the same thing, except it will
Expand Down

0 comments on commit 7c3f662

Please sign in to comment.