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

Commit b594b6f0 authored by Chris Craik's avatar Chris Craik Committed by Felka Chang
Browse files

Fix UnsupportedOperationException in CutoutSpecificationBenchmark

Exception was due to an exception from trying to get the display from
the app context, instead of an Activity context.

java.lang.UnsupportedOperationException: Tried to obtain display from a Context not associated
 with one.

In order to fix that and fix the display metrics factor, the CutoutSpecificationBenchmark only run
for the resolution 1080x1920 and density is 3.5f.

Test: atest CutoutSpecificationBenchmark

Change-Id: I0be9d09a859c5b3a8c5abff11a3d06d809edf9ab
parent 47cdc972
Loading
Loading
Loading
Loading
+11 −27
Original line number Diff line number Diff line
@@ -16,24 +16,20 @@

package android.view;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.PathParser;

import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +37,10 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class CutoutSpecificationBenchmark {
    private static final int DISPLAY_WIDTH = 1080;
    private static final int DISPLAY_HEIGHT = 1920;
    private static final float DISPLAY_DENSITY = 3.5f;

    private static final String TAG = "CutoutSpecificationBenchmark";

    private static final String BOTTOM_MARKER = "@bottom";
@@ -69,21 +69,6 @@ public class CutoutSpecificationBenchmark {
    @Rule
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    private Context mContext;
    private DisplayMetrics mDisplayMetrics;

    /**
     * Setup the necessary member field used by test methods.
     */
    @Before
    public void setUp() {
        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        mDisplayMetrics = new DisplayMetrics();
        mContext.getDisplay().getRealMetrics(mDisplayMetrics);
    }


    private static void toRectAndAddToRegion(Path p, Region inoutRegion, Rect inoutRect) {
        final RectF rectF = new RectF();
        p.computeBounds(rectF, false /* unused */);
@@ -170,8 +155,8 @@ public class CutoutSpecificationBenchmark {
    public void parseByOldMethodForDoubleCutout() {
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            oldMethodParsingSpec(DOUBLE_CUTOUT_SPEC, mDisplayMetrics.widthPixels,
                    mDisplayMetrics.heightPixels, mDisplayMetrics.density);
            oldMethodParsingSpec(DOUBLE_CUTOUT_SPEC, DISPLAY_WIDTH, DISPLAY_HEIGHT,
                    DISPLAY_DENSITY);
        }
    }

@@ -179,8 +164,7 @@ public class CutoutSpecificationBenchmark {
    public void parseByNewMethodForDoubleCutout() {
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            new CutoutSpecification.Parser(mDisplayMetrics.density,
                    mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)
            new CutoutSpecification.Parser(DISPLAY_DENSITY, DISPLAY_WIDTH, DISPLAY_HEIGHT)
                    .parse(DOUBLE_CUTOUT_SPEC);
        }
    }
@@ -211,8 +195,8 @@ public class CutoutSpecificationBenchmark {

        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            new CutoutSpecification.Parser(mDisplayMetrics.density,
                    mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels).parse(spec);
            new CutoutSpecification.Parser(DISPLAY_DENSITY, DISPLAY_WIDTH, DISPLAY_HEIGHT)
                    .parse(spec);
        }
    }

@@ -233,8 +217,8 @@ public class CutoutSpecificationBenchmark {

        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            new CutoutSpecification.Parser(mDisplayMetrics.density,
                    mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels).parse(spec);
            new CutoutSpecification.Parser(DISPLAY_DENSITY, DISPLAY_WIDTH, DISPLAY_HEIGHT)
                    .parse(spec);
        }
    }
}