Search in sources :

Example 11 with KeyguardManager

use of android.app.KeyguardManager in project android-app-common-tasks by multidots.

the class Common method disableSleepMode.

// ------------------------------
/**
     * use for make disable sleep screen lock while application in use.
     *
     * @param mContext
     */
@SuppressWarnings({ "static-access" })
public static void disableSleepMode(Context mContext) {
    System.out.println("disable");
    ((Activity) mContext).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(Activity.KEYGUARD_SERVICE);
    lock = keyguardManager.newKeyguardLock(mContext.KEYGUARD_SERVICE);
    lock.disableKeyguard();
}
Also used : KeyguardManager(android.app.KeyguardManager)

Example 12 with KeyguardManager

use of android.app.KeyguardManager in project boxing by Bilibili.

the class PickerFragmentTest method setup.

@Before
public void setup() throws Throwable {
    // espresso need the screen on
    final Activity activity = mRule.getActivity();
    mRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
            KeyguardManager.KeyguardLock lock = km.newKeyguardLock(Context.KEYGUARD_SERVICE);
            lock.disableKeyguard();
            //turn the screen on
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
        }
    });
}
Also used : Activity(android.app.Activity) KeyguardManager(android.app.KeyguardManager) Before(org.junit.Before)

Example 13 with KeyguardManager

use of android.app.KeyguardManager 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)

Example 14 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by DirtyUnicorns.

the class PhoneWindowManager method powerLongPress.

private void powerLongPress() {
    if (!mTorchEnabled || isScreenOn()) {
        int behavior = getResolvedLongPressOnPowerBehavior();
        switch(behavior) {
            case LONG_PRESS_POWER_NOTHING:
                break;
            case LONG_PRESS_POWER_GLOBAL_ACTIONS:
                mPowerKeyHandled = true;
                if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
                    performAuditoryFeedbackForAccessibilityIfNeed();
                }
                KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
                boolean locked = km.inKeyguardRestrictedInputMode();
                boolean globalActionsOnLockScreen = Settings.System.getInt(mContext.getContentResolver(), Settings.System.POWER_MENU_LOCKSCREEN, 1) == 1;
                if (locked && !globalActionsOnLockScreen) {
                    behavior = LONG_PRESS_POWER_NOTHING;
                } else {
                    showGlobalActionsInternal();
                }
                break;
            case LONG_PRESS_POWER_SHUT_OFF:
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
                mPowerKeyHandled = true;
                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
                break;
        }
    } else if (mTorchEnabled && !isScreenOn()) {
        try {
            mCameraManager.setTorchMode(getCameraId(), true);
        } catch (Exception e) {
        }
        mWasTorchActive = false;
        mIsTorchActive = true;
        mPowerKeyHandled = true;
    }
}
Also used : KeyguardManager(android.app.KeyguardManager) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) CameraAccessException(android.hardware.camera2.CameraAccessException)

Example 15 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by crdroidandroid.

the class ConnectivityManagerTestBase method turnScreenOn.

// Turn screen on
protected void turnScreenOn() {
    logv("Turn screen on");
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    pm.wakeUp(SystemClock.uptimeMillis());
    // disable lock screen
    KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode()) {
        sendKeys(KeyEvent.KEYCODE_MENU);
    }
}
Also used : PowerManager(android.os.PowerManager) KeyguardManager(android.app.KeyguardManager)

Aggregations

KeyguardManager (android.app.KeyguardManager)46 Intent (android.content.Intent)25 PendingIntent (android.app.PendingIntent)14 IIntentSender (android.content.IIntentSender)10 IntentSender (android.content.IntentSender)10 PowerManager (android.os.PowerManager)8 Resources (android.content.res.Resources)5 RemoteException (android.os.RemoteException)4 Context (android.content.Context)3 SuppressLint (android.annotation.SuppressLint)2 WindowManager (android.view.WindowManager)2 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 AlarmManager (android.app.AlarmManager)1 IActivityManager (android.app.IActivityManager)1 NotificationManager (android.app.NotificationManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 SensorManager (android.hardware.SensorManager)1 CameraAccessException (android.hardware.camera2.CameraAccessException)1