Ejemplo n.º 1
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (!initiated) {
      IntentFilter filter = new IntentFilter();
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      filter.addAction(Intent.ACTION_SCREEN_ON);
      filter.setPriority(1000);
      registerReceiver(new LockscreenManager(), filter);

      IntentFilter filter2 = new IntentFilter();
      filter2.addAction(Intent.ACTION_SCREEN_OFF);
      filter2.setPriority(1000);
      registerReceiver(new UnlocktimeReceiver(), filter2);

      IntentFilter filter3 = new IntentFilter();
      filter3.addAction(Intent.ACTION_SCREEN_ON);
      filter3.setPriority(1000);
      registerReceiver(new ExpositionUnlockReceiver(), filter3);

      // todo refactor this method is depricated
      KeyguardManager keyguardManager =
          (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
      KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
      lock.disableKeyguard();

      initiated = true;
    }

    //        stopSelf();

    return Service.START_STICKY;
  }
Ejemplo n.º 2
0
 @SuppressWarnings("deprecation")
 private void enableKeyguard(boolean enabled) {
   if (mKeyguardLock == null) {
     KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
     mKeyguardLock = km.newKeyguardLock(LOG_TAG);
   }
   if (enabled) {
     mKeyguardLock.reenableKeyguard();
   } else {
     mKeyguardLock.disableKeyguard();
   }
 }
  /**
   * Called by the Android runtime to clean up the {@code Instrumentation}. This implementation
   * releases the locks obtained in {@code onStart} and stops the Jetty server.
   */
  @Override
  public void onDestroy() {
    if (wakeLock != null) {
      wakeLock.release();
      wakeLock = null;
    }

    if (keyguardLock != null) {
      keyguardLock.reenableKeyguard();
      keyguardLock = null;
    }

    if (server != null) {
      try {
        callServerStop();
      } catch (Exception exception) {
        Log.e(LOG_TAG, "Exception when stopping Jetty.", exception);
      }

      Log.i(LOG_TAG, "Jetty stopped");

      server = null;
    } else {
      Log.i(LOG_TAG, "In onDestroy(), but Jetty is not running");
    }

    instance = null;
  }
  /**
   * Attempts to acquire the keyguard lock.
   *
   * @return a reference to the keyguard lock, or {@code null} if the keyguard lock could not be
   *     obtained
   * @see #onStart
   */
  @Nullable
  protected KeyguardManager.KeyguardLock tryToAcquireKeyguardLock() {
    KeyguardManager keyguardManager =
        (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock acquiredLock = keyguardManager.newKeyguardLock(LOG_TAG);

    try {
      acquiredLock.disableKeyguard();
    } catch (SecurityException exception) {
      Log.w(
          LOG_TAG,
          "Could not disable the keyguard for testing; it must be " + "disabled manually.",
          exception);
      acquiredLock = null;
    }

    return acquiredLock;
  }
Ejemplo n.º 5
0
 void reenableKeyguard() {
   if (!enabled) {
     try {
       if (Integer.parseInt(Build.VERSION.SDK) < 5) Thread.sleep(1000);
     } catch (InterruptedException e) {
     }
     mKeyguardLock.reenableKeyguard();
     enabled = true;
   }
 }
Ejemplo n.º 6
0
  @Override
  @SuppressWarnings("deprecation")
  public void onCreate() {
    KeyguardManager.KeyguardLock key;
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

    // This is deprecated, but it is a simple way to disable the lockscreen in code
    key = km.newKeyguardLock("IN");

    key.disableKeyguard();

    // Start listening for the Screen On, Screen Off, and Boot completed actions
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);

    // Set up a receiver to listen for the Intents in this Service
    receiver = new LockScreenReceiver();
    registerReceiver(receiver, filter);

    super.onCreate();
  }
Ejemplo n.º 7
0
  @SuppressWarnings({"deprecation", "unused"})
  @Override
  public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)
        || intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {

      Intent lockIntent = new Intent(context, LockScreenActivity.class);

      keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
      keyguardLock = keyguardManager.newKeyguardLock("");
      keyguardLock.disableKeyguard(); //
      //
      //			context.startActivity(lockIntent); //
    }
  }
Ejemplo n.º 8
0
 void disableKeyguard() {
   if (mKeyguardManager == null) {
     mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
     mKeyguardLock = mKeyguardManager.newKeyguardLock("Sipdroid");
     enabled = true;
   }
   if (enabled) {
     mKeyguardLock.disableKeyguard();
     if (Integer.parseInt(Build.VERSION.SDK) == 16 && Build.MODEL.contains("HTC One"))
       mKeyguardManager.exitKeyguardSecurely(
           new OnKeyguardExitResult() {
             public void onKeyguardExitResult(boolean success) {}
           });
     enabled = false;
     enabletime = SystemClock.elapsedRealtime();
   }
 }
Ejemplo n.º 9
0
 @Override
 public void unlock() {
   manageKeyguard = true;
   keyguardLock.disableKeyguard();
 }
Ejemplo n.º 10
0
 @Override
 public void lock() {
   if (manageKeyguard) {
     keyguardLock.reenableKeyguard();
   }
 }
Ejemplo n.º 11
0
 public void release() {
   if (keyguardLock != null) {
     // 禁用显示键盘锁定
     keyguardLock.reenableKeyguard();
   }
 }
Ejemplo n.º 12
0
 public void reenableKeyguard() {
   keyguardLock.reenableKeyguard();
 }
Ejemplo n.º 13
0
 public void disableKeyguard() {
   keyguardLock.disableKeyguard();
 }
Ejemplo n.º 14
0
 /**
  * Re-enables the keyguard after a previous disableKeyguard() call.
  *
  * <p>Any call to this method MUST correspond to (i.e. be balanced with) a previous
  * disableKeyguard() call.
  */
 /* package */ void reenableKeyguard() {
   if (DBG) Log.d(LOG_TAG, "re-enable keyguard");
   // if (DBG) Log.d(LOG_TAG, "reenableKeyguard()...", new Throwable("stack dump"));
   mKeyguardLock.reenableKeyguard();
 }