Merge "Move isSecurityHold/clearAccountHoldFlags to Account"

This commit is contained in:
Makoto Onuki 2010-07-28 13:44:42 -07:00 committed by Android (Google) Code Review
commit 4de80f22ae
10 changed files with 327 additions and 184 deletions

View File

@ -62,19 +62,6 @@ public class SecurityPolicy {
AccountColumns.ID, AccountColumns.SECURITY_FLAGS
};
private static final int ACCOUNT_SECURITY_COLUMN_FLAGS = 1;
// Note, this handles the NULL case to deal with older accounts where the column was added
private static final String WHERE_ACCOUNT_SECURITY_NONZERO =
Account.SECURITY_FLAGS + " IS NOT NULL AND " + Account.SECURITY_FLAGS + "!=0";
/**
* This projection on Account is for clearing the "security hold" column. Also includes
* the security flags column, so we can use it for selecting.
*/
private static final String[] ACCOUNT_FLAGS_PROJECTION = new String[] {
AccountColumns.ID, AccountColumns.FLAGS, AccountColumns.SECURITY_FLAGS
};
private static final int ACCOUNT_FLAGS_COLUMN_ID = 0;
private static final int ACCOUNT_FLAGS_COLUMN_FLAGS = 1;
/**
* Get the security policy instance
@ -132,7 +119,7 @@ public class SecurityPolicy {
int passwordComplexChars = Integer.MIN_VALUE;
Cursor c = mContext.getContentResolver().query(Account.CONTENT_URI,
ACCOUNT_SECURITY_PROJECTION, WHERE_ACCOUNT_SECURITY_NONZERO, null, null);
ACCOUNT_SECURITY_PROJECTION, Account.SECURITY_NONZERO_SELECTION, null, null);
try {
while (c.moveToNext()) {
long flags = c.getLong(ACCOUNT_SECURITY_COLUMN_FLAGS);
@ -333,30 +320,6 @@ public class SecurityPolicy {
account.update(mContext, cv);
}
/**
* Clear all account hold flags that are set. This will trigger watchers, and in particular
* will cause EAS to try and resync the account(s).
*/
public void clearAccountHoldFlags() {
ContentResolver resolver = mContext.getContentResolver();
Cursor c = resolver.query(Account.CONTENT_URI, ACCOUNT_FLAGS_PROJECTION,
WHERE_ACCOUNT_SECURITY_NONZERO, null, null);
try {
while (c.moveToNext()) {
int flags = c.getInt(ACCOUNT_FLAGS_COLUMN_FLAGS);
if (0 != (flags & Account.FLAGS_SECURITY_HOLD)) {
ContentValues cv = new ContentValues();
cv.put(AccountColumns.FLAGS, flags & ~Account.FLAGS_SECURITY_HOLD);
long accountId = c.getLong(ACCOUNT_FLAGS_COLUMN_ID);
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId);
resolver.update(uri, cv, null, null);
}
}
} finally {
c.close();
}
}
/**
* API: Sync service should call this any time a sync fails due to isActive() returning false.
* This will kick off the notify-acquire-admin-state process and/or increase the security level.
@ -774,7 +737,7 @@ public class SecurityPolicy {
*/
@Override
public void onPasswordChanged(Context context, Intent intent) {
SecurityPolicy.getInstance(context).clearAccountHoldFlags();
Account.clearSecurityHoldOnAllAccounts(context);
}
}
}

View File

@ -33,6 +33,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.security.MessageDigest;
import android.telephony.TelephonyManager;
@ -744,4 +745,32 @@ public class Utility {
}
return null;
}
/**
* @return a long in column {@code column} of the first result row, if the query returns at
* least 1 row. Otherwise returns {@code defaultValue}.
*/
public static Long getFirstRowLong(Context context, Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder, int column,
Long defaultValue) {
Cursor c = context.getContentResolver().query(uri, projection, selection, selectionArgs,
sortOrder);
try {
if (c.moveToFirst()) {
return c.getLong(column);
}
} finally {
c.close();
}
return defaultValue;
}
/**
* {@link #getFirstRowLong} with null as a default value.
*/
public static Long getFirstRowLong(Context context, Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder, int column) {
return getFirstRowLong(context, uri, projection, selection, selectionArgs,
sortOrder, column, null);
}
}

View File

@ -94,10 +94,6 @@ public class MessageList extends Activity implements OnClickListener,
private static final String[] ACCOUNT_NAME_PROJECTION = new String[] {
AccountColumns.DISPLAY_NAME };
private static final int ACCOUNT_INFO_COLUMN_FLAGS = 0;
private static final String[] ACCOUNT_INFO_PROJECTION = new String[] {
AccountColumns.FLAGS };
private static final String ID_SELECTION = EmailContent.RECORD_ID + "=?";
/* package */ MessageListFragment getListFragmentForTest() {
@ -470,7 +466,7 @@ public class MessageList extends Activity implements OnClickListener,
@Override
protected Long doInBackground(Void... params) {
// Quick check that account is not in security hold
if (mAccountId != -1 && isSecurityHold(mAccountId)) {
if (mAccountId != -1 && Account.isSecurityHold(MessageList.this, mAccountId)) {
mAction = SHOW_SECURITY_ACTIVITY;
return Mailbox.NO_MAILBOX;
}
@ -524,26 +520,6 @@ public class MessageList extends Activity implements OnClickListener,
}
}
/**
* Check a single account for security hold status. Do not call from UI thread.
*/
private boolean isSecurityHold(long accountId) {
Cursor c = MessageList.this.getContentResolver().query(
ContentUris.withAppendedId(Account.CONTENT_URI, accountId),
ACCOUNT_INFO_PROJECTION, null, null, null);
try {
if (c.moveToFirst()) {
int flags = c.getInt(ACCOUNT_INFO_COLUMN_FLAGS);
if ((flags & Account.FLAGS_SECURITY_HOLD) != 0) {
return true;
}
}
} finally {
c.close();
}
return false;
}
/**
* Handle the eventual result from the security update activity
*

View File

@ -127,19 +127,18 @@ public class AccountSecurity extends Activity {
SecurityPolicy sp = SecurityPolicy.getInstance(this);
// check current security level - if sufficient, we're done!
if (sp.isActive(null)) {
sp.clearAccountHoldFlags();
Account.clearSecurityHoldOnAllAccounts(this);
return;
}
// set current security level
sp.setActivePolicies();
// check current security level - if sufficient, we're done!
if (sp.isActive(null)) {
sp.clearAccountHoldFlags();
Account.clearSecurityHoldOnAllAccounts(this);
return;
}
// if not sufficient, launch the activity to have the user set a new password.
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
}
}

View File

@ -50,11 +50,6 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
private CheckAccountStateTask mCheckAccountStateTask;
private static final int ACCOUNT_INFO_COLUMN_FLAGS = 0;
private static final int ACCOUNT_INFO_COLUMN_SECURITY_FLAGS = 1;
private static final String[] ACCOUNT_INFO_PROJECTION = new String[] {
AccountColumns.FLAGS, AccountColumns.SECURITY_FLAGS };
public static void actionSetNames(Activity fromActivity) {
fromActivity.startActivity(new Intent(fromActivity, AccountSetupNames.class));
}
@ -208,22 +203,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
@Override
protected Boolean doInBackground(Void... params) {
Cursor c = AccountSetupNames.this.getContentResolver().query(
ContentUris.withAppendedId(Account.CONTENT_URI, mAccountId),
ACCOUNT_INFO_PROJECTION, null, null, null);
try {
if (c.moveToFirst()) {
int flags = c.getInt(ACCOUNT_INFO_COLUMN_FLAGS);
int securityFlags = c.getInt(ACCOUNT_INFO_COLUMN_SECURITY_FLAGS);
if ((flags & Account.FLAGS_SECURITY_HOLD) != 0) {
return Boolean.TRUE;
}
}
} finally {
c.close();
}
return Boolean.FALSE;
return Account.isSecurityHold(AccountSetupNames.this, mAccountId);
}
@Override

View File

@ -16,6 +16,8 @@
package com.android.email.provider;
import com.android.email.Utility;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
@ -150,16 +152,8 @@ public abstract class EmailContent {
* @return the number of items matching the query (or zero)
*/
static public int count(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = context.getContentResolver()
.query(uri, COUNT_COLUMNS, selection, selectionArgs, null);
try {
if (!cursor.moveToFirst()) {
return 0;
}
return cursor.getInt(0);
} finally {
cursor.close();
}
return Utility.getFirstRowLong(context,
uri, COUNT_COLUMNS, selection, selectionArgs, null, 0, Long.valueOf(0)).intValue();
}
/**
@ -290,15 +284,11 @@ public abstract class EmailContent {
/**
* Returns the bodyId for the given messageId, or -1 if no body is found.
*/
public static long lookupBodyIdWithMessageId(ContentResolver resolver, long messageId) {
Cursor c = resolver.query(Body.CONTENT_URI, ID_PROJECTION,
Body.MESSAGE_KEY + "=?",
new String[] {Long.toString(messageId)}, null);
try {
return c.moveToFirst() ? c.getLong(ID_PROJECTION_COLUMN) : -1;
} finally {
c.close();
}
public static long lookupBodyIdWithMessageId(Context context, long messageId) {
return Utility.getFirstRowLong(context, Body.CONTENT_URI,
ID_PROJECTION, Body.MESSAGE_KEY + "=?",
new String[] {Long.toString(messageId)}, null, ID_PROJECTION_COLUMN,
Long.valueOf(-1));
}
/**
@ -309,7 +299,7 @@ public abstract class EmailContent {
public static void updateBodyWithMessageId(Context context, long messageId,
ContentValues values) {
ContentResolver resolver = context.getContentResolver();
long bodyId = lookupBodyIdWithMessageId(resolver, messageId);
long bodyId = lookupBodyIdWithMessageId(context, messageId);
values.put(BodyColumns.MESSAGE_KEY, messageId);
if (bodyId == -1) {
resolver.insert(CONTENT_URI, values);
@ -320,18 +310,10 @@ public abstract class EmailContent {
}
public static long restoreBodySourceKey(Context context, long messageId) {
Cursor c = context.getContentResolver().query(Body.CONTENT_URI,
return Utility.getFirstRowLong(context, Body.CONTENT_URI,
Body.PROJECTION_SOURCE_KEY,
Body.MESSAGE_KEY + "=?", new String[] {Long.toString(messageId)}, null);
try {
if (c.moveToFirst()) {
return c.getLong(0);
} else {
return 0;
}
} finally {
c.close();
}
Body.MESSAGE_KEY + "=?", new String[] {Long.toString(messageId)}, null, 0,
Long.valueOf(0));
}
private static String restoreTextWithMessageId(Context context, long messageId,
@ -907,6 +889,11 @@ public abstract class EmailContent {
RECORD_ID, MailboxColumns.TYPE
};
public static final int ACCOUNT_FLAGS_COLUMN_ID = 0;
public static final int ACCOUNT_FLAGS_COLUMN_FLAGS = 1;
public static final String[] ACCOUNT_FLAGS_PROJECTION = new String[] {
AccountColumns.ID, AccountColumns.FLAGS};
public static final String MAILBOX_SELECTION =
MessageColumns.MAILBOX_KEY + " =?";
@ -915,6 +902,10 @@ public abstract class EmailContent {
public static final String UUID_SELECTION = AccountColumns.COMPATIBILITY_UUID + " =?";
public static final String SECURITY_NONZERO_SELECTION =
Account.SECURITY_FLAGS + " IS NOT NULL AND " + Account.SECURITY_FLAGS + "!=0";
/**
* This projection is for searching for the default account
*/
@ -1257,17 +1248,9 @@ public abstract class EmailContent {
* Helper method for finding the default account.
*/
static private long getDefaultAccountWhere(Context context, String where) {
Cursor cursor = context.getContentResolver().query(CONTENT_URI,
return Utility.getFirstRowLong(context, CONTENT_URI,
DEFAULT_ID_PROJECTION,
where, null, null);
try {
if (cursor.moveToFirst()) {
return cursor.getLong(0); // column 0 is id
}
} finally {
cursor.close();
}
return -1;
where, null, null, 0, Long.valueOf(-1));
}
/**
@ -1322,16 +1305,9 @@ public abstract class EmailContent {
}
// Now id is a UUId.
Cursor cursor = context.getContentResolver().query(CONTENT_URI, ID_PROJECTION,
UUID_SELECTION, new String[] {id}, null);
try {
if (cursor.moveToFirst()) {
return cursor.getLong(0); // column 0 is id
}
} finally {
cursor.close();
}
return -1; // Not found.
return Utility.getFirstRowLong(context,
CONTENT_URI, ID_PROJECTION,
UUID_SELECTION, new String[] {id}, null, 0, Long.valueOf(-1));
}
/**
@ -1381,16 +1357,45 @@ public abstract class EmailContent {
* @return true if an {@code accountId} is assigned to any existing account.
*/
public static boolean isValidId(Context context, long accountId) {
Cursor cursor = context.getContentResolver().query(CONTENT_URI, ID_PROJECTION,
ID_SELECTION, new String[] {"" + accountId}, null);
return null != Utility.getFirstRowLong(context, CONTENT_URI, ID_PROJECTION,
ID_SELECTION, new String[] {Long.toString(accountId)}, null, 0);
}
/**
* Check a single account for security hold status.
*/
public static boolean isSecurityHold(Context context, long accountId) {
Long flags = Utility.getFirstRowLong(context,
ContentUris.withAppendedId(Account.CONTENT_URI, accountId),
ACCOUNT_FLAGS_PROJECTION, null, null, null, ACCOUNT_FLAGS_COLUMN_FLAGS);
return (flags != null) && ((flags & Account.FLAGS_SECURITY_HOLD) != 0);
}
/**
* Clear all account hold flags that are set.
*
* (This will trigger watchers, and in particular will cause EAS to try and resync the
* account(s).)
*/
public static void clearSecurityHoldOnAllAccounts(Context context) {
ContentResolver resolver = context.getContentResolver();
Cursor c = resolver.query(Account.CONTENT_URI, ACCOUNT_FLAGS_PROJECTION,
SECURITY_NONZERO_SELECTION, null, null);
try {
if (cursor.moveToFirst()) {
return true;
while (c.moveToNext()) {
int flags = c.getInt(ACCOUNT_FLAGS_COLUMN_FLAGS);
if (0 != (flags & FLAGS_SECURITY_HOLD)) {
ContentValues cv = new ContentValues();
cv.put(AccountColumns.FLAGS, flags & ~FLAGS_SECURITY_HOLD);
long accountId = c.getLong(ACCOUNT_FLAGS_COLUMN_ID);
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId);
resolver.update(uri, cv, null, null);
}
}
} finally {
cursor.close();
c.close();
}
return false; // Not found.
}
/**
@ -2126,18 +2131,10 @@ public abstract class EmailContent {
* @return the id of the mailbox, or -1 if not found
*/
public static long findMailboxOfType(Context context, long accountId, int type) {
long mailboxId = NO_MAILBOX;
String[] bindArguments = new String[] {Long.toString(type), Long.toString(accountId)};
Cursor c = context.getContentResolver().query(Mailbox.CONTENT_URI,
ID_PROJECTION, WHERE_TYPE_AND_ACCOUNT_KEY, bindArguments, null);
try {
if (c.moveToFirst()) {
mailboxId = c.getLong(ID_PROJECTION_COLUMN);
}
} finally {
c.close();
}
return mailboxId;
return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI,
ID_PROJECTION, WHERE_TYPE_AND_ACCOUNT_KEY, bindArguments, null,
ID_PROJECTION_COLUMN, NO_MAILBOX);
}
/**

View File

@ -0,0 +1,138 @@
/*
* Copyright (C) 2010 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.email.provider.EmailProvider;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContext;
import android.test.mock.MockCursor;
/**
* Helper classes (and possibly methods) for database related tests.
*/
public final class DBTestHelper {
private DBTestHelper() { // Utility class. No instantiation.
}
/**
* A simple {@link Context} that returns {@link MyProvider} as the email content provider.
*/
public static class MyContext extends MockContext {
private final MockContentResolver mContentResolver;
private final MyProvider mProvider;
public MyContext() {
mProvider = new MyProvider();
mContentResolver = new MockContentResolver();
mContentResolver.addProvider(EmailProvider.EMAIL_AUTHORITY, mProvider);
}
@Override
public ContentResolver getContentResolver() {
return mContentResolver;
}
public MyProvider getMyProvider() {
return mProvider;
}
}
/**
* A simply {@link ContentProvider} to mock out {@link ContentProvider#query}.
*/
public static class MyProvider extends ContentProvider {
public Cursor mQueryPresetResult;
public Uri mPassedUri;
public String[] mPassedProjection;
public String mPassedSelection;
public String[] mPassedSelectionArgs;
public String mPassedSortOrder;
public void reset() {
mQueryPresetResult = null;
mPassedUri = null;
mPassedProjection = null;
mPassedSelection = null;
mPassedSelectionArgs = null;
mPassedSortOrder = null;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
mPassedUri = uri;
mPassedProjection = projection;
mPassedSelection = selection;
mPassedSelectionArgs = selectionArgs;
mPassedSortOrder = sortOrder;
return mQueryPresetResult;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
throw new UnsupportedOperationException();
}
@Override
public String getType(Uri uri) {
throw new UnsupportedOperationException();
}
@Override
public Uri insert(Uri uri, ContentValues values) {
throw new UnsupportedOperationException();
}
@Override
public boolean onCreate() {
throw new UnsupportedOperationException();
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
throw new UnsupportedOperationException();
}
}
/**
* Simple {@link MockCursor} subclass that implements common methods.
*/
public static class EasyMockCursor extends MockCursor {
public int mCount;
public boolean mClosed;
public EasyMockCursor(int count) {
mCount = count;
}
@Override
public int getCount() {
return mCount;
}
@Override
public void close() {
mClosed = true;
}
}
}

View File

@ -353,29 +353,6 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
assertEquals(Account.FLAGS_VIBRATE_ALWAYS, a2b.mFlags);
}
/**
* Test the API to clear all policy hold flags in all accounts)
*/
public void testClearHoldFlags() {
SecurityPolicy sp = getSecurityPolicy();
Account a1 = ProviderTestUtils.setupAccount("holdflag-1", false, mMockContext);
a1.mFlags = Account.FLAGS_NOTIFY_NEW_MAIL;
a1.save(mMockContext);
Account a2 = ProviderTestUtils.setupAccount("holdflag-2", false, mMockContext);
a2.mFlags = Account.FLAGS_VIBRATE_ALWAYS | Account.FLAGS_SECURITY_HOLD;
a2.save(mMockContext);
// bulk clear
sp.clearAccountHoldFlags();
// confirm new values as expected - no hold flags; other flags unmolested
Account a1a = Account.restoreAccountWithId(mMockContext, a1.mId);
assertEquals(Account.FLAGS_NOTIFY_NEW_MAIL, a1a.mFlags);
Account a2a = Account.restoreAccountWithId(mMockContext, a2.mId);
assertEquals(Account.FLAGS_VIBRATE_ALWAYS, a2a.mFlags);
}
/**
* Test the response to disabling DeviceAdmin status
*/

View File

@ -17,6 +17,7 @@
package com.android.email;
import com.android.email.Utility.NewFileCreator;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.Mailbox;
import android.content.Context;
@ -25,6 +26,7 @@ import android.os.Environment;
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;
import android.test.mock.MockCursor;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import android.widget.TextView;
@ -348,4 +350,55 @@ public class UtilityUnitTests extends AndroidTestCase {
view.setText("65535");
assertTrue(Utility.isPortFieldValid(view));
}
public void testGetFirstRowLong() {
DBTestHelper.MyContext context = new DBTestHelper.MyContext();
DBTestHelper.MyProvider provider = context.getMyProvider();
// Case 1: Row found
DBTestHelper.EasyMockCursor cursor = new DBTestHelper.EasyMockCursor(1) {
@Override
public boolean moveToFirst() {
return true;
}
@Override
public long getLong(int index) {
assertEquals(1, index);
return 100;
}
};
provider.mQueryPresetResult = cursor;
Long actual = Utility.getFirstRowLong(context, Account.CONTENT_URI,
new String[] {"p"}, "se", new String[] {"sa"}, "so", 1);
assertEquals(Long.valueOf(100), actual);
MoreAsserts.assertEquals(new String[] {"p"}, provider.mPassedProjection);
assertEquals("se", provider.mPassedSelection);
MoreAsserts.assertEquals(new String[] {"sa"}, provider.mPassedSelectionArgs);
assertEquals("so", provider.mPassedSortOrder);
assertTrue(cursor.mClosed);
// Case 2: No row found
cursor = new DBTestHelper.EasyMockCursor(0) {
@Override
public boolean moveToFirst() {
return false;
}
};
provider.mQueryPresetResult = cursor;
actual = Utility.getFirstRowLong(context, Account.CONTENT_URI, new String[] {"p"},
null, null, null, 0);
assertEquals(null, actual);
assertTrue(cursor.mClosed);
// Test with a default value.
actual = Utility.getFirstRowLong(context, Account.CONTENT_URI, new String[] {"p"},
null, null, null, 0, Long.valueOf(-1));
assertEquals(Long.valueOf(-1), actual);
assertTrue(cursor.mClosed);
}
}

View File

@ -577,14 +577,14 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false,
true, mMockContext);
long message1Id = message1.mId;
long bodyId1 = Body.lookupBodyIdWithMessageId(resolver, message1Id);
long bodyId1 = Body.lookupBodyIdWithMessageId(mMockContext, message1Id);
assertEquals(bodyId1, -1);
// 2. create message with body, check that returned bodyId is correct
Message message2 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, true,
true, mMockContext);
long message2Id = message2.mId;
long bodyId2 = Body.lookupBodyIdWithMessageId(resolver, message2Id);
long bodyId2 = Body.lookupBodyIdWithMessageId(mMockContext, message2Id);
Body body = loadBodyForMessageId(message2Id);
assertNotNull(body);
assertEquals(body.mId, bodyId2);
@ -1226,7 +1226,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
long account1Id = account1.mId;
Mailbox box1 = ProviderTestUtils.setupMailbox("box1", account1Id, true, mMockContext);
long box1Id = box1.mId;
// Each message has a body, and also give each 2 attachments
Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, true,
false, mMockContext);
@ -1256,7 +1256,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
String bodySelection = BodyColumns.MESSAGE_KEY + " IN (?,?)";
String attachmentSelection = AttachmentColumns.MESSAGE_KEY + " IN (?,?)";
String[] selArgs = new String[] { String.valueOf(message1Id), String.valueOf(message2Id) };
// make sure there are two bodies
int numBodies = EmailContent.count(mMockContext, Body.CONTENT_URI, bodySelection, selArgs);
assertEquals(2, numBodies);
@ -1632,7 +1632,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
// TODO We should check for the deletion of attachment files once this is implemented in
// the provider
// Explanation for what happens below...
// The next time the database is created by the provider, it will notice that there's
// already a EmailProviderBody.db file. In this case, it will delete that database to
@ -1774,4 +1774,35 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct2Contacts,
Mailbox.restoreMailboxOfType(context, acct2.mId, Mailbox.TYPE_CONTACTS));
}
public void testAccountIsSecurityHold() {
final Context context = mMockContext;
Account acct1 = ProviderTestUtils.setupAccount("acct1", true, context);
Account acct2 = ProviderTestUtils.setupAccount("acct2", false, context);
acct2.mFlags |= Account.FLAGS_SECURITY_HOLD;
acct2.save(context);
assertFalse(Account.isSecurityHold(context, acct1.mId));
assertTrue(Account.isSecurityHold(context, acct2.mId));
assertFalse(Account.isSecurityHold(context, 9999999)); // No such account
}
public void testClearAccountHoldFlags() {
Account a1 = ProviderTestUtils.setupAccount("holdflag-1", false, mMockContext);
a1.mFlags = Account.FLAGS_NOTIFY_NEW_MAIL;
a1.save(mMockContext);
Account a2 = ProviderTestUtils.setupAccount("holdflag-2", false, mMockContext);
a2.mFlags = Account.FLAGS_VIBRATE_ALWAYS | Account.FLAGS_SECURITY_HOLD;
a2.save(mMockContext);
// bulk clear
Account.clearSecurityHoldOnAllAccounts(mMockContext);
// confirm new values as expected - no hold flags; other flags unmolested
Account a1a = Account.restoreAccountWithId(mMockContext, a1.mId);
assertEquals(Account.FLAGS_NOTIFY_NEW_MAIL, a1a.mFlags);
Account a2a = Account.restoreAccountWithId(mMockContext, a2.mId);
assertEquals(Account.FLAGS_VIBRATE_ALWAYS, a2a.mFlags);
}
}