diff --git a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java index 1a016910d0..25681076f7 100644 --- a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java +++ b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java @@ -10,11 +10,14 @@ import android.net.Uri; import android.os.Build; import android.os.PowerManager; import android.provider.Settings; +import android.util.Log; public class PowerSaveModeReceiver extends BroadcastReceiver { 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(); @@ -30,18 +33,21 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { public static void initAndSend(final Activity activity) { sendPowerSaving(activity); - activity.getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, new ContentObserver(null) { - @Override - public void onChange(boolean selfChange, Uri uri) { - super.onChange(selfChange, uri); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + activity.getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, new ContentObserver(null) { + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @Override + public void onChange(boolean selfChange, Uri uri) { + super.onChange(selfChange, uri); - String key = uri.getPath(); - key = key.substring(key.lastIndexOf("/") + 1, key.length()); - if (key != null && (key.equals("user_powersaver_enable") || key.equals("psm_switch"))) { - PowerSaveModeReceiver.sendPowerSaving(activity); + String key = uri.getPath(); + key = key.substring(key.lastIndexOf("/") + 1, key.length()); + if (key != null && (key.equals("user_powersaver_enable") || key.equals("psm_switch"))) { + PowerSaveModeReceiver.sendPowerSaving(activity); + } } - } - }); + }); + } } @TargetApi(21) @@ -72,10 +78,19 @@ public class PowerSaveModeReceiver extends BroadcastReceiver { isPowerSaving = getExtraPowerSaving(context); } - if (isBatteryLow || isPowerSaving) { - NativeApp.sendMessage("core_powerSaving", "true"); - } else { - NativeApp.sendMessage("core_powerSaving", "false"); + if (!PpssppActivity.libraryLoaded) { + Log.e(TAG, "Cannot send power saving: Library not loaded"); + return; + } + + try { + if (isBatteryLow || isPowerSaving) { + NativeApp.sendMessage("core_powerSaving", "true"); + } else { + NativeApp.sendMessage("core_powerSaving", "false"); + } + } catch (Exception e) { + Log.e(TAG, "Exception in sendPowerSaving: " + e.toString()); } } } diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index 35b2851f67..16d66d36bb 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -16,6 +16,8 @@ public class PpssppActivity extends NativeActivity { private static boolean m_hasUnsupportedABI = false; private static boolean m_hasNoNativeBinary = false; + public static boolean libraryLoaded = false; + @SuppressWarnings("deprecation") public static void CheckABIAndLoadLibrary() { if (Build.CPU_ABI.equals("armeabi")) { @@ -23,6 +25,7 @@ public class PpssppActivity extends NativeActivity { } else { try { System.loadLibrary("ppsspp_jni"); + libraryLoaded = true; } catch (UnsatisfiedLinkError e) { Log.e(TAG, "LoadLibrary failed, UnsatifiedLinkError: " + e.toString()); m_hasNoNativeBinary = true;