Gallery: AudioSystem wrapper

CRs-Fixed: 986672
Change-Id: I6cb69643162a089b3565666523291563860e6170
diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
index 434771b..2802d07 100644
--- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
+++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
@@ -352,4 +352,29 @@
             return obj == null ? null : new Metadata(obj);
         }
     }
+
+    public static class AudioSystem {
+        public static final int FORCE_NONE = 0;
+        public static final int FORCE_SPEAKER = 1;
+
+        public static final int FOR_MEDIA = 1;
+
+        private static final Method setForceUseMethod;
+        private static final Method getForceUseMethod;
+
+        static {
+            Class<?> klass = getClassForName("android.media.AudioSystem");
+            setForceUseMethod = getMethod(klass, "setForceUse", int.class, int.class);
+            getForceUseMethod = getMethod(klass, "getForceUse", int.class);
+        }
+
+        public static void setForceUse(int usage, int config) {
+            invoke(setForceUseMethod, null, usage, config);
+        }
+
+        public static int getForceUse(int usage) {
+            Object obj = invoke(getForceUseMethod, null, usage);
+            return obj == null ? FORCE_NONE : (Integer) obj;
+        }
+    }
 }
diff --git a/src/org/codeaurora/gallery3d/video/SpeakerHooker.java b/src/org/codeaurora/gallery3d/video/SpeakerHooker.java
index 4825436..e21452f 100644
--- a/src/org/codeaurora/gallery3d/video/SpeakerHooker.java
+++ b/src/org/codeaurora/gallery3d/video/SpeakerHooker.java
@@ -28,10 +28,6 @@
 */
 package org.codeaurora.gallery3d.video;
 
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.Toast;
-
 import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.content.BroadcastReceiver;
@@ -39,10 +35,13 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.media.AudioManager;
-import android.media.AudioSystem;
 import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.Toast;
 
 import org.codeaurora.gallery.R;
+import com.android.gallery3d.common.ApiHelper.AudioSystem;
 
 public class SpeakerHooker extends MovieHooker {
 
@@ -197,9 +196,8 @@
     }
 
     private boolean isSpeakerOn() {
-        boolean isSpeakerOn = (AudioSystem.FORCE_SPEAKER
-                == AudioSystem.getForceUse(AudioSystem.FOR_MEDIA)) ? true : false;
-        return isSpeakerOn;
+        return (AudioSystem.FORCE_SPEAKER
+                == AudioSystem.getForceUse(AudioSystem.FOR_MEDIA));
     }
 
 }