示例#1
0
  private void onLock() {
    boolean active = manger.isAdminActive(componentName);
    if (active) {
      manger.lockNow();

    } else {
      Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
      intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
      startActivityForResult(intent, 0);
      manger.lockNow();
    }
  }
 /**
  * 锁定屏幕
  *
  * @return
  */
 public boolean lockScreen(Context context) {
   if (isActive()) {
     String password = SafeSharedpreference.getString(context, ConstConfig.LOCKSCREEN_PWD);
     policyManager.lockNow();
     if (!password.equals("")) {
       policyManager.resetPassword(password, 0);
     }
     return true;
   }
   return false;
 }
示例#3
0
 public void onClick(View v) {
   // TODO Auto-generated method stub
   devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
   if (devicePolicyManager.isAdminActive(Dar.getCn(this))) {
     devicePolicyManager.lockNow();
   } else {
     Intent intent = new Intent("android.intent.action.oneKeyLock");
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
   }
 }
示例#4
0
  /**
   * Clear device password.
   *
   * @param code - Operation code.
   * @param requestMode - Request mode(Normal mode or policy bundle mode).
   */
  public void clearPassword(String code) {
    ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
    resultBuilder.build(code);

    devicePolicyManager.setPasswordQuality(
        demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
    devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_LENGTH);
    devicePolicyManager.resetPassword(
        resources.getString(R.string.shared_pref_default_string),
        DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
    devicePolicyManager.lockNow();
    devicePolicyManager.setPasswordQuality(
        demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
  }
示例#5
0
 public void onClick(View v) {
   if (mAM.isUserAMonkey()) {
     // Don't trust monkeys to do the right thing!
     AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
     builder.setMessage("You can't lock my screen because you are a monkey!");
     builder.setPositiveButton("I admit defeat", null);
     builder.show();
     return;
   }
   boolean active = mDPM.isAdminActive(mDeviceAdminSample);
   if (active) {
     mDPM.lockNow();
   }
 }
示例#6
0
  /**
   * Change device lock code.
   *
   * @param code - Operation code.
   * @param data - Data required(Lock code).
   */
  public void changeLockCode(String code, String data) {
    ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
    devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_MIN_LENGTH);
    String password = null;

    try {
      JSONObject lockData = new JSONObject(data);
      if (!lockData.isNull(resources.getString(R.string.intent_extra_password))) {
        password = (String) lockData.get(resources.getString(R.string.intent_extra_password));
      }

      resultBuilder.build(code);

      if (password != null && !password.isEmpty()) {
        devicePolicyManager.resetPassword(
            password, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
        devicePolicyManager.lockNow();
      }
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
示例#7
0
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 private void enableHardLock() {
   String message = context.getResources().getString(R.string.txt_lock_activity);
   if (appUri != null && !appUri.isEmpty()) {
     message = appUri;
   }
   if (SettingsManager.isDeviceOwner()) {
     devicePolicyManager.setLockTaskPackages(cdmDeviceAdmin, AUTHORIZED_PINNING_APPS);
     Intent intent = new Intent(context, LockActivity.class);
     intent.setFlags(
         Intent.FLAG_ACTIVITY_CLEAR_TASK
             | Intent.FLAG_ACTIVITY_CLEAR_TOP
             | Intent.FLAG_ACTIVITY_NEW_TASK
             | Intent.FLAG_ACTIVITY_NO_HISTORY
             | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
     intent.putExtra(Constants.ADMIN_MESSAGE, message);
     intent.putExtra(Constants.IS_LOCKED, true);
     context.startActivity(intent);
   } else {
     Log.e(TAG, "Device owner is not set, hence executing default lock");
     devicePolicyManager.lockNow();
   }
 }
示例#8
0
 /**
  * Ring the device.
  *
  * @param code - Operation code.
  */
 public void ringDevice(String code) {
   resultBuilder.build(code);
   devicePolicyManager.lockNow();
 }