mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-14 15:00:30 +02:00
Update PowerSaveModeReceiver (again)
This commit is contained in:
1 parent
010da8080c
commit
187dfb2816
3 files changed
+23
-31
No files matched your search
@@ -102,14 +102,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".PowerSaveModeReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.os.action.POWER_SAVE_MODE_CHANGED" />
|
||||
<action android:name="android.intent.action.BATTERY_LOW" />
|
||||
<action android:name="android.intent.action.BATTERY_OKAY" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<meta-data
|
||||
android:name="xperiaplayoptimized_content"
|
||||
android:resource="@drawable/ic_launcher" />
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user