From 81a77949fcdc58617423e69f70d74384356873cc Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 27 Nov 2014 10:52:19 -0500 Subject: [PATCH 1/2] CB-6153 Add a preference for controlling hardware button audio stream (DefaultVolumeStream) This, along with the commit to the audio plugin, makes it so that by default apps control the ringer volume, but when any audio players are active, the media volume is controlled. --- framework/src/org/apache/cordova/CordovaActivity.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 3c12a97a..816b12b9 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -20,6 +20,7 @@ package org.apache.cordova; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -346,9 +347,11 @@ public class CordovaActivity extends Activity implements CordovaInterface { } createViews(); - // TODO: Make this a preference (CB-6153) - // Setup the hardware volume controls to handle volume control - setVolumeControlStream(AudioManager.STREAM_MUSIC); + // Wire the hardware volume controls to control media if desired. + String volumePref = preferences.getString("DefaultVolumeStream", ""); + if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) { + setVolumeControlStream(AudioManager.STREAM_MUSIC); + } } /** From 132650df28a22e61fe6db1206546acd6ddf16988 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Wed, 3 Dec 2014 10:04:54 -0500 Subject: [PATCH 2/2] CB-8112 Turn off mediaPlaybackRequiresUserGesture --- .../src/org/apache/cordova/CordovaWebView.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 4d01f586..62a641b5 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -215,8 +215,12 @@ public class CordovaWebView extends WebView { // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { Level16Apis.enableUniversalAccess(settings); + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + Level17Apis.setMediaPlaybackRequiresUserGesture(settings, false); + } // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); @@ -831,12 +835,19 @@ public class CordovaWebView extends WebView { // Wrapping these functions in their own class prevents warnings in adb like: // VFY: unable to resolve virtual method 285: Landroid/webkit/WebSettings;.setAllowUniversalAccessFromFileURLs @TargetApi(16) - private static class Level16Apis { + private static final class Level16Apis { static void enableUniversalAccess(WebSettings settings) { settings.setAllowUniversalAccessFromFileURLs(true); } } - + + @TargetApi(17) + private static final class Level17Apis { + static void setMediaPlaybackRequiresUserGesture(WebSettings settings, boolean value) { + settings.setMediaPlaybackRequiresUserGesture(value); + } + } + public void printBackForwardList() { WebBackForwardList currentList = this.copyBackForwardList(); int currentSize = currentList.getSize();