am 47288061: am 416f9210: am 13666c7f: am 8209d6c0: Display a warning if account is on security hold

* commit '472880614e9d72916b18a3840df119a43ca667e7':
  Display a warning if account is on security hold
This commit is contained in:
Martin Hibdon 2014-11-02 18:52:29 +00:00 committed by Android Git Automerger
commit 0df19789c9
2 changed files with 58 additions and 9 deletions

View File

@ -28,16 +28,20 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import com.android.email.DebugUtils;
import com.android.email.R;
import com.android.email.SecurityPolicy;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.provider.Policy;
import com.android.emailcommon.utility.IntentUtilities;
import com.android.mail.ui.MailAsyncTaskLoader;
import com.android.mail.utils.LogUtils;
@ -87,6 +91,14 @@ public class AccountSecurity extends Activity {
private AccountAndPolicyLoaderCallbacks mAPLoaderCallbacks;
private Bundle mAPLoaderArgs;
public static Uri getUpdateSecurityUri(final long accountId, final boolean showDialog) {
final Uri.Builder baseUri = Uri.parse("auth://" + EmailContent.EMAIL_PACKAGE_NAME +
".ACCOUNT_SECURITY/").buildUpon();
IntentUtilities.setAccountId(baseUri, accountId);
baseUri.appendQueryParameter(EXTRA_SHOW_DIALOG, Boolean.toString(showDialog));
return baseUri.build();
}
/**
* Used for generating intent for this activity (which is intended to be launched
* from a notification.)
@ -126,7 +138,25 @@ public class AccountSecurity extends Activity {
mHandler = new Handler();
final Intent i = getIntent();
final long accountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
final long accountId;
Bundle extras = i.getExtras();
if (extras == null) {
// We have been invoked via a uri. We need to get our parameters from the URI instead
// of looking in the intent extras.
extras = new Bundle();
accountId = IntentUtilities.getAccountIdFromIntent(i);
extras.putLong(EXTRA_ACCOUNT_ID, accountId);
boolean showDialog = false;
final String value = i.getData().getQueryParameter(EXTRA_SHOW_DIALOG);
if (!TextUtils.isEmpty(value)) {
showDialog = Boolean.getBoolean(value);
}
extras.putBoolean(EXTRA_SHOW_DIALOG, showDialog);
} else {
accountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
extras = i.getExtras();
}
final SecurityPolicy security = SecurityPolicy.getInstance(this);
security.clearNotification();
if (accountId == -1) {
@ -148,7 +178,7 @@ public class AccountSecurity extends Activity {
}
if (!mInitialized) {
startAccountAndPolicyLoader(i.getExtras());
startAccountAndPolicyLoader(extras);
}
}

View File

@ -67,6 +67,7 @@ import com.android.email.DebugUtils;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.SecurityPolicy;
import com.android.email.activity.setup.AccountSecurity;
import com.android.email.activity.setup.AccountSettingsFragment;
import com.android.email.activity.setup.AccountSettingsUtils;
import com.android.email.activity.setup.HeadlessAccountSettingsLoader;
@ -3332,10 +3333,8 @@ public class EmailProvider extends ContentProvider
return sb.toString();
}
private static int getCapabilities(Context context, long accountId) {
final Account account = Account.restoreAccountWithId(context, accountId);
private static int getCapabilities(Context context, final Account account) {
if (account == null) {
LogUtils.d(TAG, "Account %d not found during getCapabilities", accountId);
return 0;
}
// Account capabilities are based on protocol -- different protocols (and, for EAS,
@ -3376,10 +3375,10 @@ public class EmailProvider extends ContentProvider
AccountCapabilities.DISCARD_CONVERSATION_DRAFTS;
}
} else {
LogUtils.w(TAG, "Unknown protocol for account %d", accountId);
LogUtils.w(TAG, "Unknown protocol for account %d", account.getId());
return 0;
}
LogUtils.d(TAG, "getCapabilities() for %d (protocol %s): 0x%x %s", accountId, protocol,
LogUtils.d(TAG, "getCapabilities() for %d (protocol %s): 0x%x %s", account.getId(), protocol,
capabilities, getBits(capabilities));
// If the configuration states that feedback is supported, add that capability
@ -3421,9 +3420,14 @@ public class EmailProvider extends ContentProvider
// TODO: If uiProjection is null, this will NPE. We should do everything here if it's null.
final Set<String> projectionColumns = ImmutableSet.copyOf(uiProjection);
final Account account = Account.restoreAccountWithId(context, accountId);
if (account == null) {
LogUtils.d(TAG, "Account %d not found during genQueryAccount", accountId);
}
if (projectionColumns.contains(UIProvider.AccountColumns.CAPABILITIES)) {
// Get account capabilities from the service
values.put(UIProvider.AccountColumns.CAPABILITIES, getCapabilities(context, accountId));
values.put(UIProvider.AccountColumns.CAPABILITIES,
(account == null ? 0 : getCapabilities(context, account)));
}
if (projectionColumns.contains(UIProvider.AccountColumns.SETTINGS_INTENT_URI)) {
values.put(UIProvider.AccountColumns.SETTINGS_INTENT_URI,
@ -3502,6 +3506,16 @@ public class EmailProvider extends ContentProvider
// Email is now sanitized, which grants the ability to inject beautifying javascript.
values.put(UIProvider.AccountColumns.ENABLE_MESSAGE_TRANSFORMS, 1);
}
if (projectionColumns.contains(UIProvider.AccountColumns.SECURITY_HOLD)) {
final int hold = ((account != null &&
((account.getFlags() & Account.FLAGS_SECURITY_HOLD) == 0)) ? 0 : 1);
values.put(UIProvider.AccountColumns.SECURITY_HOLD, hold);
}
if (projectionColumns.contains(UIProvider.AccountColumns.ACCOUNT_SECURITY_URI)) {
values.put(UIProvider.AccountColumns.ACCOUNT_SECURITY_URI,
(account == null ? "" : AccountSecurity.getUpdateSecurityUri(
account.getId(), true).toString()));
}
if (projectionColumns.contains(
UIProvider.AccountColumns.SettingsColumns.IMPORTANCE_MARKERS_ENABLED)) {
// Email doesn't support priority inbox, so always state importance markers disabled.
@ -3631,7 +3645,6 @@ public class EmailProvider extends ContentProvider
final Map<String, Integer> colPosMap = builder.build();
final MailPrefs mailPrefs = MailPrefs.get(getContext());
final Object[] values = new Object[columnNames.length];
if (colPosMap.containsKey(BaseColumns._ID)) {
values[colPosMap.get(BaseColumns._ID)] = 0;
@ -3670,6 +3683,12 @@ public class EmailProvider extends ContentProvider
values[colPosMap.get(UIProvider.AccountColumns.MIME_TYPE)] =
EMAIL_APP_MIME_TYPE;
}
if (colPosMap.containsKey(UIProvider.AccountColumns.SECURITY_HOLD)) {
values[colPosMap.get(UIProvider.AccountColumns.SECURITY_HOLD)] = 0;
}
if (colPosMap.containsKey(UIProvider.AccountColumns.ACCOUNT_SECURITY_URI)) {
values[colPosMap.get(UIProvider.AccountColumns.ACCOUNT_SECURITY_URI)] = "";
}
if (colPosMap.containsKey(UIProvider.AccountColumns.SETTINGS_INTENT_URI)) {
values[colPosMap.get(UIProvider.AccountColumns.SETTINGS_INTENT_URI)] =
getExternalUriString("settings", COMBINED_ACCOUNT_ID_STRING);