From 912db8daaf96d6bac929f6145f2b907d97c37a6e Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 29 May 2020 10:51:18 +0900 Subject: [PATCH] Don't use impl lib of android.test.[mock|base|runners] The java_sdk_library modules are now added with 'default_to_stubs: true' so that their impl libraries are not used even when the clients don't have sdk_version property set. This will allow us to replace the direct references to the stub libraries of the java_sdk_library modules with the references to the modules themselves (e.g. android.test.base.stubs -> android.test.base) in many of the CTS tests without unintentionally exposing the private APIs in the impl lib. As part of the change, MockContentProvider.getIContentProviderBinder() now returns an anonymous Binder object instead of throwing an exception. This is to eliminate the need for clients to override the now inaccessible method to escape from the exception. Also, InstrumentationTestRunner.addTestListener method is added to the stub because it is used by several tests (MtpServiceTests, etc.) Bug: 157007292 Test: m Merged-In: I14cf217f21fd3534c920c3a6336cf2d14c02e60c (cherry picked from commit b4e458d1063a3ece9a7f539ed6dbaeb6fb9c495d) Change-Id: I14cf217f21fd3534c920c3a6336cf2d14c02e60c --- test-base/Android.bp | 1 + test-mock/Android.bp | 1 + test-mock/src/android/test/mock/MockContentProvider.java | 3 ++- test-runner/Android.bp | 1 + test-runner/api/current.txt | 1 + test-runner/src/android/test/InstrumentationTestRunner.java | 1 - 6 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test-base/Android.bp b/test-base/Android.bp index 69c296e7ee9c..c7c9fc739189 100644 --- a/test-base/Android.bp +++ b/test-base/Android.bp @@ -38,6 +38,7 @@ java_sdk_library { ], compile_dex: true, + default_to_stubs: true, } // Build the android.test.base_static library diff --git a/test-mock/Android.bp b/test-mock/Android.bp index 248c117d2e03..7d0f92fac4c7 100644 --- a/test-mock/Android.bp +++ b/test-mock/Android.bp @@ -37,6 +37,7 @@ java_sdk_library { "android.test.mock", ], compile_dex: true, + default_to_stubs: true, } // Make the current.txt available for use by the cts/tests/signature tests. diff --git a/test-mock/src/android/test/mock/MockContentProvider.java b/test-mock/src/android/test/mock/MockContentProvider.java index e9a5ff70a7cc..3206adc31b98 100644 --- a/test-mock/src/android/test/mock/MockContentProvider.java +++ b/test-mock/src/android/test/mock/MockContentProvider.java @@ -29,6 +29,7 @@ import android.content.pm.ProviderInfo; import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; +import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.ICancellationSignal; @@ -282,7 +283,7 @@ public class MockContentProvider extends ContentProvider { * @hide */ public IBinder getIContentProviderBinder() { - throw new UnsupportedOperationException("unimplemented mock method"); + return new Binder(); } /** diff --git a/test-runner/Android.bp b/test-runner/Android.bp index 75f5b5a96eb1..1f6db8403eee 100644 --- a/test-runner/Android.bp +++ b/test-runner/Android.bp @@ -41,6 +41,7 @@ java_sdk_library { ], compile_dex: true, + default_to_stubs: true, } // Build the android.test.runner-minus-junit library diff --git a/test-runner/api/current.txt b/test-runner/api/current.txt index 2c19a2e85410..5407b685bb34 100644 --- a/test-runner/api/current.txt +++ b/test-runner/api/current.txt @@ -78,6 +78,7 @@ package android.test { @Deprecated public class InstrumentationTestRunner extends android.app.Instrumentation implements android.test.TestSuiteProvider { ctor @Deprecated public InstrumentationTestRunner(); + method @Deprecated protected void addTestListener(junit.framework.TestListener); method @Deprecated public junit.framework.TestSuite getAllTests(); method @Deprecated protected android.test.AndroidTestRunner getAndroidTestRunner(); method @Deprecated public android.os.Bundle getArguments(); diff --git a/test-runner/src/android/test/InstrumentationTestRunner.java b/test-runner/src/android/test/InstrumentationTestRunner.java index b2582c19b548..07e3f8736cc8 100644 --- a/test-runner/src/android/test/InstrumentationTestRunner.java +++ b/test-runner/src/android/test/InstrumentationTestRunner.java @@ -410,7 +410,6 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu /** * Add a {@link TestListener} - * @hide */ protected void addTestListener(TestListener listener){ if(mTestRunner!=null && listener!=null){