Skip to content
Permalink
Browse files

Merge pull request #12260 from Florin9doi/PowerSaveMode2

Update PowerSaveModeReceiver (again)
  • Loading branch information...
hrydgard committed Aug 20, 2019
2 parents a7ce741 + 187dfb2 commit f46a63cfd9b265384be607270a16229421dfe4a5
@@ -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 @@
private InputDeviceState inputPlayerC;
private String inputPlayerADesc;

private PowerSaveModeReceiver mPowerSaveModeReceiver = null;

private static LocationHelper mLocationHelper;
private static CameraHelper mCameraHelper;

@@ -311,7 +313,6 @@ public void Initialize() {
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 void onCreate(Bundle savedInstanceState) {
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 @@ protected void onDestroy() {
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 @@ protected void onResume() {
mSurfaceView.onResume();
}
}
PowerSaveModeReceiver.sendPowerSaving(this);

gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
NativeApp.resume();
@@ -16,7 +16,6 @@

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 void onReceive(final Context context, final Intent intent) {
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 void onChange(boolean selfChange, Uri uri) {
}
});
}
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 @@ private static boolean getBooleanSetting(final Context context, final String nam
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 {

0 comments on commit f46a63c

Please sign in to comment.
You can’t perform that action at this time.