Loading packages/DocumentsUI/src/com/android/documentsui/Events.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading @@ -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; Loading packages/DocumentsUI/src/com/android/documentsui/Shared.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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!"); } } } packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading @@ -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; Loading packages/DocumentsUI/tests/src/com/android/documentsui/ThumbnailCacheTest.java +0 −18 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -71,7 +63,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testMiss() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -81,7 +72,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Exact() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -92,7 +82,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Smaller() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -103,7 +92,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Larger() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -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); Loading @@ -126,7 +113,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Exact_MultiplePut() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -141,7 +127,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_EqualLastModified() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading Loading
packages/DocumentsUI/src/com/android/documentsui/Events.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading @@ -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; Loading
packages/DocumentsUI/src/com/android/documentsui/Shared.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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!"); } } }
packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading @@ -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; Loading
packages/DocumentsUI/tests/src/com/android/documentsui/ThumbnailCacheTest.java +0 −18 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -71,7 +63,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testMiss() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -81,7 +72,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Exact() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -92,7 +82,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Smaller() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -103,7 +92,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Larger() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -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); Loading @@ -126,7 +113,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_Exact_MultiplePut() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -141,7 +127,6 @@ public class ThumbnailCacheTest { } @Test @UiThreadTest public void testHit_EqualLastModified() { mCache.putThumbnail(URI_0, MID_SIZE, MIDSIZE_BITMAP, LAST_MODIFIED); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading