Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f99ae765 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Hold wake lock while shutting down.

It is nicer to make sure the screen stays on while we are shutting
down, so the screen goes off when we are actually complete rather
than some time before.

Change-Id: I8725ac9884df6d21344f35288da3e375d9779b3b
parent 529b2854
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.Power;
import android.os.ServiceManager;
@@ -56,6 +57,8 @@ public final class ShutdownThread extends Thread {
    private final Object mBroadcastDoneSync = new Object();
    private boolean mBroadcastDone;
    private Context mContext;
    private PowerManager mPowerManager;
    private PowerManager.WakeLock mWakeLock;
    private Handler mHandler;
    
    private ShutdownThread() {
@@ -125,6 +128,18 @@ public final class ShutdownThread extends Thread {

        // start the thread that initiates shutdown
        sInstance.mContext = context;
        sInstance.mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        sInstance.mWakeLock = null;
        if (sInstance.mPowerManager.isScreenOn()) {
            try {
                sInstance.mWakeLock = sInstance.mPowerManager.newWakeLock(
                        PowerManager.FULL_WAKE_LOCK, "Shutdown");
                sInstance.mWakeLock.acquire();
            } catch (SecurityException e) {
                Log.w(TAG, "No permission to acquire wake lock", e);
                sInstance.mWakeLock = null;
            }
        }
        sInstance.mHandler = new Handler() {
        };
        sInstance.start();