From 809667407c96310210d2ae1e86355f5506ca90ba Mon Sep 17 00:00:00 2001 From: Mindy Pereira Date: Tue, 1 Nov 2011 14:10:34 -0700 Subject: [PATCH] Create a require manual sync dialog. Fixes b/5533550 [Verizon Reported Issue]Add one-time notice to user when auto sync is disabled due to security policy Change-Id: I1d5380928429a829dbcb31d5f7309f9bc98e8dff --- res/values/strings.xml | 4 ++ src/com/android/email/Preferences.java | 50 +++++++++++++++++++ .../email/RequireManualSyncDialog.java | 40 +++++++++++++++ .../email/activity/UIControllerBase.java | 18 ++++++- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/com/android/email/RequireManualSyncDialog.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 95fa9367b..b83aea74b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1215,4 +1215,8 @@ as %s. looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong + + + Background sync for this account is disabled while\ + roaming. diff --git a/src/com/android/email/Preferences.java b/src/com/android/email/Preferences.java index 8e448bb90..f960797ae 100644 --- a/src/com/android/email/Preferences.java +++ b/src/com/android/email/Preferences.java @@ -50,6 +50,7 @@ public class Preferences { private static final String BACKGROUND_ATTACHMENTS = "backgroundAttachments"; private static final String TRUSTED_SENDERS = "trustedSenders"; private static final String LAST_ACCOUNT_USED = "lastAccountUsed"; + private static final String REQUIRE_MANUAL_SYNC_DIALOG_SHOWN = "requireManualSyncDialogShown"; public static final int AUTO_ADVANCE_NEWER = 0; public static final int AUTO_ADVANCE_OLDER = 1; @@ -287,6 +288,34 @@ public class Preferences { .apply(); } + /** + * Gets whether the require manual sync dialog has been shown for the specified account. + * It should only be shown once per account. + */ + public boolean getHasShownRequireManualSync(Context context, Account account) { + return getBoolean(context, account.getEmailAddress(), REQUIRE_MANUAL_SYNC_DIALOG_SHOWN, + false); + } + + /** + * Sets whether the require manual sync dialog has been shown for the specified account. + * It should only be shown once per account. + */ + public void setHasShownRequireManualSync(Context context, Account account, boolean value) { + setBoolean(context, account.getEmailAddress(), REQUIRE_MANUAL_SYNC_DIALOG_SHOWN, value); + } + + + /** + * Get whether to show the manual sync dialog. This dialog is shown when the user is roaming, + * connected to a mobile network, the administrator has set the RequireManualSyncWhenRoaming + * flag to true, and the dialog has not been shown before for the supplied account. + */ + public boolean shouldShowRequireManualSync(Context context, Account account) { + return Account.isAutomaticSyncDisabledByRoaming(context, account.mId) + && !getHasShownRequireManualSync(context, account); + } + public void clear() { mSharedPreferences.edit().clear().apply(); } @@ -298,4 +327,25 @@ public class Preferences { } } } + + /** + * Utility method for setting a boolean value on a per-account preference. + */ + private void setBoolean(Context context, String account, String key, Boolean value) { + mSharedPreferences.edit().putBoolean(makeKey(account, key), value).apply(); + } + + /** + * Utility method for getting a boolean value from a per-account preference. + */ + private boolean getBoolean(Context context, String account, String key, boolean def) { + return mSharedPreferences.getBoolean(makeKey(account, key), def); + } + + /** + * Utility method for creating a per account preference key. + */ + private String makeKey(String account, String key) { + return account != null ? account + "-" + key : key; + } } diff --git a/src/com/android/email/RequireManualSyncDialog.java b/src/com/android/email/RequireManualSyncDialog.java new file mode 100644 index 000000000..d1c60b9a2 --- /dev/null +++ b/src/com/android/email/RequireManualSyncDialog.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.email; + +import com.android.emailcommon.provider.Account; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.res.Resources; + +public class RequireManualSyncDialog extends AlertDialog implements OnClickListener { + + public RequireManualSyncDialog(Context context, Account account) { + super(context); + setMessage(context.getResources().getString(R.string.require_manual_sync_message)); + setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), this); + Preferences.getPreferences(context).setHasShownRequireManualSync(context, account, true); + } + + /** {@inheritDoc} */ + public void onClick(DialogInterface dialog, int which) { + // No-op. + } +} \ No newline at end of file diff --git a/src/com/android/email/activity/UIControllerBase.java b/src/com/android/email/activity/UIControllerBase.java index e353a27c2..15809acd2 100644 --- a/src/com/android/email/activity/UIControllerBase.java +++ b/src/com/android/email/activity/UIControllerBase.java @@ -32,6 +32,7 @@ import com.android.email.MessageListContext; import com.android.email.Preferences; import com.android.email.R; import com.android.email.RefreshManager; +import com.android.email.RequireManualSyncDialog; import com.android.email.activity.setup.AccountSettings; import com.android.email.activity.setup.MailboxSettings; import com.android.emailcommon.Logging; @@ -206,7 +207,9 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, if (mNfcHandler != null) { mNfcHandler.onAccountChanged(); // workaround for email not set on initial load } - Preferences.getPreferences(mActivity).setLastUsedAccountId(getUIAccountId()); + long accountId = getUIAccountId(); + Preferences.getPreferences(mActivity).setLastUsedAccountId(accountId); + showAccountSpecificWarning(accountId); } /** @@ -558,6 +561,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, mNfcHandler.onAccountChanged(); } Preferences.getPreferences(mActivity).setLastUsedAccountId(accountId); + showAccountSpecificWarning(accountId); } /** @@ -1017,6 +1021,18 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, } } + + private void showAccountSpecificWarning(long accountId) { + if (accountId != Account.NO_ACCOUNT && accountId != Account.NO_ACCOUNT) { + Account account = Account.restoreAccountWithId(mActivity, accountId); + if (account != null && + Preferences.getPreferences(mActivity) + .shouldShowRequireManualSync(mActivity, account)) { + new RequireManualSyncDialog(mActivity, account).show(); + } + } + } + @Override public String toString() { return getClass().getSimpleName(); // Shown on logcat