Remove illegal references to IsolatedContext
This fixes a crash on account deletion, leaving around bad accounts that were in limbo Also remove a test for an unsupported operation Bug: 5051951 Change-Id: Ieebc7f769075614ae1a656cf123d8ce0313e611d
This commit is contained in:
parent
e12c0522f8
commit
1ecfb5311b
|
@ -28,7 +28,6 @@ import android.os.Bundle;
|
|||
import android.os.IBinder;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.test.IsolatedContext;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.mail.store.Pop3Store.Pop3Message;
|
||||
|
@ -117,6 +116,8 @@ public class Controller {
|
|||
private static RemoteCallbackList<IEmailServiceCallback> sCallbackList =
|
||||
new RemoteCallbackList<IEmailServiceCallback>();
|
||||
|
||||
private volatile boolean mInUnitTests = false;
|
||||
|
||||
protected Controller(Context _context) {
|
||||
mContext = _context.getApplicationContext();
|
||||
mProviderContext = _context;
|
||||
|
@ -124,6 +125,15 @@ public class Controller {
|
|||
mLegacyController.addListener(mLegacyListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this controller as being in use in a unit test.
|
||||
* This is a kludge vs having proper mocks and dependency injection; since the Controller is a
|
||||
* global singleton there isn't much else we can do.
|
||||
*/
|
||||
public void markForUnitTest(boolean inUnitTests) {
|
||||
mInUnitTests = inUnitTests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup for test. Mustn't be called for the regular {@link Controller}, as it's a
|
||||
* singleton and lives till the process finishes.
|
||||
|
@ -472,7 +482,7 @@ public class Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Look for a specific mailbox, creating it if necessary, and return the mailbox id.
|
||||
* Look for a specific system mailbox, creating it if necessary, and return the mailbox id.
|
||||
* This is a blocking operation and should not be called from the UI thread.
|
||||
*
|
||||
* Synchronized so multiple threads can call it (and not risk creating duplicate boxes).
|
||||
|
@ -1148,8 +1158,10 @@ public class Controller {
|
|||
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId);
|
||||
context.getContentResolver().delete(uri, null, null);
|
||||
|
||||
// For unit tests, don't run backup, security, and ui pieces
|
||||
if (context instanceof IsolatedContext) return;
|
||||
// For unit tests, don't run backup, security, and ui pieces.
|
||||
if (mInUnitTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up
|
||||
AccountBackupRestore.backup(context);
|
||||
|
|
|
@ -136,15 +136,6 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
|||
assertNotNull(testMailbox);
|
||||
assertEquals(8, testMailbox.mFlags); // Flags should be "holds mail"
|
||||
assertEquals(-1L, testMailbox.mParentKey); // Parent is off the top-level
|
||||
|
||||
// Test creating user mailbox; some fields have changed
|
||||
mTestController.createMailbox(1L, Mailbox.TYPE_MAIL);
|
||||
testMailboxId = Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_MAIL);
|
||||
assertTrue(testMailboxId != Mailbox.NO_MAILBOX);
|
||||
testMailbox = Mailbox.restoreMailboxWithId(mProviderContext, testMailboxId);
|
||||
assertNotNull(testMailbox);
|
||||
assertEquals(0, testMailbox.mFlags); // Flags are not set
|
||||
assertEquals(0L, testMailbox.mParentKey); // Parent is not set
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,6 +58,7 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
|
|||
mMockContext = new MockContext2(getMockContext(), mContext);
|
||||
// Invalidate all caches, since we reset the database for each test
|
||||
ContentCache.invalidateAllCaches();
|
||||
Controller.getInstance(mMockContext).markForUnitTest(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,6 +66,7 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
|
|||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
Controller.getInstance(mMockContext).markForUnitTest(false);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
@ -398,10 +400,10 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
|
|||
* Lightweight subclass of the Controller class allows injection of mock context
|
||||
*/
|
||||
public static class TestController extends Controller {
|
||||
|
||||
protected TestController(Context providerContext, Context systemContext) {
|
||||
super(systemContext);
|
||||
setProviderContext(providerContext);
|
||||
markForUnitTest(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue