Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5195: Fix RestrictedApi Errors #5348

Merged
merged 31 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3936364
Resolve the test build error
XichengSpencer Jul 4, 2023
ed714a6
Change 1 concatenate string to 3 seperate text view
XichengSpencer Sep 12, 2023
f1c1bac
format code
XichengSpencer Sep 12, 2023
31b6f53
Merge branch 'oppia:develop' into #3843
XichengSpencer Sep 13, 2023
24050dc
Change the corresponding test.
XichengSpencer Sep 14, 2023
3406c78
Merge branch 'develop' into #3843
adhiamboperes Sep 19, 2023
b1bfe10
Merge remote-tracking branch 'origin/#3843' into #3843
XichengSpencer Sep 19, 2023
9c56e24
Remove TODO
XichengSpencer Sep 20, 2023
8d9cf96
Merge branch 'develop' into #3843
XichengSpencer Sep 22, 2023
6fe9746
remove testAddProfileActivity_inputPin_configChange_downloadAccessSwi…
XichengSpencer Nov 15, 2023
1cbe96d
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Nov 15, 2023
582f69d
Merge branch 'develop' into #3843
adhiamboperes Dec 4, 2023
40c44df
Add comment to explain the negating logic
XichengSpencer Dec 7, 2023
6824346
Merge remote-tracking branch 'origin/#3843' into #3843
XichengSpencer Dec 7, 2023
ebe5a28
Merge branch 'develop' into #3843
adhiamboperes Dec 7, 2023
b4b5f10
Add new HtmlParser create method that use less variables
XichengSpencer Dec 19, 2023
4802202
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Dec 19, 2023
e40a900
Merge remote-tracking branch 'origin/#3843' into #3843
XichengSpencer Dec 19, 2023
c362a55
Merge branch 'oppia:develop' into #3843
XichengSpencer Jan 2, 2024
015b502
Remove customOppiaTagActionListener as input arg in HtmlParser.kt cre…
XichengSpencer Jan 8, 2024
698a0d1
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Jan 8, 2024
783432a
Merge remote-tracking branch 'origin/#3843' into #3843
XichengSpencer Jan 8, 2024
74b599c
Remove TODO list and updated unnamed variable in both create function
XichengSpencer Jan 16, 2024
2fc2da8
Fix all unnamed variables
XichengSpencer Jan 17, 2024
a489412
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Jan 17, 2024
0c1b62a
Add annotation for methods not compatible with <API 26
XichengSpencer Feb 23, 2024
22040e2
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Feb 23, 2024
3094158
Merge branch 'develop' into #3843
XichengSpencer Mar 4, 2024
e2c9ca4
Revert "Add annotation for methods not compatible with <API 26 There …
XichengSpencer Mar 26, 2024
e1b26d6
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
XichengSpencer Mar 26, 2024
f29e82d
Merge remote-tracking branch 'origin/#3843' into #3843
XichengSpencer Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.oppia.android.testing.espresso

import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.view.View
import androidx.annotation.RequiresApi
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
Expand All @@ -19,6 +21,7 @@ class GenericViewMatchers {
* Returns a [Matcher] that verifies a view has a fully opaque background. The view is expected
* to have a [GradientDrawable] background.
*/
@RequiresApi(Build.VERSION_CODES.N)
fun withOpaqueBackground(): Matcher<View> = withColorBackgroundMatching(
descriptionSuffix = "an opaque background"
) { color -> color?.extractAlpha() == 0xff }
Expand All @@ -27,6 +30,7 @@ class GenericViewMatchers {
* Returns a [Matcher] with the specified description suffix and color matcher, matching against
* filled background colors of views.
*/
@RequiresApi(Build.VERSION_CODES.N)
private fun withColorBackgroundMatching(
@Suppress("SameParameterValue") descriptionSuffix: String,
colorMatcher: (Long?) -> Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.oppia.android.testing.junit

import android.os.Build
import androidx.annotation.RequiresApi
import org.junit.runner.Description
import org.junit.runner.Runner
import org.junit.runner.manipulation.Filter
Expand Down Expand Up @@ -76,6 +78,7 @@ import kotlin.reflect.KClass
* contain (thus they should be treated as undefined outside of tests that specific define their
* value via [Iteration]).
*/
@RequiresApi(Build.VERSION_CODES.N)
class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(testClass, listOf()) {
private val parameterizedMethods = computeParameterizedMethods()
private val selectedRunnerClass by lazy { fetchSelectedRunnerPlatformClass() }
Expand All @@ -85,16 +88,24 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
parameterizedMethods.flatMap { (methodName, method) ->
method.iterationNames.map { iterationName ->
ProxyParameterizedTestRunner(
selectedRunnerClass, testClass, parameterizedMethods, methodName, iterationName
selectedRunnerClass,
testClass,
parameterizedMethods,
methodName,
iterationName
)
}
} + ProxyParameterizedTestRunner(
selectedRunnerClass, testClass, parameterizedMethods, methodName = null
selectedRunnerClass,
testClass,
parameterizedMethods,
methodName = null
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
}

override fun getChildren(): MutableList<Runner> = childrenRunners.toMutableList()

@RequiresApi(Build.VERSION_CODES.N)
private fun computeParameterizedMethods(): Map<String, ParameterizedMethod> {
val fieldsAndParsers = fetchParameterizedFields().map { field ->
val valueParser = ParameterValue.createParserForField(field)
Expand Down Expand Up @@ -184,12 +195,14 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
}.associateBy { it.methodName }
}

@RequiresApi(Build.VERSION_CODES.N)
private fun fetchParameterizedFields(): List<Field> {
return testClass.declaredFields.mapNotNull { field ->
field.getDeclaredAnnotation(Parameter::class.java)?.let { field }
}
}

@RequiresApi(Build.VERSION_CODES.N)
private fun fetchParameterizedMethodDeclarations(): List<ParameterizedMethodDeclaration> {
return testClass.declaredMethods.mapNotNull { method ->
method.getDeclaredAnnotationsByType(Iteration::class.java).map { parameters ->
Expand All @@ -208,6 +221,7 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
}
}

@RequiresApi(Build.VERSION_CODES.N)
private fun fetchSelectedRunnerPlatformClass(): Class<*> {
return checkNotNull(testClass.getDeclaredAnnotation(SelectRunnerPlatform::class.java)) {
"All suites using OppiaParameterizedTestRunner must declare their base platform runner" +
Expand Down Expand Up @@ -239,15 +253,17 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
* - [Float]s
* - [Double]s
*/
@Target(AnnotationTarget.FIELD) annotation class Parameter
@Target(AnnotationTarget.FIELD)
annotation class Parameter

/**
* Specifies that a method in a test that uses a [OppiaParameterizedTestRunner] runner should be
* run multiple times for each [Iteration] specified in the [value] iterations list.
*
* See the KDoc for the runner for example code.
*/
@Target(AnnotationTarget.FUNCTION) annotation class RunParameterized(vararg val value: Iteration)
@Target(AnnotationTarget.FUNCTION)
annotation class RunParameterized(vararg val value: Iteration)
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

// TODO(#4120): Migrate to Kotlin @Repeatable once Kotlin 1.6 is used (see:
// https://youtrack.jetbrains.com/issue/KT-12794).
Expand Down Expand Up @@ -300,7 +316,10 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
private fun constructDelegate(): Any {
val constructor =
runnerClass.getConstructor(
Class::class.java, Map::class.java, String::class.java, String::class.java
Class::class.java,
Map::class.java,
String::class.java,
String::class.java
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
return constructor.newInstance(testClass, parameterizedMethods, methodName, iterationName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.oppia.android.testing.threading

import android.os.Build
import androidx.annotation.RequiresApi
import org.oppia.android.testing.time.FakeSystemClock
import java.lang.reflect.Method
import java.time.Duration
Expand Down Expand Up @@ -34,6 +36,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
} while (hasPendingCompletableTasks())
}

@RequiresApi(Build.VERSION_CODES.O)
override fun advanceTimeBy(delayTimeMillis: Long) {
var remainingDelayMillis = delayTimeMillis
while (remainingDelayMillis > 0) {
Expand All @@ -49,6 +52,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
}
}

@RequiresApi(Build.VERSION_CODES.O)
override fun advanceUntilIdle() {
// First, run through all tasks that are currently pending and can be run immediately.
runCurrent()
Expand All @@ -67,6 +71,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun advanceToNextFutureTask(
currentTimeMillis: Long,
maxDelayMs: Long = Long.MAX_VALUE
Expand Down Expand Up @@ -94,6 +99,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
}

/** Returns whether any of the dispatchers have any tasks to run, including in the future. */
@RequiresApi(Build.VERSION_CODES.O)
private fun hasPendingTasks(): Boolean {
return backgroundTestDispatcher.hasPendingTasks() ||
blockingTestDispatcher.hasPendingTasks() ||
Expand All @@ -107,6 +113,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
!uiTaskCoordinator.isIdle()
}

@RequiresApi(Build.VERSION_CODES.O)
private fun getNextFutureTaskTimeMillis(timeMillis: Long): Long? {
val nextBackgroundFutureTaskTimeMills =
backgroundTestDispatcher.getNextFutureTaskCompletionTimeMillis(timeMillis)
Expand All @@ -120,6 +127,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
return futureTimes.firstOrNull()
}

@RequiresApi(Build.VERSION_CODES.O)
private fun getNextUiThreadFutureTaskTimeMillis(timeMillis: Long): Long? {
return uiTaskCoordinator.getNextUiThreadFutureTaskTimeMillis(timeMillis)
}
Expand All @@ -139,6 +147,7 @@ class TestCoroutineDispatchersRobolectricImpl @Inject constructor(
idleMethod.invoke(shadowUiLooper)
}

@RequiresApi(Build.VERSION_CODES.O)
fun getNextUiThreadFutureTaskTimeMillis(timeMillis: Long): Long? {
val nextScheduledTime = nextScheduledTimeMethod.invoke(shadowUiLooper) as Duration
val delayMs = nextScheduledTime.toMillis()
Expand Down
Loading