Home | History | Annotate | Download | only in email

Lines Matching refs:policy

46 import com.android.emailcommon.provider.Policy;
64 private Policy mAggregatePolicy;
76 * Get the security policy instance
103 * Compute the aggregate policy for all accounts that require it, and record it.
116 * @return a policy representing the strongest aggregate. If no policy sets are defined,
117 * a lightweight "nothing required" policy will be returned. Never null.
120 Policy computeAggregatePolicy() {
122 Policy aggregate = new Policy();
138 Cursor c = mContext.getContentResolver().query(Policy.CONTENT_URI,
139 Policy.CONTENT_PROJECTION, null, null, null);
140 Policy policy = new Policy();
143 policy.restore(c);
145 LogUtils.d(TAG, "Aggregate from: " + policy);
148 Math.max(policy.mPasswordMinLength, aggregate.mPasswordMinLength);
149 aggregate.mPasswordMode = Math.max(policy.mPasswordMode, aggregate.mPasswordMode);
150 if (policy.mPasswordMaxFails > 0) {
152 Math.min(policy.mPasswordMaxFails, aggregate.mPasswordMaxFails);
154 if (policy.mMaxScreenLockTime > 0) {
155 aggregate.mMaxScreenLockTime = Math.min(policy.mMaxScreenLockTime,
158 if (policy.mPasswordHistory > 0) {
160 Math.max(policy.mPasswordHistory, aggregate.mPasswordHistory);
162 if (policy.mPasswordExpirationDays > 0) {
164 Math.min(policy.mPasswordExpirationDays, aggregate.mPasswordExpirationDays);
166 if (policy.mPasswordComplexChars > 0) {
167 aggregate.mPasswordComplexChars = Math.max(policy.mPasswordComplexChars,
170 aggregate.mRequireRemoteWipe |= policy.mRequireRemoteWipe;
171 aggregate.mRequireEncryption |= policy.mRequireEncryption;
172 aggregate.mDontAllowCamera |= policy.mDontAllowCamera;
195 LogUtils.d(TAG, "Calculated Aggregate: no policy");
197 return Policy.NO_POLICY;
201 * Return updated aggregate policy, from cached value if possible
203 public synchronized Policy getAggregatePolicy() {
222 * clear the aggregate policy (so it can be recomputed) and set the policies in the DPM
232 * Typically used when deleting accounts, although we may use it for server-side policy
243 * API: Query used to determine if a given policy is "active" (the device is operating at
246 * @param policy the policies requested, or null to check aggregate stored policies
249 public boolean isActive(Policy policy) {
250 int reasons = getInactiveReasons(policy);
252 StringBuilder sb = new StringBuilder("isActive for " + policy + ": ");
275 * Return bits from isActive: Device Policy Manager has not been activated
300 * API: Query used to determine if a given policy is "active" (the device is operating at
315 * @param policy the policies requested, or null to check aggregate stored policies
319 public int getInactiveReasons(Policy policy) {
321 if (policy == null) {
322 policy = getAggregatePolicy();
325 if (policy == Policy.NO_POLICY) {
331 // check each policy explicitly
332 if (policy.mPasswordMinLength > 0) {
333 if (dpm.getPasswordMinimumLength(mAdminName) < policy.mPasswordMinLength) {
337 if (policy.mPasswordMode > 0) {
338 if (dpm.getPasswordQuality(mAdminName) < policy.getDPManagerPasswordQuality()) {
345 if (policy.mMaxScreenLockTime > 0) {
347 if (dpm.getMaximumTimeToLock(mAdminName) > policy.mMaxScreenLockTime * 1000) {
351 if (policy.mPasswordExpirationDays > 0) {
355 || currentTimeout > policy.getDPManagerPasswordExpirationTimeout()) {
366 if (policy.mPasswordHistory > 0) {
367 if (dpm.getPasswordHistoryLength(mAdminName) < policy.mPasswordHistory) {
372 if (policy.mPasswordComplexChars > 0) {
373 if (dpm.getPasswordMinimumNonLetter(mAdminName) < policy.mPasswordComplexChars) {
377 if (policy.mRequireEncryption) {
383 if (policy.mDontAllowCamera && !dpm.getCameraDisabled(mAdminName)) {
389 if (policy.mProtocolPoliciesUnsupported != null) {
408 Policy aggregatePolicy = getAggregatePolicy();
409 // if empty set, detach from policy manager
410 if (aggregatePolicy == Policy.NO_POLICY) {
419 // set each policy in the policy manager
435 // We always / safely clear minSymbols & minNumeric to zero (there is no policy
442 // If we are running in a managed policy, it is a securityException to even
503 Policy policy = Policy.restorePolicyWithId(mContext, account.mPolicyKey);
504 if (policy == null) return;
506 LogUtils.d(TAG, "policiesRequired for " + account.mDisplayName + ": " + policy);
515 if (policy.mProtocolPoliciesUnsupported == null) {
527 * Set the policy for an account atomically; this also removes any other policy associated with
528 * the account and sets the policy key for the account. If policy is null, the policyKey is
532 * @param account the account whose policy is to be set
533 * @param policy the policy to set, or null if we're clearing the policy
534 * @param securitySyncKey the security sync key for this account (ignored if policy is null)
536 public static void setAccountPolicy(Context context, Account account, Policy policy,
540 // Make sure this is a valid policy set
541 if (policy != null) {
542 policy.normalize();
543 // Add the new policy (no account will yet reference this)
545 Policy.CONTENT_URI).withValues(policy.toContentValues()).build());
546 // Make the policyKey of the account our newly created policy, and set the sync key
560 // Delete the previous policy associated with this account, if any
564 Policy.CONTENT_URI, account.mPolicyKey)).build());
573 throw new IllegalStateException("Exception setting account policy.");
597 public void setAccountPolicy(long accountId, Policy policy, String securityKey,
604 Policy oldPolicy = null;
606 oldPolicy = Policy.restorePolicyWithId(mContext, account.mPolicyKey);
611 if ((oldPolicy.mDontAllowAttachments != policy.mDontAllowAttachments) ||
612 (oldPolicy.mMaxAttachmentSize != policy.mMaxAttachmentSize)) {
613 Policy.setAttachmentFlagsForNewPolicy(mContext, account, policy);
617 boolean policyChanged = (oldPolicy == null) || !oldPolicy.equals(policy);
620 LogUtils.d(Logging.LOG_TAG, "setAccountPolicy; policy unchanged");
622 setAccountPolicy(mContext, account, policy, securityKey);
629 if (policy.mProtocolPoliciesUnsupported != null) {
640 } else if (isActive(policy)) {
649 LogUtils.d(Logging.LOG_TAG, "Policy is active and unchanged; do not notify.");
705 * Report admin component name - for making calls into device policy manager
793 long policyId = Utility.getFirstRowLong(context, Policy.CONTENT_URI, Policy.ID_PROJECTION,
797 return Policy.getAccountIdWithPolicyKey(context, policyId);
809 Cursor c = context.getContentResolver().query(Policy.CONTENT_URI,
810 Policy.ID_PROJECTION, HAS_PASSWORD_EXPIRATION, null, null);
816 long policyId = c.getLong(Policy.ID_PROJECTION_COLUMN);
817 long accountId = Policy.getAccountIdWithPolicyKey(context, policyId);
867 * Device Policy administrator. This is primarily a listener for device state changes.