Support email lookback policy

* Requires related CL in Email app

Bug: 5792217
Change-Id: I007a022bfec4871ecfde76779e24d26246b651bc
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 804c926..1716e35 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -155,12 +155,6 @@
     <string name="policy_app_blacklist">Disallow specified apps</string>
     <!-- A policy in which the device allows only specified applications [CHAR LIMIT=50] -->
     <string name="policy_app_whitelist">Allow only specified apps</string>
-    <!-- A policy in which the device allows only calendar items newer than a specified date
-        [CHAR LIMIT=50] -->
-    <string name="policy_max_calendar_age">Restrict calendar event dates</string>
-    <!-- A policy in which the device allows only email items newer than a specified date
-        [CHAR LIMIT=50] -->
-    <string name="policy_max_email_age">Restrict email dates</string>
     <!-- A policy in which the device limits the amount of text that can be displayed for a
         given message [CHAR LIMIT=50] -->
     <string name="policy_text_truncation">Restrict text email size</string>
diff --git a/src/com/android/exchange/adapter/EmailSyncAdapter.java b/src/com/android/exchange/adapter/EmailSyncAdapter.java
index 6c9d585..9552960 100644
--- a/src/com/android/exchange/adapter/EmailSyncAdapter.java
+++ b/src/com/android/exchange/adapter/EmailSyncAdapter.java
@@ -316,6 +316,17 @@
             lookback = SyncWindow.SYNC_WINDOW_1_MONTH;
         }
 
+        // Limit lookback to policy limit
+        if (mAccount.mPolicyKey > 0) {
+            Policy policy = Policy.restorePolicyWithId(mContext, mAccount.mPolicyKey);
+            if (policy != null) {
+                int maxLookback = policy.mMaxEmailLookback;
+                if (maxLookback != 0 && (lookback > policy.mMaxEmailLookback)) {
+                    lookback = policy.mMaxEmailLookback;
+                }
+            }
+        }
+
         // Store the new lookback and persist it
         // TODO Code similar to this is used elsewhere (e.g. MailboxSettings); try to clean this up
         ContentValues cv = new ContentValues();
diff --git a/src/com/android/exchange/adapter/ProvisionParser.java b/src/com/android/exchange/adapter/ProvisionParser.java
index 51d2f8c..a9085bd 100644
--- a/src/com/android/exchange/adapter/ProvisionParser.java
+++ b/src/com/android/exchange/adapter/ProvisionParser.java
@@ -292,15 +292,9 @@
                 case Tags.PROVISION_MAX_CALENDAR_AGE_FILTER:
                     policy.mMaxCalendarLookback = getValueInt();
                     break;
-                // We currently reject max email age filter (unless it's 0, i.e. none specified)
+                // We handle max email lookback
                 case Tags.PROVISION_MAX_EMAIL_AGE_FILTER:
-                    max = getValueInt();
-                    policy.mMaxEmailLookback = max;
-                    // 0 indicates no specified filter
-                    if (max != 0) {
-                        unsupportedList.add(R.string.policy_max_email_age);
-                        tagIsSupported = false;
-                    }
+                    policy.mMaxEmailLookback = getValueInt();
                     break;
                 // We currently reject these next two policies
                 case Tags.PROVISION_MAX_EMAIL_BODY_TRUNCATION_SIZE: