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

Commit d26a673a authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Wake device from DayDream for BT Pairing request."

parents e4bff212 03baddb8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_DREAM_STATE" />
    <uses-permission android:name="android.permission.WRITE_DREAM_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.DEVICE_POWER" />
+38 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.text.Editable;
import android.text.Html;
import android.text.InputFilter;
@@ -111,6 +116,12 @@ public final class BluetoothPairingDialog extends AlertActivity implements
            finish();
            return;
        }

        // If a pairing request is received and the device is dreaming (i.e. the screen timeout
        // occurred while the user was initiating pairing), wake it up when this dialog is
        // displayed.
        wakeDeviceUpFromDreamIfDreaming();

        mCachedDeviceManager = mBluetoothManager.getCachedDeviceManager();

        mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@@ -168,6 +179,33 @@ public final class BluetoothPairingDialog extends AlertActivity implements
        registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
    }

    /**
     * If the device is in a daydream, wake it up.
     */
    private void wakeDeviceUpFromDreamIfDreaming() {
        IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
                ServiceManager.getService(DreamService.DREAM_SERVICE));

        try {
            if (dreamManagerService != null && dreamManagerService.isDreaming()) {
                dreamManagerService.awaken();

                PowerManager pm = (PowerManager) getSystemService(
                        Context.POWER_SERVICE);
                PowerManager.WakeLock wl = pm.newWakeLock(
                        PowerManager.ACQUIRE_CAUSES_WAKEUP
                        | PowerManager.FULL_WAKE_LOCK
                        | PowerManager.ON_AFTER_RELEASE,
                        TAG);
                wl.acquire();
                // Just wake the device, then release.
                wl.release();
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to awaken from dream", e);
        }
    }

    private void createUserEntryDialog() {
        final AlertController.AlertParams p = mAlertParams;
        p.mTitle = getString(R.string.bluetooth_pairing_request);