diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 07237cd121..246814efd8 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -102,14 +102,6 @@ - - - - - - - - diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index ddae8db8c0..1ced155cf3 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -106,6 +106,8 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C private InputDeviceState inputPlayerC; private String inputPlayerADesc; + private PowerSaveModeReceiver mPowerSaveModeReceiver = null; + private static LocationHelper mLocationHelper; private static CameraHelper mCameraHelper; @@ -311,7 +313,6 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C javaGL = "true".equalsIgnoreCase(NativeApp.queryConfig("androidJavaGL")); sendInitialGrants(); - PowerSaveModeReceiver.initAndSend(this); // OK, config should be initialized, we can query for screen rotation. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { @@ -489,6 +490,10 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C initialized = true; } + if (mPowerSaveModeReceiver == null) { + mPowerSaveModeReceiver = new PowerSaveModeReceiver(this); + } + // OK, config should be initialized, we can query for screen rotation. updateScreenRotation("onCreate"); updateSustainedPerformanceMode(); @@ -703,7 +708,10 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C mSurfaceView.onDestroy(); mSurfaceView = null; } - PowerSaveModeReceiver.destroy(this); + if (mPowerSaveModeReceiver != null) { + mPowerSaveModeReceiver.destroy(this); + mPowerSaveModeReceiver = null; + } // 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(); @@ -771,7 +779,6 @@ 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 5ba40291ff..38649b873c 100644 --- a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java +++ b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java @@ -16,7 +16,6 @@ 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; @@ -27,25 +26,21 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { isBatteryLow = true; } else if (Intent.ACTION_BATTERY_OKAY.equals(action)) { isBatteryLow = false; + } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)) { + // sendPowerSaving() } sendPowerSaving(context); } - 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); - } - } - }; + public PowerSaveModeReceiver(final Activity activity) { IntentFilter filter = new IntentFilter(); - filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); - activity.registerReceiver(saveModeReceiver, filter); - - sendPowerSaving(activity); + filter.addAction(Intent.ACTION_BATTERY_LOW); + filter.addAction(Intent.ACTION_BATTERY_OKAY); + if (Build.VERSION.SDK_INT >= 21) { + filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); + } + activity.registerReceiver(this, filter); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { activity.getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, new ContentObserver(null) { @@ -65,13 +60,11 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { } }); } + sendPowerSaving(activity); } - public static void destroy(final Activity activity) { - if (saveModeReceiver != null) { - activity.unregisterReceiver(saveModeReceiver); - saveModeReceiver = null; - } + public void destroy(final Context context) { + context.unregisterReceiver(this); } @TargetApi(21) @@ -101,7 +94,7 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { return value != null && value.equals("1"); } - protected static void sendPowerSaving(final Context context) { + protected void sendPowerSaving(final Context context) { if (Build.VERSION.SDK_INT >= 21) { isPowerSaving = getNativePowerSaving(context); } else {