diff --git a/android/jni/native-audio-so.cpp b/android/jni/native-audio-so.cpp index 607142f022..27729ab2cd 100644 --- a/android/jni/native-audio-so.cpp +++ b/android/jni/native-audio-so.cpp @@ -157,7 +157,6 @@ OpenSLContext::~OpenSLContext() { bqPlayerObject = nullptr; bqPlayerPlay = nullptr; bqPlayerBufferQueue = nullptr; - bqPlayerMuteSolo = nullptr; bqPlayerVolume = nullptr; } diff --git a/android/jni/native-audio-so.h b/android/jni/native-audio-so.h index a69f879855..286a3338eb 100644 --- a/android/jni/native-audio-so.h +++ b/android/jni/native-audio-so.h @@ -35,7 +35,6 @@ private: SLObjectItf bqPlayerObject = nullptr; SLPlayItf bqPlayerPlay = nullptr; SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue = nullptr; - SLMuteSoloItf bqPlayerMuteSolo = nullptr; SLVolumeItf bqPlayerVolume = nullptr; // Double buffering. diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 3bec1191cf..ddae8db8c0 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -703,6 +703,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C mSurfaceView.onDestroy(); mSurfaceView = null; } + PowerSaveModeReceiver.destroy(this); // TODO: Can we ensure that the GL thread has stopped rendering here? // I've seen crashes that seem to indicate that sometimes it hasn't... NativeApp.audioShutdown(); @@ -770,6 +771,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C mSurfaceView.onResume(); } } + PowerSaveModeReceiver.sendPowerSaving(this); gainAudioFocus(this.audioManager, this.audioFocusChangeListener); NativeApp.resume(); diff --git a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java index 69b396dfa8..5ba40291ff 100644 --- a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java +++ b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java @@ -5,25 +5,27 @@ import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.database.ContentObserver; import android.net.Uri; import android.os.Build; import android.os.PowerManager; import android.provider.Settings; +import android.text.TextUtils; import android.util.Log; public class PowerSaveModeReceiver extends BroadcastReceiver { + private static final String TAG = PowerSaveModeReceiver.class.getSimpleName(); + private static BroadcastReceiver saveModeReceiver = null; private static boolean isPowerSaving = false; private static boolean isBatteryLow = false; - private static final String TAG = "PowerSaveModeReceiver"; - @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); - if (action.equals(Intent.ACTION_BATTERY_LOW)) { + if (Intent.ACTION_BATTERY_LOW.equals(action)) { isBatteryLow = true; - } else if (action.equals(Intent.ACTION_BATTERY_OKAY)) { + } else if (Intent.ACTION_BATTERY_OKAY.equals(action)) { isBatteryLow = false; } @@ -31,6 +33,18 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { } public static void initAndSend(final Activity activity) { + saveModeReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(intent.getAction())) { + sendPowerSaving(context); + } + } + }; + IntentFilter filter = new IntentFilter(); + filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); + activity.registerReceiver(saveModeReceiver, filter); + sendPowerSaving(activity); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { @@ -46,13 +60,20 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { } key = key.substring(key.lastIndexOf("/") + 1, key.length()); if (key.equals("user_powersaver_enable") || key.equals("psm_switch") || key.equals("powersaving_switch")) { - PowerSaveModeReceiver.sendPowerSaving(activity); + sendPowerSaving(activity); } } }); } } + public static void destroy(final Activity activity) { + if (saveModeReceiver != null) { + activity.unregisterReceiver(saveModeReceiver); + saveModeReceiver = null; + } + } + @TargetApi(21) private static boolean getNativePowerSaving(final Context context) { final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); @@ -67,7 +88,7 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { } // Samsung (Touchwiz) String s5Value = Settings.System.getString(context.getContentResolver(), "powersaving_switch"); - boolean hasS5Value = s5Value != null && !s5Value.equals(""); + boolean hasS5Value = !TextUtils.isEmpty(s5Value); // On newer devices, psm_switch is always set, and powersaving_switch is used instead. if ((!hasS5Value && getBooleanSetting(context, "psm_switch")) || getBooleanSetting(context, "powersaving_switch")) { return true; @@ -80,7 +101,7 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { return value != null && value.equals("1"); } - private static void sendPowerSaving(final Context context) { + protected static void sendPowerSaving(final Context context) { if (Build.VERSION.SDK_INT >= 21) { isPowerSaving = getNativePowerSaving(context); } else {