summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2016-03-10 10:25:35 -0800
committerRoman Birg <roman@cyngn.com>2016-03-10 11:08:14 -0800
commitfc7cdbe50467ed3facd6c7125e2c7e4d34bf164d (patch)
tree38ab9485807d474be2bc6ef9a1e6408086854c85 /src
parenta1f3bb1f98338a4591964891fe96753de7009fc1 (diff)
downloadandroid_packages_apps_AudioFX-fc7cdbe50467ed3facd6c7125e2c7e4d34bf164d.tar.gz
android_packages_apps_AudioFX-fc7cdbe50467ed3facd6c7125e2c7e4d34bf164d.tar.bz2
android_packages_apps_AudioFX-fc7cdbe50467ed3facd6c7125e2c7e4d34bf164d.zip
AudioFX: fix not setting up proper defaults on fresh boot
The service will setup its own defaults as needed. If there is a necessary udpate to prefs, the pref change increment logic will handle that and we don't explicitly need to call to reapply defaults on every boot. The service will do it in every onCreate() AS NECESSRY! This logic was also leftover from before there was a preference version code. Ref: AUDIO-145, OPO-512 Change-Id: I950bed1fbb6289cd2bcc53bac8ee0c268e225774 Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/cyngn/audiofx/service/AudioFxService.java45
-rw-r--r--src/com/cyngn/audiofx/service/BootReceiver.java13
2 files changed, 20 insertions, 38 deletions
diff --git a/src/com/cyngn/audiofx/service/AudioFxService.java b/src/com/cyngn/audiofx/service/AudioFxService.java
index df540cb..c202d57 100644
--- a/src/com/cyngn/audiofx/service/AudioFxService.java
+++ b/src/com/cyngn/audiofx/service/AudioFxService.java
@@ -100,9 +100,6 @@ public class AudioFxService extends Service {
public static final String ACTION_DEVICE_OUTPUT_CHANGED
= "org.cyanogenmod.audiofx.ACTION_DEVICE_OUTPUT_CHANGED";
- public static final String ACTION_REAPPLY_DEFAULTS
- = "com.cyngn.audiofx.action.REAPPLY_DEFAULTS";
-
public static final String ACTION_UPDATE_TILE = "com.cyngn.audiofx.action.UPDATE_TILE";
public static final String EXTRA_DEVICE = "device";
@@ -167,12 +164,6 @@ public class AudioFxService extends Service {
}
}
- public void applyDefaults() {
- if (checkService()) {
- mService.get().forceDefaults();
- }
- }
-
public void setOverrideLevels(short band, float level) {
if (checkService()) {
mService.get().setOverrideLevels(band, level);
@@ -416,9 +407,6 @@ public class AudioFxService extends Service {
mDeviceListener.register();
- mSessionCallback = new FxSessionCallback();
- AudioSystem.setEffectSessionCallback(mSessionCallback);
-
try {
saveAndApplyDefaults(false);
} catch (Exception e) {
@@ -428,15 +416,16 @@ public class AudioFxService extends Service {
stopSelf();
}
+ mSessionCallback = new FxSessionCallback();
+ AudioSystem.setEffectSessionCallback(mSessionCallback);
+
updateQsTile();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null && intent.getAction() != null) {
- if (ACTION_REAPPLY_DEFAULTS.equals(intent.getAction())) {
- saveAndApplyDefaults(false);
- } else if (ACTION_UPDATE_TILE.equals(intent.getAction())) {
+ if (ACTION_UPDATE_TILE.equals(intent.getAction())) {
updateQsTile();
} else {
String action = intent.getAction();
@@ -661,24 +650,22 @@ public class AudioFxService extends Service {
}
}
- private void forceDefaults() {
- SharedPreferences prefs = getSharedPreferences(Constants.AUDIOFX_GLOBAL_FILE, 0);
- prefs.edit().putBoolean(SAVED_DEFAULTS, false).apply();
- saveAndApplyDefaults(true);
- }
-
/**
* This method sets some sane defaults for presets, device defaults, etc
* <p/>
* First we read presets from the system, then adjusts some setting values
* for some better defaults!
*/
- private synchronized void saveAndApplyDefaults(boolean overridePrevious) {
+ private void saveAndApplyDefaults(boolean overridePrevious) {
+ if (DEBUG) {
+ Log.d(TAG, "saveAndApplyDefaults() called with overridePrevious = " +
+ "[" + overridePrevious + "]");
+ }
SharedPreferences prefs = Constants.getGlobalPrefs(this);
final int currentPrefVer = prefs.getInt(Constants.AUDIOFX_GLOBAL_PREFS_VERSION_INT, 0);
- boolean needsPrefsUpdate = currentPrefVer
- < Constants.CURRENT_PREFS_INT_VERSION;
+ boolean needsPrefsUpdate = currentPrefVer < Constants.CURRENT_PREFS_INT_VERSION
+ || overridePrevious;
if (needsPrefsUpdate) {
Log.d(TAG, "rebuilding presets due to preference upgrade from " + currentPrefVer
@@ -686,6 +673,9 @@ public class AudioFxService extends Service {
}
if (prefs.getBoolean(SAVED_DEFAULTS, false) && !needsPrefsUpdate) {
+ if (DEBUG) {
+ Log.e(TAG, "we've already saved defaults and don't need a pref update. aborting.");
+ }
return;
}
EffectSet temp = EffectsFactory.createEffectSet(getApplicationContext(), 0);
@@ -741,10 +731,10 @@ public class AudioFxService extends Service {
editor.putBoolean(AUDIOFX_GLOBAL_HAS_BASSBOOST, temp.hasBassBoost());
editor.putBoolean(AUDIOFX_GLOBAL_HAS_MAXXAUDIO, temp.getBrand() == EffectsFactory.MAXXAUDIO);
editor.putBoolean(AUDIOFX_GLOBAL_HAS_DTS, temp.getBrand() == EffectsFactory.DTS);
- temp.release();
editor.commit();
+ temp.release();
- applyDefaults(overridePrevious || needsPrefsUpdate);
+ applyDefaults(needsPrefsUpdate);
prefs
.edit()
@@ -760,6 +750,9 @@ public class AudioFxService extends Service {
* Prereq: saveDefaults() must have been run before this can apply its defaults properly.
*/
private void applyDefaults(boolean overridePrevious) {
+ if (DEBUG) {
+ Log.d(TAG, "applyDefaults() called with overridePrevious = [" + overridePrevious + "]");
+ }
final SharedPreferences globalPrefs = getSharedPreferences(AUDIOFX_GLOBAL_FILE, 0);
if (globalPrefs.getBoolean(AUDIOFX_GLOBAL_HAS_MAXXAUDIO, false)) {
// Maxx Audio defaults:
diff --git a/src/com/cyngn/audiofx/service/BootReceiver.java b/src/com/cyngn/audiofx/service/BootReceiver.java
index 4f99f05..df853a5 100644
--- a/src/com/cyngn/audiofx/service/BootReceiver.java
+++ b/src/com/cyngn/audiofx/service/BootReceiver.java
@@ -8,18 +8,7 @@ import com.cyngn.audiofx.Constants;
public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
- final Intent service = new Intent(context, AudioFxService.class);
-
- SharedPreferences prefs = context.getSharedPreferences(Constants.AUDIOFX_GLOBAL_FILE, 0);
-
- if (prefs.contains(Constants.SAVED_DEFAULTS)) {
- // only reset if we've already set this before - a reboot.
- // we don't want to run apply defaults on the first boot, since the service
- // will do the same thing the first time.
- prefs.edit().putBoolean(Constants.SAVED_DEFAULTS, false).commit();
-
- service.setAction(AudioFxService.ACTION_REAPPLY_DEFAULTS);
- }
+ final Intent service = new Intent(context.getApplicationContext(), AudioFxService.class);
context.startService(service);
}
}