summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Garfield, Tan <xutan@google.com> 2016-06-10 11:23:40 -0700
committer Garfield, Tan <xutan@google.com> 2016-06-10 15:31:40 -0700
commit2056205cb85d529d732638c45fe459168168e1ee (patch)
treed9378baf05908dec2c0f4aec5fed31e4caa75e8d
parent816fe7f17222234db2b3d28e2ab5c5b0282e3f3a (diff)
Remove main looper assertions and attempts to run tests in main thread.
It looks like if we pass timeout_msec 300000 main thread is then blocked. If we ever post a runnable to it synchronously in test, we'll get a deadlock. Change-Id: I7bd4ce2aaa1ffad72b83a343ff3331179896bd78
-rw-r--r--src/com/android/documentsui/Events.java7
-rw-r--r--src/com/android/documentsui/Shared.java8
-rw-r--r--src/com/android/documentsui/ThumbnailCache.java7
-rw-r--r--tests/src/com/android/documentsui/ThumbnailCacheTest.java18
4 files changed, 12 insertions, 28 deletions
diff --git a/src/com/android/documentsui/Events.java b/src/com/android/documentsui/Events.java
index de01ee992..d131f2e85 100644
--- a/src/com/android/documentsui/Events.java
+++ b/src/com/android/documentsui/Events.java
@@ -19,7 +19,6 @@ package com.android.documentsui;
import static com.android.documentsui.Shared.DEBUG;
import android.graphics.Point;
-import android.os.Looper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.Pools;
@@ -150,8 +149,7 @@ public final class Events {
}
public static MotionInputEvent obtain(MotionEvent event, RecyclerView view) {
- // Make sure events are only used in main thread.
- assert(Looper.myLooper() == Looper.getMainLooper());
+ Shared.checkMainLoop();
MotionInputEvent instance = sPool.acquire();
instance = (instance != null ? instance : new MotionInputEvent());
@@ -168,8 +166,7 @@ public final class Events {
}
public void recycle() {
- // Make sure events are only used in main thread.
- assert(Looper.myLooper() == Looper.getMainLooper());
+ Shared.checkMainLoop();
mEvent = null;
mPosition = -1;
diff --git a/src/com/android/documentsui/Shared.java b/src/com/android/documentsui/Shared.java
index f40ab7228..24755f39d 100644
--- a/src/com/android/documentsui/Shared.java
+++ b/src/com/android/documentsui/Shared.java
@@ -21,10 +21,12 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
+import android.os.Looper;
import android.provider.DocumentsContract;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Time;
+import android.util.Log;
import android.view.WindowManager;
import java.text.Collator;
@@ -213,4 +215,10 @@ public final class Shared {
return isProductivityMode(activity, intent)
|| intent.getBooleanExtra(DocumentsContract.EXTRA_FANCY_FEATURES, false);
}
+
+ public static void checkMainLoop() {
+ if (Looper.getMainLooper() != Looper.myLooper()) {
+ Log.e(TAG, "Calling from non-UI thread!");
+ }
+ }
}
diff --git a/src/com/android/documentsui/ThumbnailCache.java b/src/com/android/documentsui/ThumbnailCache.java
index ee2f168d5..ecde685d2 100644
--- a/src/com/android/documentsui/ThumbnailCache.java
+++ b/src/com/android/documentsui/ThumbnailCache.java
@@ -22,7 +22,6 @@ import android.content.ComponentCallbacks2;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
-import android.os.Looper;
import android.util.LruCache;
import android.util.Pair;
import android.util.Pools;
@@ -196,8 +195,7 @@ public class ThumbnailCache {
private static Result obtain(@Status int status, @Nullable Bitmap thumbnail,
@Nullable Point size, long lastModified) {
- // Make sure this method is only called from main thread.
- assert(Looper.myLooper() == Looper.getMainLooper());
+ Shared.checkMainLoop();
Result instance = sPool.acquire();
instance = (instance != null ? instance : new Result());
@@ -213,8 +211,7 @@ public class ThumbnailCache {
private Result() {}
public void recycle() {
- // Make sure this method is only called from main thread.
- assert(Looper.myLooper() == Looper.getMainLooper());
+ Shared.checkMainLoop();
mStatus = -1;
mThumbnail = null;
diff --git a/tests/src/com/android/documentsui/ThumbnailCacheTest.java b/tests/src/com/android/documentsui/ThumbnailCacheTest.java
index a6951cfc2..dda491847 100644
--- a/tests/src/com/android/documentsui/ThumbnailCacheTest.java
+++ b/tests/src/com/android/documentsui/ThumbnailCacheTest.java
@@ -25,16 +25,13 @@ import android.content.ComponentCallbacks2;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
-import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
-import android.support.test.rule.UiThreadTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.android.documentsui.ThumbnailCache.Result;
import com.android.documentsui.testing.Bitmaps;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,11 +52,6 @@ public class ThumbnailCacheTest {
private static final long LAST_MODIFIED = 100;
- // We need this rule to help us run tests in main thread. It'll be applied to each test
- // annotated with @UiThreadTest.
- @Rule
- public UiThreadTestRule uiThreadRule = new UiThreadTestRule();
-
private static final int CACHE_SIZE_LIMIT =
MIDSIZE_BITMAP.getByteCount() + LARGE_BITMAP.getByteCount();
@@ -71,7 +63,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testMiss() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -81,7 +72,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_Exact() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -92,7 +82,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_Smaller() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -103,7 +92,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_Larger() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -114,7 +102,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_Larger_HasBothSize() {
mCache.putThumbnail(URI_0, LARGE_SIZE, LARGE_BITMAP, LAST_MODIFIED);
mCache.putThumbnail(URI_0, SMALL_SIZE, SMALL_BITMAP, LAST_MODIFIED);
@@ -126,7 +113,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_Exact_MultiplePut() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -141,7 +127,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testHit_EqualLastModified() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
@@ -151,7 +136,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testEvictOldest_SizeExceeded() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
mCache.putThumbnail(URI_1, SMALL_SIZE, SMALL_BITMAP, LAST_MODIFIED);
@@ -163,7 +147,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testCacheShrink_OnTrimMemory_Moderate() {
mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED);
mCache.putThumbnail(URI_0, SMALL_SIZE, SMALL_BITMAP, LAST_MODIFIED);
@@ -176,7 +159,6 @@ public class ThumbnailCacheTest {
}
@Test
- @UiThreadTest
public void testCacheShrink_OnTrimMemory_Background() {
mCache.putThumbnail(URI_0, LARGE_SIZE, LARGE_BITMAP, LAST_MODIFIED);
mCache.putThumbnail(URI_0, SMALL_SIZE, SMALL_BITMAP, LAST_MODIFIED);