Assorted failsafes around PowerSaveModeReceiver

This commit is contained in:
Henrik Rydgard committed 2016-09-18 23:11:41 +02:00
1 parent 2337523fe9
commit 97b60a23a8
2 files changed
+32 -14

No files matched your search

@@ -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());
}
}
}
@@ -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;