Pipe volume keys to adjustVolume instead of sendMediaKeyEvent

We were calling sendMediaKeyEvent with a KEYCODE_VOLUME key, which was being
ignored because it's not a media key. This redirects the volume keys to use
the adjustVolume methods instead. It also sends the appropriate flags to
make the lock screen consistent with the home screen and the volume keys
only affect active playback when the screen is off.

bug:15900519
Change-Id: I9f3853a2385869353a58debae6e6ca9933ba06ce
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 5a16e4d..310f3e9 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -27,6 +27,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.media.AudioManager;
 import android.media.IAudioService;
 import android.media.IRemoteVolumeController;
 import android.media.routeprovider.RouteRequest;
@@ -948,6 +949,12 @@
 
             }
             if (session == null) {
+                if ((flags & AudioManager.FLAG_ACTIVE_MEDIA_ONLY) != 0) {
+                    if (DEBUG) {
+                        Log.d(TAG, "No active session to adjust, skipping media only volume event");
+                        return;
+                    }
+                }
                 try {
                     if (delta == 0) {
                         mAudioService.adjustSuggestedStreamVolume(delta, suggestedStream, flags,