Skip to content
Snippets Groups Projects
Commit 46deec9f authored by Victor Chang's avatar Victor Chang Committed by Automerger Merge Worker
Browse files

Merge "Avoid mockito in MotionPredictorBenchmark" into main am: d808fab4

parents d370c4b7 d808fab4
No related branches found
No related tags found
No related merge requests found
......@@ -16,8 +16,6 @@
package android.input
import android.content.Context
import android.content.res.Resources
import android.os.SystemProperties
import android.perftests.utils.PerfStatusReporter
import android.view.InputDevice
......@@ -38,8 +36,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import java.time.Duration
......@@ -68,18 +64,6 @@ private fun getStylusMotionEvent(
InputDevice.SOURCE_STYLUS, /*flags=*/0)
}
private fun getPredictionContext(offset: Duration, enablePrediction: Boolean): Context {
val context = mock(Context::class.java)
val resources: Resources = mock(Resources::class.java)
`when`(context.getResources()).thenReturn(resources)
`when`(resources.getInteger(
com.android.internal.R.integer.config_motionPredictionOffsetNanos)).thenReturn(
offset.toNanos().toInt())
`when`(resources.getBoolean(
com.android.internal.R.bool.config_enableMotionPrediction)).thenReturn(enablePrediction)
return context
}
@RunWith(AndroidJUnit4::class)
@LargeTest
class MotionPredictorBenchmark {
......@@ -115,7 +99,7 @@ class MotionPredictorBenchmark {
var eventPosition = 0f
val positionInterval = 10f
val predictor = MotionPredictor(getPredictionContext(offset, /*enablePrediction=*/true))
val predictor = MotionPredictor(/*isPredictionEnabled=*/true, offset.toNanos().toInt())
// ACTION_DOWN t=0 x=0 y=0
predictor.record(getStylusMotionEvent(
eventTime, ACTION_DOWN, /*x=*/eventPosition, /*y=*/eventPosition))
......@@ -141,12 +125,11 @@ class MotionPredictorBenchmark {
*/
@Test
fun timeCreatePredictor() {
val context = getPredictionContext(
/*offset=*/Duration.ofMillis(20), /*enablePrediction=*/true)
val offsetNanos = Duration.ofMillis(20).toNanos().toInt()
val state = perfStatusReporter.getBenchmarkState()
while (state.keepRunning()) {
MotionPredictor(context)
MotionPredictor(/*isPredictionEnabled=*/true, offsetNanos)
}
}
}
......@@ -20,6 +20,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import com.android.internal.annotations.VisibleForTesting;
import libcore.util.NativeAllocationRegistry;
/**
......@@ -57,11 +59,21 @@ public final class MotionPredictor {
* @param context The context for the predictions
*/
public MotionPredictor(@NonNull Context context) {
mIsPredictionEnabled = context.getResources().getBoolean(
com.android.internal.R.bool.config_enableMotionPrediction);
final int offsetNanos = context.getResources().getInteger(
com.android.internal.R.integer.config_motionPredictionOffsetNanos);
mPtr = nativeInitialize(offsetNanos);
this(
context.getResources().getBoolean(
com.android.internal.R.bool.config_enableMotionPrediction),
context.getResources().getInteger(
com.android.internal.R.integer.config_motionPredictionOffsetNanos));
}
/**
* Internal constructor for testing.
* @hide
*/
@VisibleForTesting
public MotionPredictor(boolean isPredictionEnabled, int motionPredictionOffsetNanos) {
mIsPredictionEnabled = isPredictionEnabled;
mPtr = nativeInitialize(motionPredictionOffsetNanos);
RegistryHolder.REGISTRY.registerNativeAllocation(this, mPtr);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment