diff --git a/Core/Core.cpp b/Core/Core.cpp
index 8beaecd685..87d3d40fd7 100644
--- a/Core/Core.cpp
+++ b/Core/Core.cpp
@@ -56,9 +56,10 @@ static bool windowHidden = false;
static double lastActivity = 0.0;
static double lastKeepAwake = 0.0;
static GraphicsContext *graphicsContext;
+static bool powerSaving = false;
void Core_SetGraphicsContext(GraphicsContext *ctx) {
- graphicsContext = ctx;
+ graphicsContext = ctx;
}
void Core_NotifyWindowHidden(bool hidden) {
@@ -120,6 +121,14 @@ void Core_WaitInactive(int milliseconds) {
}
}
+void Core_SetPowerSaving(bool mode) {
+ powerSaving = mode;
+}
+
+bool Core_GetPowerSaving() {
+ return powerSaving;
+}
+
bool UpdateScreenScale(int width, int height, bool smallWindow) {
g_dpi = 72;
g_dpi_scale = 1.0f;
diff --git a/Core/Core.h b/Core/Core.h
index 3cf96c8575..d21ec4847a 100644
--- a/Core/Core.h
+++ b/Core/Core.h
@@ -52,3 +52,6 @@ bool UpdateScreenScale(int width, int height, bool smallWindow);
// Don't run the core when minimized etc.
void Core_NotifyWindowHidden(bool hidden);
void Core_NotifyActivity();
+
+void Core_SetPowerSaving(bool mode);
+bool Core_GetPowerSaving();
diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp
index 81669500d5..fdf78a3d5d 100644
--- a/UI/EmuScreen.cpp
+++ b/UI/EmuScreen.cpp
@@ -196,6 +196,11 @@ void EmuScreen::bootComplete() {
}
}
+ if (Core_GetPowerSaving()) {
+ I18NCategory *sy = GetI18NCategory("System");
+ osm.Show(sy->T("WARNING: Battery save mode is on"), 2.0f, 0xFFFFFF, -1, true, "core_powerSaving");
+ }
+
System_SendMessage("event", "startgame");
}
diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp
index ba3401d71a..048a235c8a 100644
--- a/UI/NativeApp.cpp
+++ b/UI/NativeApp.cpp
@@ -784,6 +784,14 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) {
// Show for the same duration as the preview.
osm.Show(msg, 2.0f, 0xFFFFFF, -1, true, "savestate_slot");
}
+ if (msg == "core_powerSaving") {
+ if (value != "false") {
+ I18NCategory *sy = GetI18NCategory("System");
+ osm.Show(sy->T("WARNING: Battery save mode is on"), 2.0f, 0xFFFFFF, -1, true, "core_powerSaving");
+ }
+
+ Core_SetPowerSaving(value != "false");
+ }
}
void NativeUpdate(InputState &input) {
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index a9bd8f3324..bcb1ca730f 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -96,6 +96,14 @@
+
+
+
+
+
+
+
+
diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java
index 6453530f77..245f45c5b6 100644
--- a/android/src/org/ppsspp/ppsspp/NativeActivity.java
+++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java
@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.os.PowerManager;
import android.os.Vibrator;
import android.text.InputType;
import android.util.DisplayMetrics;
@@ -124,6 +125,16 @@ 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 {
@@ -272,6 +283,9 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
javaGL = "true".equalsIgnoreCase(NativeApp.queryConfig("androidJavaGL"));
sendInitialGrants();
+ if (Build.VERSION.SDK_INT >= 21) {
+ sendPowerSaving();
+ }
// OK, config should be initialized, we can query for screen rotation.
if (Build.VERSION.SDK_INT >= 9) {
diff --git a/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java
new file mode 100644
index 0000000000..27a2b92f7d
--- /dev/null
+++ b/android/src/org/ppsspp/ppsspp/PowerSaveModeReceiver.java
@@ -0,0 +1,41 @@
+package org.ppsspp.ppsspp;
+
+import android.annotation.TargetApi;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.PowerManager;
+
+public class PowerSaveModeReceiver extends BroadcastReceiver {
+ private boolean isPowerSaving = false;
+ private 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;
+ } else if (action.equals(Intent.ACTION_BATTERY_OKAY)) {
+ isBatteryLow = false;
+ }
+
+ 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();
+ }
+}