Java 类android.app.KeyguardManager 实例源码

项目:GongXianSheng    文件:UnlockDeviceAndroidJUnitRunner.java   
@SuppressLint("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
项目:GitHub    文件:PickerFragmentTest.java   
@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);
        }
    });
}
项目:stynico    文件:AppCompatDlalog.java   
private void wakeAndUnlock()
{
    //获取电源管理器对象
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //点亮屏幕
    wl.acquire(1000);

    //得到键盘锁管理器对象
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    kl = km.newKeyguardLock("unLock");

    //解锁
    kl.disableKeyguard();

}
项目:stynico    文件:dex_smali.java   
private void wakeAndUnlock(boolean b)
   {
if (b)
{
    //获取电源管理器对象
    mPowerManager = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE);
    //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
    mWakeLock = mPowerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
    //点亮屏幕
    mWakeLock.acquire();
    //得到键盘锁管理器对象
    mKeyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
    mKeyguardLock = mKeyguardManager.newKeyguardLock("unLock");
    //解锁
    mKeyguardLock.disableKeyguard();
}
else
{
    //锁屏
    mKeyguardLock.reenableKeyguard();
    //释放wakeLock,关灯
    mWakeLock.release();
}}
项目:miser-utils    文件:ComeOnMoneyService.java   
private void wakeAndUnlock(boolean b) {
    Log.i(TAG, "解锁亮屏?:" + b);
    if (b) {
        //获取电源管理器对象
        pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
        wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
        //点亮屏幕
        wl.acquire();
        //得到键盘锁管理器对象
        km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        kl = km.newKeyguardLock("unLock");
        //解锁
        kl.disableKeyguard();
        isWaked = true;
    } else {
        //锁屏
        kl.reenableKeyguard();
        //释放wakeLock,关灯
        wl.release();
    }
}
项目:Phoenix-for-VK    文件:FingerprintTools.java   
public static SensorState checkSensorState(Context context) {
    if (checkFingerprintCompatibility(context)) {
        KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

        if (!keyguardManager.isKeyguardSecure()) {
            return SensorState.NOT_BLOCKED;
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !((FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE)).hasEnrolledFingerprints()) {
            return SensorState.NO_FINGERPRINTS;
        }

        return SensorState.READY;
    } else {
        return SensorState.NOT_SUPPORTED;
    }
}
项目:airgram    文件:PopupNotificationActivity.java   
private void handleIntent(Intent intent) {
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
        getWindow().addFlags(
                        WindowManager.LayoutParams.FLAG_DIM_BEHIND |
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    if (currentMessageObject == null) {
        currentMessageNum = 0;
    }
    getNewMessage();
}
项目:WeChatFingerprintPay    文件:PayHook.java   
private void initFingerPrint(Context context) {
    KeyguardManager keyguardManager =
            (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    FingerprintManager fingerprintManager =
            (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);

    if (!fingerprintManager.isHardwareDetected()) {
        Toast.makeText(context, "Your device doesn't support fingerprint authentication", Toast.LENGTH_LONG).show();
    } else if (context.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(context, "Please enable the fingerprint permission", Toast.LENGTH_LONG).show();
    } else if (!fingerprintManager.hasEnrolledFingerprints()) {
        Toast.makeText(
                context,
                "No fingerprint configured. Please register at least one fingerprint in your device's Settings",
                Toast.LENGTH_LONG).show();
    } else if (!keyguardManager.isKeyguardSecure()) {
        Toast.makeText(
                context,
                "Please enable lock screen security in your device's Settings",
                Toast.LENGTH_LONG).show();
    } else {
        fHandler = new FingerprintHandler(context);
    }
}
项目:boxing    文件:PickerFragmentTest.java   
@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);
        }
    });
}
项目:Android-Show-Reader    文件:UnlockDeviceAndroidJUnitRunner.java   
@SuppressWarnings("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
项目:REDAndroid    文件:UnlockDeviceAndroidJUnitRunner.java   
@SuppressLint("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
项目:MiHomePlus    文件:MyAccessibility.java   
private void wakeAndUnlock(boolean b) {
    if (b) {
        //获取电源管理器对象
        powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
        wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);

        // 屏幕解锁
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");

        keyguardLock.reenableKeyguard();
        keyguardLock.disableKeyguard(); // 解锁

        //点亮屏幕
        wakeLock.acquire();
    } else {
        //释放wakeLock,关灯
        wakeLock.release();
    }
}
项目:buildAPKsSamples    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    Button purchaseButton = (Button) findViewById(R.id.purchase_button);
    if (!mKeyguardManager.isKeyguardSecure()) {
        // Show a message that the user hasn't set up a lock screen.
        Toast.makeText(this,
                "Secure lock screen hasn't set up.\n"
                        + "Go to 'Settings -> Security -> Screenlock' to set up a lock screen",
                Toast.LENGTH_LONG).show();
        purchaseButton.setEnabled(false);
        return;
    }
    createKey();
    findViewById(R.id.purchase_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Test to encrypt something. It might fail if the timeout expired (30s).
            tryEncrypt();
        }
    });
}
项目:QiangHongBao    文件:NotifyUtils.java   
public static void wakeAndUnlock() {
    //获取电源管理器对象
    PowerManager pm = getPowerManager();

    //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //点亮屏幕
    wl.acquire(1000);

    //得到键盘锁管理器对象
    KeyguardManager km = getKeyguardManager();
    KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");

    //解锁
    kl.disableKeyguard();
}
项目:ReplyMessage    文件:AutoReplyService.java   
private void wakeAndUnlock() {
    //获取电源管理器对象
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //点亮屏幕
    wl.acquire(1000);

    //得到键盘锁管理器对象
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    kl = km.newKeyguardLock("unLock");

    //解锁
    kl.disableKeyguard();

}
项目:JinsMemeBRIDGE-Android    文件:MainActivity.java   
void showAuthScreen() {
  KeyguardManager keyguardManager = (KeyguardManager) getSystemService(
      Context.KEYGUARD_SERVICE);

  if (!keyguardManager.isKeyguardSecure()) {
    basicConfigFragment.unlockAppIDandSecret();
    return;
  }

  Intent intent = keyguardManager
      .createConfirmDeviceCredentialIntent(getString(R.string.unlock_auth_title),
          getString(R.string.unlock_auth_explain));

  if (intent != null) {
    startActivityForResult(intent, 1);
  }
}
项目:programming    文件:MainActivity.java   
private void inicializarSeguranca() {

        if (ActivityCompat.checkSelfPermission(this,
                Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {

            Toast.makeText(this,
                    getString(R.string.fingerprint_error_no_permission),
                    Toast.LENGTH_LONG).show();

            return;
        }

        keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);

        keystoreManager = new AndroidKeystoreManager(KEY_NAME);
        keystoreManager.generateKey();

        if (keystoreManager.cipherInit()) {
            cryptoObject = new FingerprintManager.CryptoObject(keystoreManager.getCipher());
        }
    }
项目:GravityBox    文件:ModLedControl.java   
private static void toggleActiveScreenFeature(boolean enable) {
    try {
        if (enable && mContext != null) {
            mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            mKm = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
            mSm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
            mProxSensor = mSm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        } else {
            mProxSensor = null;
            mSm = null;
            mPm = null;
            mKm = null;
        }
        if (DEBUG) log("Active screen feature: " + enable);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
项目:trust-wallet-android    文件:KS.java   
public static void showAuthenticationScreen(Context context, int requestCode) {
    // Create the Confirm Credentials screen. You can customize the title and description. Or
    // we will provide a generic one for you if you leave it null
    Log.e(TAG, "showAuthenticationScreen: ");
    if (context instanceof Activity) {
        Activity app = (Activity) context;
        KeyguardManager mKeyguardManager = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
        if (mKeyguardManager == null) {
            return;
        }
        Intent intent = mKeyguardManager
                .createConfirmDeviceCredentialIntent(
                        context.getString(R.string.unlock_screen_title_android),
                        context.getString(R.string.unlock_screen_prompt_android));
        if (intent != null) {
            app.startActivityForResult(intent, requestCode);
        } else {
            Log.e(TAG, "showAuthenticationScreen: failed to create intent for auth");
            app.finish();
        }
    } else {
        Log.e(TAG, "showAuthenticationScreen: context is not activity!");
    }
}
项目:kheera-testrunner-android    文件:LoginScreen.java   
public static void open() {

            boolean mInitialTouchMode = false;

            getInstrumentation().setInTouchMode(mInitialTouchMode);

            Intent newIntent = new Intent(getInstrumentation().getTargetContext(), LoginActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ActivityInstance = getInstrumentation().startActivitySync(newIntent);

            getInstrumentation().waitForIdleSync();

            ((KeyguardManager) getInstrumentation().getContext().getSystemService(KEYGUARD_SERVICE)).newKeyguardLock(KEYGUARD_SERVICE).disableKeyguard();

            //turn the screen on
            ActivityInstance.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ActivityInstance.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);
                }
            });
    }
项目:schulcloud-mobile-android    文件:UnlockDeviceAndroidJUnitRunner.java   
@Override
@SuppressLint("MissingPermission")
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = (PowerManager) application.getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
项目:appkicker    文件:AppUsageLogger.java   
/**
     * creates a new app logger that needs to be started afterwards
     * @param context
     */
    private AppUsageLogger(Context context) {
        super("AppSensorThread");

        // better synchronize
//      appChangeListeners = new HashSet<AppChangeListener>();

        Utils.d(AppUsageLogger.class, "created new instance");
        this.context = context;
        keyManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        appHistory = new ArrayList<AppUsageEvent>();
        generalInteractionHistory = new ArrayList<AppUsageEvent>();
        activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);



    }
项目:android-overlay-protection    文件:MonitorAccessibilityService.java   
private void InitializeDetectionEngine() {
    Class clazz = _settings.getDetectionEngine().getDetectionClass();
    if (_detectionEngine != null) {
        if (clazz.isInstance(_detectionEngine)) {
            return;
        }
    }

    try {
        ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);
        ProcessHelper processHelper = new ProcessHelper(activityManager);
        _detectionEngine = (AbstractDetectionEngine) clazz
                .getConstructor(Context.class, DatabaseHelper.class, KeyguardManager.class, IOverlayNotifyService.class, ProcessHelper.class)
                .newInstance(getApplicationContext(), _helper, _keyguardManager, this, processHelper);
    } catch (Exception e) {
        Log.e(TAG, "Failed to instantiate detection engine", e);
    }

}
项目:toothpick    文件:SmoothieApplicationModule.java   
private void bindSystemServices(Application application) {
  bindSystemService(application, LocationManager.class, LOCATION_SERVICE);
  bindSystemService(application, WindowManager.class, WINDOW_SERVICE);
  bindSystemService(application, ActivityManager.class, ACTIVITY_SERVICE);
  bindSystemService(application, PowerManager.class, POWER_SERVICE);
  bindSystemService(application, AlarmManager.class, ALARM_SERVICE);
  bindSystemService(application, NotificationManager.class, NOTIFICATION_SERVICE);
  bindSystemService(application, KeyguardManager.class, KEYGUARD_SERVICE);
  bindSystemService(application, Vibrator.class, VIBRATOR_SERVICE);
  bindSystemService(application, ConnectivityManager.class, CONNECTIVITY_SERVICE);
  bindSystemService(application, WifiManager.class, WIFI_SERVICE);
  bindSystemService(application, InputMethodManager.class, INPUT_METHOD_SERVICE);
  bindSystemService(application, SearchManager.class, SEARCH_SERVICE);
  bindSystemService(application, SensorManager.class, SENSOR_SERVICE);
  bindSystemService(application, TelephonyManager.class, TELEPHONY_SERVICE);
  bindSystemService(application, AudioManager.class, AUDIO_SERVICE);
  bindSystemService(application, DownloadManager.class, DOWNLOAD_SERVICE);
}
项目:GestureWave    文件:SensorService.java   
@Override
public void onCreate()
{
    super.onCreate();

    //CREATES A NEW DATABASE INSTANCE
    dbHelper = new DBHelper(this);

    handlerLock = false;
    statusBarDown = false;
    sensorChangeCount = 0;
    direction = 0;

    audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    waveHandler = new Handler();
    screenFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
    screenStateReceiver = setScreenStateReceiver(this);
    sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
}
项目:android-fingerprint-example    文件:MainActivity.java   
private void checkFingerprints() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.USE_FINGERPRINT}, REQ_FINGERPRINT_PERMISSION);
        return;
    }
    mKeyguardManager = getSystemService(KeyguardManager.class);
    mFingerPrintManager = getSystemService(FingerprintManager.class);

    if(!backdoor) {
        Toast.makeText(MainActivity.this, R.string.checking_secure_n_permissions, Toast.LENGTH_SHORT).show();
        if (!mKeyguardManager.isKeyguardSecure()) {
            Toast.makeText(MainActivity.this, R.string.go_2_settings, Toast.LENGTH_LONG).show();
            return;
        }
        if (!mFingerPrintManager.hasEnrolledFingerprints()) {
            Toast.makeText(MainActivity.this, R.string.go_2_settings, Toast.LENGTH_LONG).show();
            return;
        }
    }
    createKey();
    showFingerPrintDialog();
}
项目:Newton_for_Android_AS    文件:AlertWakeLock.java   
/**
 * 激活屏幕,不锁屏。 每次唤醒屏幕前都release。
 * 
 * @param context
 */
public static void acquire(Context context) {
    DebugLog.v(TAG, "Acquiring wake lock");
    if (sWakeLock != null) {
        sWakeLock.release();
    }

    PowerManager pm = (PowerManager) context
            .getSystemService(Context.POWER_SERVICE);

    sWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, TAG);

    sWakeLock.acquire();

    // 解锁
    KeyguardManager keyguardManager = (KeyguardManager) context
            .getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
    keyguardLock.disableKeyguard();
}
项目:Hover    文件:HoverService.java   
@Override
public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_PRESENT);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);

    screenReceiver = new ScreenReceiver();
    registerReceiver(screenReceiver, filter);
}
项目:j2se_for_android    文件:AndroidPlatformService.java   
public boolean isLockScreen(){
       final KeyguardManager km = (KeyguardManager)ActivityManager.getActivity().getSystemService(Context.KEYGUARD_SERVICE);
       final boolean isLock = km.inKeyguardRestrictedInputMode();

       if(isLock == false){
        final String isPause = System.getProperty("user.hc.app.isPause");
        if(isPause != null && isPause.equals("true")){
            //切换到当前的应用中
            AndroidUIUtil.runDelay(new Runnable() {
                @Override
                public void run() {
                    J2SEInitor.doAction(J2SEActionMap.startBringToFrontService);

                    try{
                        Thread.sleep(2000);
                    }catch (final Exception e) {
                    }

                    J2SEInitor.doAction(J2SEActionMap.stopBringToFrontService);
                }
            });
        }
       }

       return isLock;
}
项目:mobile-messaging-sdk-android    文件:DeviceInformation.java   
public static boolean isDeviceSecure(Context context) {
    // Starting with android 6.0 calling isLockScreenDisabled fails altogether because the signature has changed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        KeyguardManager keyguardMgr = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        return keyguardMgr != null && keyguardMgr.isDeviceSecure();
    }

    try {
        String LOCKSCREEN_UTILS_CLASSNAME = "com.android.internal.widget.LockPatternUtils";
        Class<?> lockUtilsClass = Class.forName(LOCKSCREEN_UTILS_CLASSNAME);
        Object lockUtils = lockUtilsClass.getConstructor(Context.class).newInstance(context);
        Method method = lockUtilsClass.getMethod("getActivePasswordQuality");

        // Starting with android 5.x this fails with InvocationTargetException (caused by SecurityException - MANAGE_USERS permission is
        // required because internally some additional logic was added to return false if one can switch between several users)
        // -> therefore if no exception is thrown, we know the screen lock setting is set to Pattern, PIN/PW or something else other than 'None' or 'Swipe'
        Integer lockProtectionLevel = (Integer) method.invoke(lockUtils);
        return lockProtectionLevel >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;

    } catch (InvocationTargetException ignored) {
    } catch (Exception e) {
        MobileMessagingLogger.e("Error detecting whether screen lock is disabled: " + e);
    }

    return false;
}
项目:wirebug    文件:DebugStatusService.java   
@Override
public void onCreate() {
    super.onCreate();

    Timber.d("Service is created");

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    if (powerManager == null) {
        Timber.e("Not able to access PowerManager");
        return;
    }

    wakeLock = powerManager.newWakeLock(
        PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
        TAG);

    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    notificationBuilder = createNotificationBuilder();
}
项目:Auth0.Android    文件:SecureCredentialsManager.java   
/**
 * Require the user to authenticate using the configured LockScreen before accessing the credentials.
 * This feature is disabled by default and will only work if the device is running on Android version 21 or up and if the user
 * has configured a secure LockScreen (PIN, Pattern, Password or Fingerprint).
 * <p>
 * The activity passed as first argument here must override the {@link Activity#onActivityResult(int, int, Intent)} method and
 * call {@link SecureCredentialsManager#checkAuthenticationResult(int, int)} with the received parameters.
 *
 * @param activity    a valid activity context. Will be used in the authentication request to launch a LockScreen intent.
 * @param requestCode the request code to use in the authentication request. Must be a value between 1 and 255.
 * @param title       the text to use as title in the authentication screen. Passing null will result in using the OS's default value.
 * @param description the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value.
 * @return whether this device supports requiring authentication or not. This result can be ignored safely.
 */
public boolean requireAuthentication(@NonNull Activity activity, @IntRange(from = 1, to = 255) int requestCode, @Nullable String title, @Nullable String description) {
    if (requestCode < 1 || requestCode > 255) {
        throw new IllegalArgumentException("Request code must a value between 1 and 255.");
    }
    KeyguardManager kManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    this.authIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? kManager.createConfirmDeviceCredentialIntent(title, description) : null;
    this.authenticateBeforeDecrypt = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && kManager.isDeviceSecure())
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && kManager.isKeyguardSecure()))
            && authIntent != null;
    if (authenticateBeforeDecrypt) {
        this.activity = activity;
        this.authenticationRequestCode = requestCode;
    }
    return authenticateBeforeDecrypt;
}
项目:Auth0.Android    文件:SecureCredentialsManagerTest.java   
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 21, manifest = Config.NONE)
public void shouldNotRequireAuthenticationIfAPI21AndLockScreenDisabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 21);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Disabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isKeyguardSecure()).thenReturn(false);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(null);

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(false));
}
项目:Auth0.Android    文件:SecureCredentialsManagerTest.java   
@RequiresApi(api = Build.VERSION_CODES.M)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 23, manifest = Config.NONE)
public void shouldNotRequireAuthenticationIfAPI23AndLockScreenDisabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 23);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Disabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isDeviceSecure()).thenReturn(false);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(null);

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(false));
}
项目:q-mail    文件:DeviceNotifications.java   
private boolean isPrivacyModeActive() {
    KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

    boolean privacyModeAlwaysEnabled = QMail.getNotificationHideSubject() == NotificationHideSubject.ALWAYS;
    boolean privacyModeEnabledWhenLocked = QMail.getNotificationHideSubject() == NotificationHideSubject.WHEN_LOCKED;
    boolean screenLocked = keyguardService.inKeyguardRestrictedInputMode();

    return privacyModeAlwaysEnabled || (privacyModeEnabledWhenLocked && screenLocked);
}
项目:GitHub    文件:TestRunner.java   
@Override
public void callApplicationOnCreate(final Application app) {
    // Unlock the screen
    KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
    keyguard.newKeyguardLock(getClass().getSimpleName()).disableKeyguard();

    // Start a wake lock
    PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
    mWakeLock = power.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                    | PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName());
    mWakeLock.acquire();
    super.callApplicationOnCreate(app);

}
项目:unlock-apk    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // add flag to current window
    Window window = this.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    // init KeyguardManager

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

    if (keyguardManager.inKeyguardRestrictedInputMode()) {
        KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(getLocalClassName());
        keyguardLock.disableKeyguard();
    }

    // wake up screen light
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "");
    wakeLock.acquire();

    // finish current activity
    finish();
}
项目:unlock-apk    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // add flag to current window
    Window window = this.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    // init KeyguardManager

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

    if (keyguardManager.inKeyguardRestrictedInputMode()) {
        KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(getLocalClassName());
        keyguardLock.disableKeyguard();
    }

    // wake up screen light
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "");
    wakeLock.acquire();

    // finish current activity
    finish();
}
项目:PluckLockEx    文件:AccelerometerService.java   
public static boolean lockDeviceNow(Context context, Context baseContext) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(baseContext);
    int lockMethod = prefs.getInt(PreferenceString.LOCK_METHOD, LOCK_METHOD_DEVICE_ADMIN);
    switch (lockMethod) {
        case LOCK_METHOD_DEVICE_ADMIN:
            KeyguardManager keyguardManager = (KeyguardManager) baseContext.getSystemService(Context.KEYGUARD_SERVICE);
            if (!keyguardManager.inKeyguardRestrictedInputMode()) {
                DevicePolicyManager dpm = (DevicePolicyManager) baseContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
                if (dpm.isAdminActive(new ComponentName(baseContext, AdminReceiver.class)))
                    dpm.lockNow();
            }
            return true;
        case LOCK_METHOD_ROOT:
            try {
                KeyguardManager km = (KeyguardManager) baseContext.getSystemService(Context.KEYGUARD_SERVICE);
                boolean locked = km.inKeyguardRestrictedInputMode();
                if (!locked) { // don't lock if already screen off
                    Runtime.getRuntime().exec(new String[]{"su", "-c", "input keyevent 26"}).waitFor();
                }
                return true;
            } catch (IOException | InterruptedException e) {
                Toast.makeText(context, "PluckLockEx Root access denied", Toast.LENGTH_SHORT).show();
            }

        case LOCK_METHOD_FAKE:
            Toast.makeText(context, "PluckLockEx fake lock", Toast.LENGTH_SHORT).show();
            return true;
    }
    return false;
}
项目:stynico    文件:Air.java   
private void wakeAndUnlock2(boolean b)
{
    if(b)
    {
        //获取电源管理器对象
        pm=(PowerManager) getSystemService(Context.POWER_SERVICE);

        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
        wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

        //点亮屏幕
        wl.acquire();

        //得到键盘锁管理器对象
        km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
        kl = km.newKeyguardLock("unLock");

        //解锁
        kl.disableKeyguard();
    }
    else
    {
        //锁屏
        kl.reenableKeyguard();

        //释放wakeLock,关灯
        wl.release();
    }

}