Search in sources :

Example 81 with PowerManager

use of android.os.PowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CryptKeeper method passwordEntryInit.

private void passwordEntryInit() {
    // Password/pin case
    mPasswordEntry = (EditText) findViewById(R.id.passwordEntry);
    if (mPasswordEntry != null) {
        mPasswordEntry.setOnEditorActionListener(this);
        mPasswordEntry.requestFocus();
        // Become quiet when the user interacts with the Edit text screen.
        mPasswordEntry.setOnKeyListener(this);
        mPasswordEntry.setOnTouchListener(this);
        mPasswordEntry.addTextChangedListener(this);
    }
    mLockPatternButtons.clear();
    // Pattern case
    mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern);
    if (mLockPatternView != null) {
        mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener);
        for (int id : LOCK_BUTTON_IDS) {
            Button btn = (Button) findViewById(id);
            if (btn != null) {
                btn.setOnClickListener(this);
                mLockPatternButtons.add(btn);
            }
        }
    }
    // Disable the Emergency call button if the device has no voice telephone capability
    if (!getTelephonyManager().isVoiceCapable()) {
        final View emergencyCall = findViewById(R.id.emergencyCallButton);
        if (emergencyCall != null) {
            Log.d(TAG, "Removing the emergency Call button");
            emergencyCall.setVisibility(View.GONE);
        }
    }
    final View imeSwitcher = findViewById(R.id.switch_ime_button);
    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imeSwitcher != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) {
        imeSwitcher.setVisibility(View.VISIBLE);
        imeSwitcher.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                imm.showInputMethodPicker(false);
            }
        });
    }
    // password.
    if (mWakeLock == null) {
        Log.d(TAG, "Acquiring wakelock.");
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (pm != null) {
            mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
            mWakeLock.acquire();
            // Keep awake for 10 minutes - if the user hasn't been alerted by then
            // best not to just drain their battery
            // 96 * 5 secs per click + 120 secs before we show this = 600
            mReleaseWakeLockCountdown = 96;
        }
    }
    // immediately.
    if (mLockPatternView == null && !mCooldown) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                imm.showSoftInputUnchecked(0, null);
            }
        }, 0);
    }
    updateEmergencyCallButtonState();
    // Notify the user in 120 seconds that we are waiting for him to enter the password.
    mHandler.removeMessages(MESSAGE_NOTIFY);
    mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 120 * 1000);
    // Dismiss secure & non-secure keyguards while this screen is showing.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
Also used : PowerManager(android.os.PowerManager) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) TextView(android.widget.TextView) LockPatternView(com.android.internal.widget.LockPatternView)

Example 82 with PowerManager

use of android.os.PowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothPairingRequest method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
        // convert broadcast intent into activity intent (same action string)
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
        Intent pairingIntent = new Intent();
        pairingIntent.setClass(context, BluetoothPairingDialog.class);
        pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
        if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
            int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR);
            pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
        }
        pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        String deviceAddress = device != null ? device.getAddress() : null;
        String deviceName = device != null ? device.getName() : null;
        boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(context, deviceAddress, deviceName);
        if (powerManager.isInteractive() && shouldShowDialog) {
            // Since the screen is on and the BT-related activity is in the foreground,
            // just open the dialog
            context.startActivity(pairingIntent);
        } else {
            // Put up a notification that leads to the dialog
            Resources res = context.getResources();
            Notification.Builder builder = new Notification.Builder(context).setSmallIcon(android.R.drawable.stat_sys_data_bluetooth).setTicker(res.getString(R.string.bluetooth_notif_ticker));
            PendingIntent pending = PendingIntent.getActivity(context, 0, pairingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
            if (TextUtils.isEmpty(name)) {
                name = device != null ? device.getAliasName() : context.getString(android.R.string.unknownName);
            }
            builder.setContentTitle(res.getString(R.string.bluetooth_notif_title)).setContentText(res.getString(R.string.bluetooth_notif_message, name)).setContentIntent(pending).setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color));
            NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            manager.notify(NOTIFICATION_ID, builder.getNotification());
        }
    } else if (action.equals(BluetoothDevice.ACTION_PAIRING_CANCEL)) {
        Intent pairingIntent = new Intent();
        pairingIntent.setClass(context, BluetoothPairingDialog.class);
        pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pending = PendingIntent.getActivity(context, 0, pairingIntent, PendingIntent.FLAG_NO_CREATE);
        if (pending != null) {
            pending.cancel();
        }
        // Remove the notification
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(NOTIFICATION_ID);
    } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
        int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
        int oldState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
        if ((oldState == BluetoothDevice.BOND_BONDING) && (bondState == BluetoothDevice.BOND_NONE)) {
            // Remove the notification
            NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            manager.cancel(NOTIFICATION_ID);
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) PowerManager(android.os.PowerManager) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent)

Example 83 with PowerManager

use of android.os.PowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DockEventReceiver method beginStartingService.

/**
     * Start the service to process the current event notifications, acquiring
     * the wake lock before returning to ensure that the service will run.
     */
private static void beginStartingService(Context context, Intent intent) {
    synchronized (sStartingServiceSync) {
        if (sStartingService == null) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            sStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "StartingDockService");
        }
        sStartingService.acquire();
        if (context.startService(intent) == null) {
            Log.e(TAG, "Can't start DockService");
        }
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 84 with PowerManager

use of android.os.PowerManager in project u2020 by JakeWharton.

the class DebugViewContainer method riseAndShine.

/**
   * Show the activity over the lock-screen and wake up the device. If you launched the app manually
   * both of these conditions are already true. If you deployed from the IDE, however, this will
   * save you from hundreds of power button presses and pattern swiping per day!
   */
public static void riseAndShine(Activity activity) {
    activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED);
    PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE);
    PowerManager.WakeLock lock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "wakeup!");
    lock.acquire();
    lock.release();
}
Also used : PowerManager(android.os.PowerManager)

Example 85 with PowerManager

use of android.os.PowerManager in project u2020 by JakeWharton.

the class U2020TestRunner method onStart.

@SuppressLint("MissingPermission")
@Override
public void onStart() {
    // Inform the app we are an instrumentation test before the object graph is initialized.
    DebugU2020Module.instrumentationTest = true;
    Context app = getTargetContext().getApplicationContext();
    String name = U2020TestRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE);
    keyguard.newKeyguardLock(name).disableKeyguard();
    // Wake up the screen.
    PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE);
    wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
    wakeLock.acquire();
    super.onStart();
}
Also used : Context(android.content.Context) PowerManager(android.os.PowerManager) KeyguardManager(android.app.KeyguardManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7