Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Expand Up @@ -3,7 +3,7 @@ package org.oppia.android.app.administratorcontrols.learneranalytics
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Build
import android.util.Base64
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
Expand All @@ -20,7 +20,6 @@ import org.oppia.android.util.logging.SyncStatusManager
import org.oppia.android.util.logging.SyncStatusManager.SyncStatus
import java.io.ByteArrayOutputStream
import java.security.MessageDigest
import java.util.Base64
import java.util.zip.GZIPOutputStream
import javax.inject.Inject

Expand Down Expand Up @@ -229,11 +228,7 @@ class ControlButtonsViewModel private constructor(
val compressedMessage = ByteArrayOutputStream().also { byteOutputStream ->
GZIPOutputStream(byteOutputStream).use(::writeTo)
}.toByteArray()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Base64.getEncoder().encodeToString(compressedMessage)
} else {
android.util.Base64.encodeToString(compressedMessage, 0)
}
return Base64.encodeToString(compressedMessage, Base64.NO_WRAP)
}

private fun String.computeSha1Hash(machineLocale: OppiaLocale.MachineLocale): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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 @@ -74,7 +72,6 @@ import kotlin.reflect.KClass
* fields since there's no way to ensure what values those fields will 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 @@ -94,7 +91,6 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test

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,17 +180,15 @@ 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 }
field.getAnnotation(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 ->
method.fetchIterations().map { parameters ->
parameters.name to parameters.keyValuePairs.toList()
}.takeIf { it.isNotEmpty() }?.let { rawValues ->
val groupedValues = rawValues.groupBy({ it.first }, { it.second })
Expand All @@ -210,9 +204,25 @@ class OppiaParameterizedTestRunner(private val testClass: Class<*>) : Suite(test
}
}

@RequiresApi(Build.VERSION_CODES.N)
private fun Method.fetchIterations(): List<Iteration> {
val iterations = mutableListOf<Iteration>()
getAnnotation(Iteration::class.java)?.let { iterations.add(it) }
declaredAnnotations.forEach { annotation ->
try {
val valueMethod = annotation.annotationClass.java.getMethod("value")
val result = valueMethod.invoke(annotation)
val containerIterations = (result as? Array<*>)?.filterIsInstance<Iteration>()
if (containerIterations != null) {
iterations.addAll(containerIterations)
}
} catch (ignored: Exception) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this concern. Could you please update this logic so that unexpected reflection errors are not silently ignored? @Kishan8548

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
}
return iterations.distinct()
}

private fun fetchSelectedRunnerPlatformClass(): Class<*> {
return checkNotNull(testClass.getDeclaredAnnotation(SelectRunnerPlatform::class.java)) {
return checkNotNull(testClass.getAnnotation(SelectRunnerPlatform::class.java)) {
"All suites using OppiaParameterizedTestRunner must declare their base platform runner" +
" using SelectRunnerPlatform."
}.runnerType.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ private class LatexImageSpan(
override fun draw(canvas: Canvas) {}
override fun setAlpha(alpha: Int) {}
override fun setColorFilter(colorFilter: android.graphics.ColorFilter?) {}
// PixelFormat.TRANSPARENT is valid for an empty transparent drawable.
@Suppress("WrongConstant")
override fun getOpacity(): Int = android.graphics.PixelFormat.TRANSPARENT

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ abstract class SvgPictureDrawable(

override fun setColorFilter(colorFilter: ColorFilter?) { /* Unsupported. */ }

@Suppress("WrongConstant") // PixelFormat.TRANSLUCENT is valid for SVGs requiring alpha blending.
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

/**
Expand Down
Loading