summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2016-04-08 12:56:59 -0700
committerRoman Birg <roman@cyngn.com>2016-04-15 21:37:53 +0000
commitad3dc3a1d00df809bfac4b288cd676cfb5b1724b (patch)
treed7956ef1b59234eb1a5a81b36ce4fc0d8cf2d607 /src
parent7f127de294b8b607080a73a9d1a22b6768992fb0 (diff)
downloadandroid_packages_apps_AudioFX-ad3dc3a1d00df809bfac4b288cd676cfb5b1724b.tar.gz
android_packages_apps_AudioFX-ad3dc3a1d00df809bfac4b288cd676cfb5b1724b.tar.bz2
android_packages_apps_AudioFX-ad3dc3a1d00df809bfac4b288cd676cfb5b1724b.zip
AudioFX: don't assume stream type
We always assume new sessions are always content type of MUSIC. Actually parse the incoming intent and set the value correctly so we don't apply effects unnecessarily as we only want to support Music for now. Change-Id: I260e3c07ef44ceeaa0d2950f1091b9f4f213f115 Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/cyngn/audiofx/service/AudioFxService.java56
-rw-r--r--src/com/cyngn/audiofx/service/DevicePreferenceManager.java2
-rw-r--r--src/com/cyngn/audiofx/service/SessionManager.java14
3 files changed, 37 insertions, 35 deletions
diff --git a/src/com/cyngn/audiofx/service/AudioFxService.java b/src/com/cyngn/audiofx/service/AudioFxService.java
index 414a642..d5fae5c 100644
--- a/src/com/cyngn/audiofx/service/AudioFxService.java
+++ b/src/com/cyngn/audiofx/service/AudioFxService.java
@@ -53,7 +53,7 @@ import cyanogenmod.app.CustomTile;
*/
public class AudioFxService extends Service {
- private static final String TAG = AudioFxService.class.getSimpleName();
+ static final String TAG = AudioFxService.class.getSimpleName();
public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -118,27 +118,6 @@ public class AudioFxService extends Service {
}
}
- public AudioDeviceInfo getCurrentDevice() {
- if (checkService()) {
- return mService.get().mSessionManager.getCurrentDevice();
- }
- return null;
- }
-
- public AudioDeviceInfo getPreviousDevice() {
- if (checkService()) {
- return mService.get().mSessionManager.getPreviousDevice();
- }
- return null;
- }
-
- public AudioDeviceInfo getDeviceById(int id) {
- if (checkService()) {
- return mService.get().mSessionManager.getDeviceById(id);
- }
- return null;
- }
-
public EffectSet getEffect(Integer id) {
if (checkService()) {
return mService.get().mSessionManager.getEffectForSession(id);
@@ -161,6 +140,7 @@ public class AudioFxService extends Service {
mPreferenceManager = new DevicePreferenceManager(getApplicationContext(), mSessionManager);
if (!mPreferenceManager.initDefaults()) {
stopSelf();
+ return;
}
updateQsTile();
@@ -179,18 +159,20 @@ public class AudioFxService extends Service {
String action = intent.getAction();
int sessionId = intent.getIntExtra(AudioEffect.EXTRA_AUDIO_SESSION, 0);
String pkg = intent.getStringExtra(AudioEffect.EXTRA_PACKAGE_NAME);
- String contentType = intent.getStringExtra(AudioEffect.EXTRA_CONTENT_TYPE);
+ int stream = mapContentTypeToStream(
+ intent.getIntExtra(AudioEffect.EXTRA_CONTENT_TYPE,
+ AudioEffect.CONTENT_TYPE_MUSIC));
if (action.equals(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION)) {
if (DEBUG) {
- Log.i(TAG, String.format("New audio session: %d package: %s contentType=%s",
- sessionId, pkg, contentType));
+ Log.i(TAG, String.format("New audio session: %d package: %s contentType=%d",
+ sessionId, pkg, stream));
}
- mSessionManager.onSessionAdded(AudioManager.STREAM_MUSIC, sessionId, -1, -1, -1);
+ mSessionManager.onSessionAdded(stream, sessionId, -1, -1, -1);
} else if (action.equals(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION)) {
- mSessionManager.onSessionRemoved(AudioManager.STREAM_MUSIC, sessionId);
+ mSessionManager.onSessionRemoved(stream, sessionId);
}
}
@@ -198,6 +180,23 @@ public class AudioFxService extends Service {
return START_STICKY;
}
+ /**
+ * maps {@link AudioEffect#EXTRA_CONTENT_TYPE} to an AudioManager.STREAM_* item
+ */
+ private static int mapContentTypeToStream(int contentType) {
+ switch (contentType) {
+ case AudioEffect.CONTENT_TYPE_VOICE:
+ return AudioManager.STREAM_VOICE_CALL;
+ case AudioEffect.CONTENT_TYPE_GAME:
+ // explicitly don't support game effects right now
+ return -1;
+ case AudioEffect.CONTENT_TYPE_MOVIE:
+ case AudioEffect.CONTENT_TYPE_MUSIC:
+ default:
+ return AudioManager.STREAM_MUSIC;
+ }
+ }
+
private void updateQsTile() {
if (mTileBuilder == null) {
mTileBuilder = new CustomTile.Builder(this);
@@ -218,7 +217,8 @@ public class AudioFxService extends Service {
mTileBuilder
.hasSensitiveData(false)
- .setIcon(mPreferenceManager.isGlobalEnabled() ? R.drawable.ic_qs_visualizer_on : R.drawable.ic_qs_visualizer_off)
+ .setIcon(mPreferenceManager.isGlobalEnabled() ? R.drawable.ic_qs_visualizer_on
+ : R.drawable.ic_qs_visualizer_off)
.setLabel(label)
.setContentDescription(R.string.qs_tile_content_description)
.shouldCollapsePanel(false)
diff --git a/src/com/cyngn/audiofx/service/DevicePreferenceManager.java b/src/com/cyngn/audiofx/service/DevicePreferenceManager.java
index e80f28a..d774bee 100644
--- a/src/com/cyngn/audiofx/service/DevicePreferenceManager.java
+++ b/src/com/cyngn/audiofx/service/DevicePreferenceManager.java
@@ -42,7 +42,7 @@ import java.util.Locale;
class DevicePreferenceManager {
- private static final String TAG = "AudioFxService";
+ private static final String TAG = AudioFxService.TAG;
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private final Context mContext;
diff --git a/src/com/cyngn/audiofx/service/SessionManager.java b/src/com/cyngn/audiofx/service/SessionManager.java
index acbdca8..188932b 100644
--- a/src/com/cyngn/audiofx/service/SessionManager.java
+++ b/src/com/cyngn/audiofx/service/SessionManager.java
@@ -42,7 +42,7 @@ import com.cyngn.audiofx.eq.EqUtils;
class SessionManager extends AudioOutputChangeListener implements AudioSystem.EffectSessionCallback {
- private static final String TAG = "AudioFxService";
+ private static final String TAG = AudioFxService.TAG;
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private final Context mContext;
@@ -116,11 +116,13 @@ class SessionManager extends AudioOutputChangeListener implements AudioSystem.Ef
*/
@Override
public void onSessionAdded(int stream, int sessionId, int flags, int channelMask, int uid) {
- if (stream == AudioManager.STREAM_MUSIC &&
- ((flags < 0) || (flags & AudioFxService.AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) > 0 ||
- (flags & AudioFxService.AUDIO_OUTPUT_FLAG_DEEP_BUFFER) > 0) &&
- (channelMask < 0 || channelMask > 1) &&
- !mHandler.hasMessages(MSG_ADD_SESSION, sessionId)) {
+ final boolean music = stream == AudioManager.STREAM_MUSIC;
+ final boolean offloaded = (flags < 0)
+ || (flags & AudioFxService.AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) > 0
+ || (flags & AudioFxService.AUDIO_OUTPUT_FLAG_DEEP_BUFFER) > 0;
+ final boolean stereo = channelMask < 0 || channelMask > 1;
+
+ if (music && offloaded && stereo && !mHandler.hasMessages(MSG_ADD_SESSION, sessionId)) {
if (DEBUG) Log.i(TAG, String.format("New audio session: %d [flags=%d channelMask=%d uid=%d]",
sessionId, flags, channelMask, uid));
mHandler.obtainMessage(MSG_ADD_SESSION, sessionId).sendToTarget();