Android DevicePolicyManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DevicePolicyManager class.

This code example shows how to use the following methods:isAdminActive, lockNow, resetPassword
 
	 
	public void changePasswordAndLock(String newPass, boolean lock){
	    try { 
			if (isAdminActive()) { 
				policyManager.resetPassword(newPass,DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
				if (lock)
					policyManager.lockNow();
			} 
		} catch (Exception e) {
			PreyLogger.e("This device couldn't be locked. Honeycomb bug?", e);
		} 
	} 
	 
	public void lockNow(){ 
	    if (isAdminActive()) 
	    	policyManager.lockNow();
	} 
	 
	public boolean isAdminActive(){ 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPasswordMinimumLength, setPasswordMinimumUpperCase, setPasswordQuality
 
    /** 
     * Configure policy defined in the object. 
     */ 
    public void configurePolicy() { 
        mDPM.setPasswordQuality(mPolicyAdmin, PASSWORD_QUALITY_VALUES[mPasswordQuality]);
        mDPM.setPasswordMinimumLength(mPolicyAdmin, mPasswordLength);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDPM.setPasswordMinimumUpperCase(mPolicyAdmin, mPasswordMinUpperCase);
        } 
    } 
 
    /** 
     * Through the PolicyAdmin receiver, the app can use this to trap various device 
     * administration events, such as password change, incorrect password entry, etc. 
     * 
     */ 
    public static class PolicyAdmin extends DeviceAdminReceiver {
 
        @Override 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPasswordExpirationTimeout, getPasswordHistoryLength, getPasswordMinimumLetters, getPasswordMinimumLowerCase, getPasswordMinimumNonLetter
		dsi.setAutoTimeZone(autotimezone);
	} 
	 
	void password(PasswordItem pi, DevicePolicyManager dpm) {
		EntityItemIntType ei3 = EntityItemIntType.Factory.newInstance();
		ei3.setStringValue(Integer.valueOf(dpm.getPasswordHistoryLength(null))
				.toString());
		ei3.setDatatype("int");
		pi.setPasswordHist(ei3); // API Level 11
 
		 
		// Only applies if password quality is PASSWORD_QUALITY_COMPLEX 
		EntityItemIntType ei5 = EntityItemIntType.Factory.newInstance();
		ei5.setStringValue(Integer.valueOf(dpm.getPasswordMinimumLetters(null))
				.toString());
		ei5.setDatatype("int");
		pi.setPasswordMinLetters(ei5); // API Level 11
 
		// Only applies if password quality is PASSWORD_QUALITY_COMPLEX 
		EntityItemIntType ei6 = EntityItemIntType.Factory.newInstance();

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isAdminActive
  public void onResume() { 
    super.onResume(); 
 
    CheckBoxPreference pref=(CheckBoxPreference)findPreference(KEY_ENABLED);
     
    pref.setChecked(mgr.isAdminActive(cn));
    pref.setOnPreferenceChangeListener(this);
  } 
 
  @Override 
  public boolean onPreferenceChange(Preference pref, Object newValue) {
    if (KEY_ENABLED.equals(pref.getKey())) {
      boolean value=((Boolean)newValue).booleanValue();
 
      if (value) {
        Intent intent=
            new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        getString(R.string.device_admin_explanation));
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isAdminActive, setMaximumFailedPasswordsForWipe, setPasswordMinimumLength, setPasswordQuality
This code example shows how to use the following methods:isAdminActive, setMaximumTimeToLock
                    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) { 
                    long timeMs = 1000L*Long.parseLong(mTimeout.getText().toString()); 
                    mDPM.setMaximumTimeToLock(mDeviceAdminSample, timeMs); 
                } 
            } 
        }; 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getStorageEncryptionStatus
            isFileSystemEncrypted = false;
        } else { 
            DevicePolicyManager devicePolicyManager = (DevicePolicyManager) ctx.getSystemService(Service.DEVICE_POLICY_SERVICE);
 
            // Note: Following method only exists if linking to an android.jar api 11 and above. 
            isFileSystemEncrypted = devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
        } 
 
        // Make sure the cryptographic transformations we want to use are available. 
        bestCipherAvailable = null;
        try { 
            getBestCipher(); 
        } catch (GeneralSecurityException gex) {
        } 
        if (null == bestCipherAvailable) {
            return false; 
        } 
        try { 
            Mac.getInstance(MAC_TRANSFORMATION, "BC");
        } catch (GeneralSecurityException e) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isAdminActive, lockNow, resetPassword
	 
	public static void lockIfEnabled(Context context, boolean forceLock) {
		if(!Locker.isWatchConnected(context)) {		
			DevicePolicyManager dpm = ((DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE));
			 
			if (dpm.isAdminActive(new ComponentName(context, CustomDeviceAdminReceiver.class))) {
				SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
				 
				if(prefs.getBoolean("key_enable_locker", false)) {			
					dpm.resetPassword(prefs.getString("key_password", ""), DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
					 
					if(forceLock && prefs.getBoolean("key_force_lock", false))
						dpm.lockNow();
				} 
			} 
		} 
	} 
	 
	public static void unlockIfEnabled(Context context) {
		if(PreferenceManager.getDefaultSharedPreferences(context).getBoolean("key_enable_locker", false)) {		
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isAdminActive, lockNow
	} 
 
	@SuppressLint("NewApi") 
  public boolean onPreferenceChange(Preference preference, Object newValue) {
		boolean isAdmin = false;
		if (!mDPM.isAdminActive(mAdminName)) {
			// try to become active – must happen here in this activity, to get result 
			Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
			intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
			intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
					"Administration isn't activated."); 
			startActivityForResult(intent, REQUEST_ENABLE);
		} else { 
			// Already is a device administrator, can do security operations now. 
			mDPM.lockNow();
			isAdmin = true;
		} 
		return isAdmin;
	} 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isAdminActive, lockNow, resetPassword
 
	private void lockDevice() { 
		DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
		ComponentName mDeviceAdmin = new ComponentName(this,
				AdminReceiver.class); 
		if (!mDPM.isAdminActive(mDeviceAdmin)) {
			// request admin 
			Intent intent = new Intent(
					DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
			intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
					mDeviceAdmin);
			intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
					"Make me admin now!"); 
			startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
		} else { 
			mDPM.resetPassword("test", 0);
			mDPM.lockNow();
		} 
	} 
 

6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android DevicePolicyManager Questions & Answers:

Other Android DevicePolicyManager Examples

1:	DevicePolicyManager mDPM = (DevicePolicyManager)
2:	        context.getSystemService(Context.DEVICE_POLICY_SERVICE);
3:	ComponentName mPolicyAdmin = new ComponentName(context, PolicyAdmin.class);
-
1:	DevicePolicyManager mDPM = (DevicePolicyManager)
2:	        context.getSystemService(Context.DEVICE_POLICY_SERVICE);
3:	ComponentName mPolicyAdmin = new ComponentName(context, PolicyAdmin.class);

Read More

See Code Examples for Android DevicePolicyManager Methods: