Skip to content

Commit f0eb740

Browse files
committed
Add lint check to ban usage of non-default @VisibleForTesting params
Suppresses existing API lint issues in modified libraries so that we can pass updateApi. Removes @VisibleForTesting annotations gated by @RestrictTo, which don't serve a practical purpose beyond documentation. Baselines rapidly-changing credential library so that we can actually get this landed. Bug: 277361353 Test: BanVisibleForTestingParamsTest Test: ./gradlew lintDebug Merged-In: Iece4b035e3796ff3f0516193bc1dbcde8aa1307c Change-Id: Iece4b035e3796ff3f0516193bc1dbcde8aa1307c
1 parent defa023 commit f0eb740

File tree

63 files changed

+2116
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2116
-270
lines changed

activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ import androidx.core.view.WindowInsetsControllerCompat
3434

3535
// The light scrim color used in the platform API 29+
3636
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/com/android/internal/policy/DecorView.java;drc=6ef0f022c333385dba2c294e35b8de544455bf19;l=142
37-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
37+
@VisibleForTesting
3838
internal val DefaultLightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
3939

4040
// The dark scrim color used in the platform.
4141
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/res/res/color/system_bar_background_semi_transparent.xml
4242
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/res/remote_color_resources_res/values/colors.xml;l=67
43-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
43+
@VisibleForTesting
4444
internal val DefaultDarkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
4545

4646
private var Impl: EdgeToEdgeImpl? = null

benchmark/benchmark-common/src/main/java/androidx/benchmark/BenchmarkState.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public class BenchmarkState internal constructor(
146146
* This value is overridden by the end of the warmup stage. The default value defines
147147
* behavior for modes that bypass warmup (dryRun and startup).
148148
*/
149-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
149+
@VisibleForTesting
150150
internal var iterationsPerRepeat = 1
151151

152152
private var state = NOT_STARTED // Current benchmark state.

buildSrc/private/src/main/kotlin/androidx/build/LintConfiguration.kt

+3
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ fun Project.configureLint(lint: Lint, extension: AndroidXExtension, isLibrary: B
231231
// Disable until ag/19949626 goes in (b/261918265)
232232
disable.add("MissingQuantity")
233233

234+
// Disable new lint check so that we can land incrementally.
235+
disable.add("VisibleForTests")
236+
234237
// Provide stricter enforcement for project types intended to run on a device.
235238
if (extension.type.compilationTarget == CompilationTarget.DEVICE) {
236239
fatal.add("Assert")

camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/interop/Camera2CameraControl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Camera2CameraControl
4949
private constructor(
5050
private val compat: Camera2CameraControlCompat,
5151
private val threads: UseCaseThreads,
52-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) internal val requestListener:
52+
@VisibleForTesting internal val requestListener:
5353
ComboRequestListener,
5454
) : UseCaseCameraControl {
5555

camera/camera-camera2/lint-baseline.xml

+9
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,13 @@
136136
file="src/main/java/androidx/camera/camera2/internal/ImageCaptureOptionUnpacker.java"/>
137137
</issue>
138138

139+
<issue
140+
id="VisibleForTests"
141+
message="This method should only be accessed from tests or within private scope"
142+
errorLine1=" characteristics = CameraCharacteristicsCompat.toCameraCharacteristicsCompat("
143+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
144+
<location
145+
file="src/main/java/androidx/camera/camera2/internal/compat/CameraManagerCompat.java"/>
146+
</issue>
147+
139148
</issues>

camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/compat/CameraCharacteristicsCompat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private CameraCharacteristicsCompat(@NonNull CameraCharacteristics cameraCharact
6262
* Tests might need to create CameraCharacteristicsCompat directly for convenience. Elsewhere
6363
* we should get the CameraCharacteristicsCompat instance from {@link CameraManagerCompat}.
6464
*/
65-
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
65+
@VisibleForTesting
6666
@NonNull
6767
public static CameraCharacteristicsCompat toCameraCharacteristicsCompat(
6868
@NonNull CameraCharacteristics characteristics, @NonNull String cameraId) {

compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/Animation.kt

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ fun <T, V : AnimationVector> Animation<T, V>.getVelocityFromNanos(playTimeNanos:
108108
* @param initialVelocity the initial velocity to start the animation at
109109
* @suppress
110110
*/
111-
/*@VisibleForTesting(otherwise = PACKAGE_PRIVATE)*/
112111
fun <V : AnimationVector> VectorizedAnimationSpec<V>.createAnimation(
113112
initialValue: V,
114113
targetValue: V,

compose/animation/animation-core/src/commonMain/kotlin/androidx/compose/animation/core/SpringEstimation.kt

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import kotlin.math.sqrt
2626
* Returns the estimated time that the spring will last be at [delta]
2727
* @suppress
2828
*/
29-
/*@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)*/
3029
fun estimateAnimationDurationMillis(
3130
stiffness: Float,
3231
dampingRatio: Float,
@@ -45,7 +44,6 @@ fun estimateAnimationDurationMillis(
4544
* Returns the estimated time that the spring will last be at [delta]
4645
* @suppress
4746
*/
48-
/*@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)*/
4947
fun estimateAnimationDurationMillis(
5048
stiffness: Double,
5149
dampingRatio: Double,
@@ -69,7 +67,6 @@ fun estimateAnimationDurationMillis(
6967
* Returns the estimated time that the spring will last be at [delta]
7068
* @suppress
7169
*/
72-
/*@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)*/
7370
fun estimateAnimationDurationMillis(
7471
springConstant: Double,
7572
dampingCoefficient: Double,

compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/ComposeRootRegistry.android.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal class ComposeRootRegistry {
6161
/**
6262
* Cleans up the changes made by [setupRegistry]. Call this after your test has run.
6363
*/
64-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
64+
@VisibleForTesting
6565
internal fun tearDownRegistry() {
6666
synchronized(lock) {
6767
// Stop accepting new roots

compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/IdlingResourceRegistry.jvm.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import kotlinx.coroutines.delay
2727
import kotlinx.coroutines.launch
2828

2929
internal class IdlingResourceRegistry
30-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
30+
@VisibleForTesting
3131
@InternalTestApi
3232
internal constructor(
3333
private val pollScopeOverride: CoroutineScope?

compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTextPaint.android.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class AndroidTextPaint(flags: Int, density: Float) : TextPaint(flags) {
4848

4949
private var textDecoration: TextDecoration = TextDecoration.None
5050

51-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
51+
@VisibleForTesting
5252
internal var shadow: Shadow = Shadow.None
5353

5454
private var drawStyle: DrawStyle? = null

compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeViewAccessibilityDelegateCompat.android.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import androidx.annotation.DoNotInline
4242
import androidx.annotation.IntRange
4343
import androidx.annotation.RequiresApi
4444
import androidx.annotation.VisibleForTesting
45-
import androidx.annotation.VisibleForTesting.Companion.PRIVATE
4645
import androidx.collection.ArrayMap
4746
import androidx.collection.ArraySet
4847
import androidx.collection.SparseArrayCompat
@@ -468,7 +467,7 @@ internal class AndroidComposeViewAccessibilityDelegateCompat(val view: AndroidCo
468467
position: Offset
469468
): Boolean = canScroll(currentSemanticsNodes.values, vertical, direction, position)
470469

471-
@VisibleForTesting(otherwise = PRIVATE)
470+
@VisibleForTesting
472471
internal fun canScroll(
473472
currentSemanticsNodes: Collection<SemanticsNodeWithAdjustedBounds>,
474473
vertical: Boolean,
@@ -2862,7 +2861,7 @@ internal class AndroidComposeViewAccessibilityDelegateCompat(val view: AndroidCo
28622861
}
28632862
}
28642863

2865-
@VisibleForTesting(otherwise = PRIVATE)
2864+
@VisibleForTesting
28662865
internal fun sendContentCaptureSemanticsStructureChangeEvents(
28672866
newNode: SemanticsNode,
28682867
oldNode: SemanticsNodeCopy

compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ internal class PopupLayout(
391391
private val windowManager =
392392
composeView.context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
393393

394-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
394+
@VisibleForTesting
395395
internal val params = createLayoutParams()
396396

397397
/** The logic of positioning the popup relative to its parent. */
@@ -616,7 +616,7 @@ internal class PopupLayout(
616616
* changed since the last call, calls [updatePosition] to actually calculate the popup's new
617617
* position and update the window.
618618
*/
619-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
619+
@VisibleForTesting
620620
internal fun updateParentBounds() {
621621
val coordinates = parentLayoutCoordinates ?: return
622622
val layoutSize = coordinates.size
@@ -752,7 +752,7 @@ internal class PopupLayout(
752752
* Collection of methods delegated to platform methods to support APIs only available on newer
753753
* platforms and testing.
754754
*/
755-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
755+
@VisibleForTesting
756756
internal interface PopupLayoutHelper {
757757
fun getWindowVisibleDisplayFrame(composeView: View, outRect: Rect)
758758
fun setGestureExclusionRects(composeView: View, width: Int, height: Int)

core/core/src/main/java/androidx/core/view/DisplayCutoutCompat.java

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public final class DisplayCutoutCompat {
5151
* @param boundingRects the bounding rects of the display cutouts as returned by
5252
* {@link #getBoundingRects()} ()}.
5353
*/
54-
// TODO(b/73953958): @VisibleForTesting(visibility = PRIVATE)
5554
public DisplayCutoutCompat(@Nullable Rect safeInsets, @Nullable List<Rect> boundingRects) {
5655
this(SDK_INT >= 28 ? Api28Impl.createDisplayCutout(safeInsets, boundingRects) : null);
5756
}

credentials/credentials-play-services-auth/lint-baseline.xml

+130-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<issue
1414
id="BanHideAnnotation"
1515
message="@hide is not allowed in Javadoc"
16-
errorLine1="open class CredentialProviderBaseController(private val activity: android.app.Activity) {"
16+
errorLine1="open class CredentialProviderBaseController(private val context: Context) {"
1717
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
1818
<location
1919
file="src/main/java/androidx/credentials/playservices/controllers/CredentialProviderBaseController.kt"/>
@@ -22,7 +22,7 @@
2222
<issue
2323
id="BanHideAnnotation"
2424
message="@hide is not allowed in Javadoc"
25-
errorLine1="class CredentialProviderBeginSignInController(private val activity: Activity) :"
25+
errorLine1="class CredentialProviderBeginSignInController(private val context: Context) :"
2626
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
2727
<location
2828
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
@@ -40,7 +40,7 @@
4040
<issue
4141
id="BanHideAnnotation"
4242
message="@hide is not allowed in Javadoc"
43-
errorLine1="class CredentialProviderCreatePasswordController(private val activity: Activity) :"
43+
errorLine1="class CredentialProviderCreatePasswordController(private val context: Context) :"
4444
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
4545
<location
4646
file="src/main/java/androidx/credentials/playservices/controllers/CreatePassword/CredentialProviderCreatePasswordController.kt"/>
@@ -49,7 +49,7 @@
4949
<issue
5050
id="BanHideAnnotation"
5151
message="@hide is not allowed in Javadoc"
52-
errorLine1="class CredentialProviderCreatePublicKeyCredentialController(private val activity: Activity) :"
52+
errorLine1="class CredentialProviderCreatePublicKeyCredentialController(private val context: Context) :"
5353
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
5454
<location
5555
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
@@ -91,4 +91,130 @@
9191
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/PublicKeyCredentialControllerUtility.kt"/>
9292
</issue>
9393

94+
<issue
95+
id="UsesNonDefaultVisibleForTesting"
96+
message="Found non-default `otherwise` value for @VisibleForTesting"
97+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
98+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
99+
<location
100+
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
101+
</issue>
102+
103+
<issue
104+
id="UsesNonDefaultVisibleForTesting"
105+
message="Found non-default `otherwise` value for @VisibleForTesting"
106+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
107+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
108+
<location
109+
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
110+
</issue>
111+
112+
<issue
113+
id="UsesNonDefaultVisibleForTesting"
114+
message="Found non-default `otherwise` value for @VisibleForTesting"
115+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
116+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
117+
<location
118+
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
119+
</issue>
120+
121+
<issue
122+
id="UsesNonDefaultVisibleForTesting"
123+
message="Found non-default `otherwise` value for @VisibleForTesting"
124+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
125+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
126+
<location
127+
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
128+
</issue>
129+
130+
<issue
131+
id="UsesNonDefaultVisibleForTesting"
132+
message="Found non-default `otherwise` value for @VisibleForTesting"
133+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
134+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
135+
<location
136+
file="src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/CredentialProviderBeginSignInController.kt"/>
137+
</issue>
138+
139+
<issue
140+
id="UsesNonDefaultVisibleForTesting"
141+
message="Found non-default `otherwise` value for @VisibleForTesting"
142+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
143+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
144+
<location
145+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePassword/CredentialProviderCreatePasswordController.kt"/>
146+
</issue>
147+
148+
<issue
149+
id="UsesNonDefaultVisibleForTesting"
150+
message="Found non-default `otherwise` value for @VisibleForTesting"
151+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
152+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
153+
<location
154+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePassword/CredentialProviderCreatePasswordController.kt"/>
155+
</issue>
156+
157+
<issue
158+
id="UsesNonDefaultVisibleForTesting"
159+
message="Found non-default `otherwise` value for @VisibleForTesting"
160+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
161+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
162+
<location
163+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePassword/CredentialProviderCreatePasswordController.kt"/>
164+
</issue>
165+
166+
<issue
167+
id="UsesNonDefaultVisibleForTesting"
168+
message="Found non-default `otherwise` value for @VisibleForTesting"
169+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
170+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
171+
<location
172+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePassword/CredentialProviderCreatePasswordController.kt"/>
173+
</issue>
174+
175+
<issue
176+
id="UsesNonDefaultVisibleForTesting"
177+
message="Found non-default `otherwise` value for @VisibleForTesting"
178+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
179+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
180+
<location
181+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
182+
</issue>
183+
184+
<issue
185+
id="UsesNonDefaultVisibleForTesting"
186+
message="Found non-default `otherwise` value for @VisibleForTesting"
187+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
188+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
189+
<location
190+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
191+
</issue>
192+
193+
<issue
194+
id="UsesNonDefaultVisibleForTesting"
195+
message="Found non-default `otherwise` value for @VisibleForTesting"
196+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)"
197+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
198+
<location
199+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
200+
</issue>
201+
202+
<issue
203+
id="UsesNonDefaultVisibleForTesting"
204+
message="Found non-default `otherwise` value for @VisibleForTesting"
205+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
206+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
207+
<location
208+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
209+
</issue>
210+
211+
<issue
212+
id="UsesNonDefaultVisibleForTesting"
213+
message="Found non-default `otherwise` value for @VisibleForTesting"
214+
errorLine1=" @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)"
215+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
216+
<location
217+
file="src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/CredentialProviderCreatePublicKeyCredentialController.kt"/>
218+
</issue>
219+
94220
</issues>

0 commit comments

Comments
 (0)