Loading motiontoollib/build.gradle +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ dependencies { androidTestImplementation project(':SharedTestLib') androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation "androidx.test:rules:1.4.0" } protobuf { Loading motiontoollib/src/com/android/app/motiontool/MotionToolManager.kt +11 −12 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.app.motiontool import android.os.Process import android.util.Log import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.annotation.VisibleForTesting Loading @@ -41,10 +43,8 @@ import com.android.app.viewcapture.data.nano.ExportedData * * @see [DdmHandleMotionTool] */ class MotionToolManager private constructor( private val viewCapture: ViewCapture, private val windowManagerGlobal: WindowManagerGlobal ) { class MotionToolManager private constructor(private val windowManagerGlobal: WindowManagerGlobal) { private val viewCapture: ViewCapture = SimpleViewCapture() companion object { private const val TAG = "MotionToolManager" Loading @@ -52,13 +52,8 @@ class MotionToolManager private constructor( private var INSTANCE: MotionToolManager? = null @Synchronized fun getInstance( viewCapture: ViewCapture, windowManagerGlobal: WindowManagerGlobal ): MotionToolManager { return INSTANCE ?: MotionToolManager(viewCapture, windowManagerGlobal).also { INSTANCE = it } fun getInstance(windowManagerGlobal: WindowManagerGlobal): MotionToolManager { return INSTANCE ?: MotionToolManager(windowManagerGlobal).also { INSTANCE = it } } } Loading Loading @@ -139,6 +134,10 @@ class MotionToolManager private constructor( private fun getRootView(windowId: String): View? { return windowManagerGlobal.getRootView(windowId) } class SimpleViewCapture : ViewCapture(DEFAULT_MEMORY_SIZE, DEFAULT_INIT_POOL_SIZE, MAIN_EXECUTOR.submit { Choreographer.getInstance() }.get(), createAndStartNewLooperExecutor("MTViewCapture", Process.THREAD_PRIORITY_FOREGROUND)) } private data class TraceMetadata( Loading motiontoollib/tests/com/android/app/motiontool/DdmHandleMotionToolTest.kt +13 −22 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.app.motiontool import android.content.Intent import android.testing.AndroidTestingRunner import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.test.ext.junit.rules.ActivityScenarioRule Loading @@ -34,7 +35,6 @@ import com.android.app.motiontool.nano.MotionToolsResponse import com.android.app.motiontool.nano.PollTraceRequest import com.android.app.motiontool.nano.WindowIdentifier import com.android.app.motiontool.util.TestActivity import com.android.app.viewcapture.ViewCapture import com.google.protobuf.nano.MessageNano import junit.framework.Assert import junit.framework.Assert.assertEquals Loading @@ -46,17 +46,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidTestingRunner::class) class DdmHandleMotionToolTest { private val viewCaptureMemorySize = 100 private val viewCaptureInitPoolSize = 15 private val viewCapture = ViewCapture.getInstance(false, viewCaptureMemorySize, viewCaptureInitPoolSize) private val windowManagerGlobal = WindowManagerGlobal.getInstance() private val motionToolManager = MotionToolManager.getInstance(viewCapture, windowManagerGlobal) private val motionToolManager = MotionToolManager.getInstance(windowManagerGlobal) private val ddmHandleMotionTool = DdmHandleMotionTool.getInstance(motionToolManager) private val CLIENT_VERSION = 1 Loading @@ -74,7 +69,6 @@ class DdmHandleMotionToolTest { @After fun cleanup() { ddmHandleMotionTool.unregister() motionToolManager.reset() } @Test Loading Loading @@ -141,16 +135,13 @@ class DdmHandleMotionToolTest { @Test fun testOneOnDrawCallReturnsOneFrameResponse() { var traceId = 0 activityScenarioRule.scenario.onActivity { activityScenarioRule.scenario.onActivity { activity -> val beginTraceResponse = performBeginTraceRequest(getActivityViewRootId()) traceId = beginTraceResponse.beginTrace.traceId val rootView = it.findViewById<View>(android.R.id.content) rootView.invalidate() } val traceId = beginTraceResponse.beginTrace.traceId Choreographer.getInstance().postFrameCallback { activity.findViewById<View>(android.R.id.content).viewTreeObserver.dispatchOnDraw() // waits until main looper has no remaining tasks and is idle activityScenarioRule.scenario.onActivity { val pollTraceResponse = performPollTraceRequest(traceId) assertEquals(1, pollTraceResponse.pollTrace.exportedData.frameData.size) Loading @@ -158,7 +149,7 @@ class DdmHandleMotionToolTest { val endTraceResponse = performEndTraceRequest(traceId) assertEquals(0, endTraceResponse.endTrace.exportedData.frameData.size) } } } private fun performPollTraceRequest(requestTraceId: Int): MotionToolsResponse { Loading motiontoollib/tests/com/android/app/motiontool/MotionToolManagerTest.kt +12 −27 Original line number Diff line number Diff line Loading @@ -18,31 +18,25 @@ package com.android.app.motiontool import android.content.Intent import android.testing.AndroidTestingRunner import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry import com.android.app.motiontool.util.TestActivity import com.android.app.viewcapture.ViewCapture import junit.framework.Assert.assertEquals import junit.framework.Assert.assertTrue import org.junit.After import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidTestingRunner::class) class MotionToolManagerTest { private val windowManagerGlobal = WindowManagerGlobal.getInstance() private val viewCaptureMemorySize = 100 private val viewCaptureInitPoolSize = 15 private val viewCapture = ViewCapture.getInstance(false, viewCaptureMemorySize, viewCaptureInitPoolSize) private val motionToolManager = MotionToolManager.getInstance(viewCapture, windowManagerGlobal) private val motionToolManager = MotionToolManager.getInstance(windowManagerGlobal) private val activityIntent = Intent(InstrumentationRegistry.getInstrumentation().context, TestActivity::class.java) Loading @@ -50,11 +44,6 @@ class MotionToolManagerTest { @get:Rule val activityScenarioRule = ActivityScenarioRule<TestActivity>(activityIntent) @After fun cleanup() { motionToolManager.reset() } @Test(expected = UnknownTraceIdException::class) fun testEndTraceThrowsWithoutPrecedingBeginTrace() { motionToolManager.endTrace(0) Loading Loading @@ -93,15 +82,11 @@ class MotionToolManagerTest { @Test fun testOneOnDrawCallReturnsOneFrameResponse() { var traceId = 0 activityScenarioRule.scenario.onActivity { traceId = motionToolManager.beginTrace(getActivityViewRootId()) val rootView = it.findViewById<View>(android.R.id.content) rootView.invalidate() } activityScenarioRule.scenario.onActivity { activity -> val traceId = motionToolManager.beginTrace(getActivityViewRootId()) Choreographer.getInstance().postFrameCallback { activity.findViewById<View>(android.R.id.content).viewTreeObserver.dispatchOnDraw() // waits until main looper has no remaining tasks and is idle activityScenarioRule.scenario.onActivity { val polledExportedData = motionToolManager.pollTrace(traceId) assertEquals(1, polledExportedData.frameData.size) Loading @@ -109,7 +94,7 @@ class MotionToolManagerTest { val endExportedData = motionToolManager.endTrace(traceId) assertEquals(0, endExportedData.frameData.size) } } } private fun getActivityViewRootId(): String { Loading viewcapturelib/AndroidManifest.xml +3 −0 Original line number Diff line number Diff line Loading @@ -16,5 +16,8 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.android.app.viewcapture"> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions" /> </manifest> Loading
motiontoollib/build.gradle +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ dependencies { androidTestImplementation project(':SharedTestLib') androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation "androidx.test:rules:1.4.0" } protobuf { Loading
motiontoollib/src/com/android/app/motiontool/MotionToolManager.kt +11 −12 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.app.motiontool import android.os.Process import android.util.Log import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.annotation.VisibleForTesting Loading @@ -41,10 +43,8 @@ import com.android.app.viewcapture.data.nano.ExportedData * * @see [DdmHandleMotionTool] */ class MotionToolManager private constructor( private val viewCapture: ViewCapture, private val windowManagerGlobal: WindowManagerGlobal ) { class MotionToolManager private constructor(private val windowManagerGlobal: WindowManagerGlobal) { private val viewCapture: ViewCapture = SimpleViewCapture() companion object { private const val TAG = "MotionToolManager" Loading @@ -52,13 +52,8 @@ class MotionToolManager private constructor( private var INSTANCE: MotionToolManager? = null @Synchronized fun getInstance( viewCapture: ViewCapture, windowManagerGlobal: WindowManagerGlobal ): MotionToolManager { return INSTANCE ?: MotionToolManager(viewCapture, windowManagerGlobal).also { INSTANCE = it } fun getInstance(windowManagerGlobal: WindowManagerGlobal): MotionToolManager { return INSTANCE ?: MotionToolManager(windowManagerGlobal).also { INSTANCE = it } } } Loading Loading @@ -139,6 +134,10 @@ class MotionToolManager private constructor( private fun getRootView(windowId: String): View? { return windowManagerGlobal.getRootView(windowId) } class SimpleViewCapture : ViewCapture(DEFAULT_MEMORY_SIZE, DEFAULT_INIT_POOL_SIZE, MAIN_EXECUTOR.submit { Choreographer.getInstance() }.get(), createAndStartNewLooperExecutor("MTViewCapture", Process.THREAD_PRIORITY_FOREGROUND)) } private data class TraceMetadata( Loading
motiontoollib/tests/com/android/app/motiontool/DdmHandleMotionToolTest.kt +13 −22 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.app.motiontool import android.content.Intent import android.testing.AndroidTestingRunner import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.test.ext.junit.rules.ActivityScenarioRule Loading @@ -34,7 +35,6 @@ import com.android.app.motiontool.nano.MotionToolsResponse import com.android.app.motiontool.nano.PollTraceRequest import com.android.app.motiontool.nano.WindowIdentifier import com.android.app.motiontool.util.TestActivity import com.android.app.viewcapture.ViewCapture import com.google.protobuf.nano.MessageNano import junit.framework.Assert import junit.framework.Assert.assertEquals Loading @@ -46,17 +46,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidTestingRunner::class) class DdmHandleMotionToolTest { private val viewCaptureMemorySize = 100 private val viewCaptureInitPoolSize = 15 private val viewCapture = ViewCapture.getInstance(false, viewCaptureMemorySize, viewCaptureInitPoolSize) private val windowManagerGlobal = WindowManagerGlobal.getInstance() private val motionToolManager = MotionToolManager.getInstance(viewCapture, windowManagerGlobal) private val motionToolManager = MotionToolManager.getInstance(windowManagerGlobal) private val ddmHandleMotionTool = DdmHandleMotionTool.getInstance(motionToolManager) private val CLIENT_VERSION = 1 Loading @@ -74,7 +69,6 @@ class DdmHandleMotionToolTest { @After fun cleanup() { ddmHandleMotionTool.unregister() motionToolManager.reset() } @Test Loading Loading @@ -141,16 +135,13 @@ class DdmHandleMotionToolTest { @Test fun testOneOnDrawCallReturnsOneFrameResponse() { var traceId = 0 activityScenarioRule.scenario.onActivity { activityScenarioRule.scenario.onActivity { activity -> val beginTraceResponse = performBeginTraceRequest(getActivityViewRootId()) traceId = beginTraceResponse.beginTrace.traceId val rootView = it.findViewById<View>(android.R.id.content) rootView.invalidate() } val traceId = beginTraceResponse.beginTrace.traceId Choreographer.getInstance().postFrameCallback { activity.findViewById<View>(android.R.id.content).viewTreeObserver.dispatchOnDraw() // waits until main looper has no remaining tasks and is idle activityScenarioRule.scenario.onActivity { val pollTraceResponse = performPollTraceRequest(traceId) assertEquals(1, pollTraceResponse.pollTrace.exportedData.frameData.size) Loading @@ -158,7 +149,7 @@ class DdmHandleMotionToolTest { val endTraceResponse = performEndTraceRequest(traceId) assertEquals(0, endTraceResponse.endTrace.exportedData.frameData.size) } } } private fun performPollTraceRequest(requestTraceId: Int): MotionToolsResponse { Loading
motiontoollib/tests/com/android/app/motiontool/MotionToolManagerTest.kt +12 −27 Original line number Diff line number Diff line Loading @@ -18,31 +18,25 @@ package com.android.app.motiontool import android.content.Intent import android.testing.AndroidTestingRunner import android.view.Choreographer import android.view.View import android.view.WindowManagerGlobal import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry import com.android.app.motiontool.util.TestActivity import com.android.app.viewcapture.ViewCapture import junit.framework.Assert.assertEquals import junit.framework.Assert.assertTrue import org.junit.After import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidTestingRunner::class) class MotionToolManagerTest { private val windowManagerGlobal = WindowManagerGlobal.getInstance() private val viewCaptureMemorySize = 100 private val viewCaptureInitPoolSize = 15 private val viewCapture = ViewCapture.getInstance(false, viewCaptureMemorySize, viewCaptureInitPoolSize) private val motionToolManager = MotionToolManager.getInstance(viewCapture, windowManagerGlobal) private val motionToolManager = MotionToolManager.getInstance(windowManagerGlobal) private val activityIntent = Intent(InstrumentationRegistry.getInstrumentation().context, TestActivity::class.java) Loading @@ -50,11 +44,6 @@ class MotionToolManagerTest { @get:Rule val activityScenarioRule = ActivityScenarioRule<TestActivity>(activityIntent) @After fun cleanup() { motionToolManager.reset() } @Test(expected = UnknownTraceIdException::class) fun testEndTraceThrowsWithoutPrecedingBeginTrace() { motionToolManager.endTrace(0) Loading Loading @@ -93,15 +82,11 @@ class MotionToolManagerTest { @Test fun testOneOnDrawCallReturnsOneFrameResponse() { var traceId = 0 activityScenarioRule.scenario.onActivity { traceId = motionToolManager.beginTrace(getActivityViewRootId()) val rootView = it.findViewById<View>(android.R.id.content) rootView.invalidate() } activityScenarioRule.scenario.onActivity { activity -> val traceId = motionToolManager.beginTrace(getActivityViewRootId()) Choreographer.getInstance().postFrameCallback { activity.findViewById<View>(android.R.id.content).viewTreeObserver.dispatchOnDraw() // waits until main looper has no remaining tasks and is idle activityScenarioRule.scenario.onActivity { val polledExportedData = motionToolManager.pollTrace(traceId) assertEquals(1, polledExportedData.frameData.size) Loading @@ -109,7 +94,7 @@ class MotionToolManagerTest { val endExportedData = motionToolManager.endTrace(traceId) assertEquals(0, endExportedData.frameData.size) } } } private fun getActivityViewRootId(): String { Loading
viewcapturelib/AndroidManifest.xml +3 −0 Original line number Diff line number Diff line Loading @@ -16,5 +16,8 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.android.app.viewcapture"> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions" /> </manifest>