Java 类android.app.KeyguardManager.KeyguardLock 实例源码

项目: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();
}
项目:spotify-tv    文件:EspressoTestRule.java   
@SuppressWarnings("deprecation")
private void riseAndShine(Activity activity) {
    KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(activity.getLocalClassName());
    keyguardLock.disableKeyguard();

    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
    WakeLock lock = powerManager.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "wakeup!");

    lock.acquire();
    lock.release();
}
项目:bkbc-bitcoinpos    文件:BootReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {

    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {

        KeyguardManager keyguardManager = (KeyguardManager) context
                .getSystemService(Activity.KEYGUARD_SERVICE);
        KeyguardLock lock = keyguardManager
                .newKeyguardLock(Context.KEYGUARD_SERVICE);
        lock.disableKeyguard();

        Intent myIntent = new Intent(context, BitcoinPosActivity.class);

        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(myIntent);
    }
}
项目:EmailPopup    文件:KeyguardManager.java   
static synchronized void secureRelease(Context context, final SecureReleaseCallback callback) {
    if (keyguardLock != null) {
        final KeyguardLock finalKeyguardLock = keyguardLock;
        keyguardLock = null;
        Log.d(EmailPopup.LOG_TAG, "Keyguard released");

        getKeyguardManager(context).exitKeyguardSecurely(new android.app.KeyguardManager.OnKeyguardExitResult() {
            @Override
            public void onKeyguardExitResult(boolean success) {
                Log.d(EmailPopup.LOG_TAG, "onKeyguardExitResult: " + success);
                //Not sure why we need to reenable keyguard
                //but it is needed for subsequent keyguard unlock to work properly
                finalKeyguardLock.reenableKeyguard();
                if (success) {
                    callback.onKeyguardSecuredReleased();
                }
            }
        });
    }
    else {
        callback.onKeyguardSecuredReleased();
    }
}
项目:AlarmClock-Android    文件:AlarmManagerBroadcastReceiver.java   
@Override
public void onReceive(Context ctx, Intent intent) {         
    //Unlock device screen
    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
    wl.acquire(30*1000);

    mKeyGuardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("com.inostudio.alar_clock");
    mLock.disableKeyguard();

    //Create notification
    creatNotification(ctx);

    //Start dialog
    Intent dialog = new Intent();
    dialog.setClassName("com.inostudio.alarm_clock", "com.inostudio.alarm_clock.RootActivity");
    dialog.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startActivity(dialog);

    //release screen
    wl.release();
}
项目:AndroidModulePattern    文件:ScreenLockUtil.java   
/**
 * 取消锁屏限制
 *
 * @param activity you know
 */
private static void cancelLockScreen(Activity activity) {
    Boolean isUnlock = mIsUnlockArray.get(activity);
    if (isUnlock != null && isUnlock) {
        return;
    }
    KeyguardManager mKeyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock mKeyguardLock = mKeyguardManager.newKeyguardLock(activity.getClass().getName());
    mKeyguardLock.disableKeyguard();

    mIsUnlockArray.put(activity, true);
}
项目:BigApp_Discuz_Android    文件:LockerUtils.java   
public static void noSysLocker(Context context) {
    KeyguardManager keyguardManager = (KeyguardManager) context
            .getApplicationContext().getSystemService(
                    Context.KEYGUARD_SERVICE);
    KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome");
    keyguardLock.disableKeyguard();
}
项目:BigApp_Discuz_Android    文件:LockerUtils.java   
public static void haveSysLocker(Context context) {
    KeyguardManager keyguardManager = (KeyguardManager) context
            .getApplicationContext().getSystemService(
                    Context.KEYGUARD_SERVICE);
    KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome");
    keyguardLock.reenableKeyguard();
}
项目:LockScreen    文件:LockScreen.java   
public void enable()
{
        KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
        KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
        lock.disableKeyguard();
        startService(new Intent(this, LockScreenService.class));
        Toast.makeText(this.getBaseContext(),"Enabled",Toast.LENGTH_SHORT).show();
        Toast.makeText(this, "Please set LockScreen as default launcher", Toast.LENGTH_SHORT).show();
}
项目:AndroidRemoteSlideshow    文件:NookImageDisplayerActivity.java   
/**
 * Not used any more. This is replaced by {@link #initWindowFlags}.
 * */
@Deprecated
private void unlockScreen() {
    CustomLog.d("Trying to unlock screen...");
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
}
项目:nfcunlocker    文件:KeyguardUnlock.java   
private static KeyguardLock getKeyguardLock(Context context) {
    if (mKeyguardLock == null) {
        KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Activity.KEYGUARD_SERVICE);  

        mKeyguardLock = keyguardManager.newKeyguardLock("nfcunlocker");
    }

    return mKeyguardLock;
}
项目:BatteryBenchmark    文件:MainActivity.java   
public static KeyguardLock getMyLock() {
    return lock;
}
项目:AlarmClock-Android    文件:AccelerometerService.java   
@Override
public void onSensorChanged(SensorEvent evt) {
    if(evt.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
        //assign directions
        float x = evt.values[0];
        float y = evt.values[1];
        float z = evt.values[2];

        if(!initializated){
            prev_x = x;
            prev_y = y;
            prev_z = z;
            initializated = true;
        }else{
            //The calculation of the error
            float dx = Math.abs(prev_x - x);
            float dy = Math.abs(prev_y - y);
            float dz = Math.abs(prev_z - z);


            //if error < accuracy set value 0
            if(dx < accuracy) dx = 0;
            if(dy < accuracy) dy = 0;
            if(dz < accuracy) dz = 0;

            prev_x = x;
            prev_y = y;
            prev_z = z;

            if(dx > 0 || dy > 0 || dz > 0){
                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "com.inostudio.alar_clock");
                wl.acquire(30 * 1000);

                //unlock screen
                mKeyGuardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
                KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("com.inostudio.alar_clock");
                mLock.disableKeyguard();    

                //Start NightActivity
                Intent nightActivity = new Intent();
                nightActivity.setClassName("com.inostudio.alarm_clock", "com.inostudio.alarm_clock.RootActivity");
                nightActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
                startActivity(nightActivity);
            }
        }
    }
}