Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 485b464a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove main looper assertions and attempts to run tests in main...

Merge "Remove main looper assertions and attempts to run tests in main thread." into nyc-andromeda-dev
parents 68bbec9b 2056205c
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -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;
+8 −0
Original line number Diff line number Diff line
@@ -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!");
        }
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -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;
+0 −18
Original line number Diff line number Diff line
@@ -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);