mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Android: Detect pre-L power saving.
Sometimes users don't realize these are on, and they can slow down gameplay. Of course, they can also save battery.
This commit is contained in:
parent
1f7a137926
commit
f366f09c4c
2 changed files with 55 additions and 27 deletions
|
@ -125,16 +125,6 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
private void sendPowerSaving() {
|
||||
final PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
|
||||
if (pm.isPowerSaveMode()) {
|
||||
NativeApp.sendMessage("core_powerSaving", "true");
|
||||
} else {
|
||||
NativeApp.sendMessage("core_powerSaving", "false");
|
||||
}
|
||||
}
|
||||
|
||||
String getApplicationLibraryDir(ApplicationInfo application) {
|
||||
String libdir = null;
|
||||
try {
|
||||
|
@ -283,9 +273,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
|
|||
javaGL = "true".equalsIgnoreCase(NativeApp.queryConfig("androidJavaGL"));
|
||||
|
||||
sendInitialGrants();
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
sendPowerSaving();
|
||||
}
|
||||
PowerSaveModeReceiver.initAndSend(this);
|
||||
|
||||
// OK, config should be initialized, we can query for screen rotation.
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
package org.ppsspp.ppsspp;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
public class PowerSaveModeReceiver extends BroadcastReceiver {
|
||||
private boolean isPowerSaving = false;
|
||||
private boolean isBatteryLow = false;
|
||||
private static boolean isPowerSaving = false;
|
||||
private static boolean isBatteryLow = false;
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
isPowerSaving = getPowerSaving(context);
|
||||
} else {
|
||||
isPowerSaving = false;
|
||||
}
|
||||
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(Intent.ACTION_BATTERY_LOW)) {
|
||||
isBatteryLow = true;
|
||||
|
@ -26,16 +24,58 @@ public class PowerSaveModeReceiver extends BroadcastReceiver {
|
|||
isBatteryLow = false;
|
||||
}
|
||||
|
||||
sendPowerSaving(context);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
private static boolean getNativePowerSaving(final Context context) {
|
||||
final PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isPowerSaveMode();
|
||||
}
|
||||
|
||||
private static boolean getExtraPowerSaving(final Context context) {
|
||||
// http://stackoverflow.com/questions/25065635/checking-for-power-saver-mode-programically
|
||||
// HTC (Sense)
|
||||
String htcValue = Settings.System.getString(context.getContentResolver(), "user_powersaver_enable");
|
||||
if (htcValue != null && htcValue.equals("1")) {
|
||||
return true;
|
||||
}
|
||||
// Samsung (Touchwiz)
|
||||
String samsungValue = Settings.System.getString(context.getContentResolver(), "psm_switch");
|
||||
if (samsungValue != null && samsungValue.equals("1")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void sendPowerSaving(final Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
isPowerSaving = getNativePowerSaving(context) || getExtraPowerSaving(context);
|
||||
} else {
|
||||
isPowerSaving = getExtraPowerSaving(context);
|
||||
}
|
||||
|
||||
if (isBatteryLow || isPowerSaving) {
|
||||
NativeApp.sendMessage("core_powerSaving", "true");
|
||||
} else {
|
||||
NativeApp.sendMessage("core_powerSaving", "false");
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
private boolean getPowerSaving(final Context context) {
|
||||
final PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isPowerSaveMode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue