Search in sources :

Example 41 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Aegis by Decad3nce.

the class Utils method lockDeviceDefault.

protected static void lockDeviceDefault(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String password = preferences.getString(SMSLockFragment.PREFERENCES_LOCK_PASSWORD, context.getResources().getString(R.string.config_default_lock_password));
    if (password.length() > 0) {
        devicePolicyManager.resetPassword(password, 0);
    }
    devicePolicyManager.lockNow();
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) SharedPreferences(android.content.SharedPreferences)

Example 42 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Aegis by Decad3nce.

the class AdvancedSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.advanced_preferences);
    final Preference removeAdmin = findPreference("remove_admin");
    final Preference installToSystem = findPreference("install_to_system");
    final DevicePolicyManager mDPM = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (mDPM.getActiveAdmins() == null || !mDPM.isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT)) {
        PreferenceCategory mCategory = (PreferenceCategory) findPreference("advanced_category");
        mCategory.removePreference(removeAdmin);
    }
    Preference.OnPreferenceClickListener preferenceListener = (new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (preference.getKey().equals(ADVANCED_PREFERENCES_REMOVE_ADMIN)) {
                if (mDPM.isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT)) {
                    removeAdmin(mDPM, removeAdmin);
                }
            }
            if (preference.getKey().equals(ADVANCED_PREFERENCES_INSTALL_TO_SYSTEM)) {
                DialogFragment dialog = new InstallToSystemDialogFragment();
                dialog.show(getActivity().getFragmentManager(), "InstallToSystemDialogFragment");
            }
            return false;
        }
    });
    removeAdmin.setOnPreferenceClickListener(preferenceListener);
    installToSystem.setOnPreferenceClickListener(preferenceListener);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) DialogFragment(android.app.DialogFragment)

Example 43 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class LockPatternUtils method saveLockPassword.

/**
     * Save a lock password.  Does not ensure that the password is as good
     * as the requested mode, but will adjust the mode to be as good as the
     * password.
     * @param password The password to save
     * @param savedPassword The previously saved lock password, or null if none
     * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
     * @param userHandle The userId of the user to change the password for
     */
public void saveLockPassword(String password, String savedPassword, int quality, int userHandle) {
    try {
        DevicePolicyManager dpm = getDevicePolicyManager();
        if (password == null || password.length() < MIN_LOCK_PASSWORD_SIZE) {
            throw new IllegalArgumentException("password must not be null and at least " + "of length " + MIN_LOCK_PASSWORD_SIZE);
        }
        final int computedQuality = computePasswordQuality(password);
        setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
        getLockSettings().setLockPassword(password, savedPassword, userHandle);
        // Update the device encryption password.
        if (userHandle == UserHandle.USER_SYSTEM && LockPatternUtils.isDeviceEncryptionEnabled()) {
            if (!shouldEncryptWithCredentials(true)) {
                clearEncryptionPassword();
            } else {
                boolean numeric = computedQuality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
                boolean numericComplex = computedQuality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
                int type = numeric || numericComplex ? StorageManager.CRYPT_TYPE_PIN : StorageManager.CRYPT_TYPE_PASSWORD;
                updateEncryptionPassword(type, password);
            }
        }
        // Add the password to the password history. We assume all
        // password hashes have the same length for simplicity of implementation.
        String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
        if (passwordHistory == null) {
            passwordHistory = "";
        }
        int passwordHistoryLength = getRequestedPasswordHistoryLength(userHandle);
        if (passwordHistoryLength == 0) {
            passwordHistory = "";
        } else {
            byte[] hash = passwordToHash(password, userHandle);
            passwordHistory = new String(hash, StandardCharsets.UTF_8) + "," + passwordHistory;
            // Cut it to contain passwordHistoryLength hashes
            // and passwordHistoryLength -1 commas.
            passwordHistory = passwordHistory.substring(0, Math.min(hash.length * passwordHistoryLength + passwordHistoryLength - 1, passwordHistory.length()));
        }
        setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
        onAfterChangingPassword(userHandle);
    } catch (RemoteException re) {
        // Cant do much
        Log.e(TAG, "Unable to save lock password " + re);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) RemoteException(android.os.RemoteException)

Example 44 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class KeyguardUpdateMonitor method scheduleStrongAuthTimeout.

private void scheduleStrongAuthTimeout() {
    final DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    long when = SystemClock.elapsedRealtime() + dpm.getRequiredStrongAuthTimeout(null, sCurrentUser);
    Intent intent = new Intent(ACTION_STRONG_AUTH_TIMEOUT);
    intent.putExtra(USER_ID, sCurrentUser);
    PendingIntent sender = PendingIntent.getBroadcast(mContext, sCurrentUser, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, when, sender);
    notifyStrongAuthStateChanged(sCurrentUser);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 45 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class HardwarePropertiesManagerService method enforceHardwarePropertiesRetrievalAllowed.

/**
     * Throws SecurityException if the calling package is not allowed to retrieve information
     * provided by the service.
     *
     * @param callingPackage The calling package name.
     *
     * @throws SecurityException if something other than the profile or device owner, the
     *        current VR service, or a caller holding the {@link Manifest.permission#DEVICE_POWER}
     *        permission tries to retrieve information provided by this service.
     */
private void enforceHardwarePropertiesRetrievalAllowed(String callingPackage) throws SecurityException {
    final PackageManager pm = mContext.getPackageManager();
    int uid = 0;
    try {
        uid = pm.getPackageUid(callingPackage, 0);
        if (Binder.getCallingUid() != uid) {
            throw new SecurityException("The caller has faked the package name.");
        }
    } catch (PackageManager.NameNotFoundException e) {
        throw new SecurityException("The caller has faked the package name.");
    }
    final int userId = UserHandle.getUserId(uid);
    final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
    final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
    if (!dpm.isDeviceOwnerApp(callingPackage) && !dpm.isProfileOwnerApp(callingPackage) && !vrService.isCurrentVrListener(callingPackage, userId) && mContext.checkCallingOrSelfPermission(Manifest.permission.DEVICE_POWER) != PackageManager.PERMISSION_GRANTED) {
        throw new SecurityException("The caller is not a device or profile owner, bound " + "VrListenerService, or holding the DEVICE_POWER permission.");
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PackageManager(android.content.pm.PackageManager) VrManagerInternal(com.android.server.vr.VrManagerInternal)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)159 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4