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();
}
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);
}
});
}
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();
}
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;
}
}
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);
}
}
Aggregations