Skip to content

Commit

Permalink
Android: Apply new detekt-suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Sep 21, 2021
1 parent ba5b74e commit 7031a50
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 21 deletions.
Expand Up @@ -499,7 +499,7 @@ open class GleanInternalAPI internal constructor () {
val jsonRes = JSONObject(ptr.getAndConsumeRustString())
branchId = jsonRes.getString("branch")
extraMap = getMapFromJSONObject(jsonRes)
} catch (e: org.json.JSONException) {
} catch (_: org.json.JSONException) {
throw NullPointerException("Could not parse experiment data as JSON")
}

Expand Down
Expand Up @@ -63,7 +63,7 @@ class GleanDebugActivity : Activity() {
private fun isActivityExported(targetActivity: ComponentName): Boolean {
return try {
packageManager.getActivityInfo(targetActivity, PackageManager.GET_META_DATA).exported
} catch (e: PackageManager.NameNotFoundException) {
} catch (_: PackageManager.NameNotFoundException) {
false
}
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ data class DistributionData(
val jsonObject: JSONObject
try {
jsonObject = JSONObject(json)
} catch (e: org.json.JSONException) {
} catch (_: org.json.JSONException) {
return null
}

Expand All @@ -48,7 +48,7 @@ data class DistributionData(
valueMap[key.toLong()] = mapData.tryGetLong(key) ?: 0L
}
valueMap
} catch (e: org.json.JSONException) {
} catch (_: org.json.JSONException) {
// This should only occur if there isn't a key/value pair stored for "values"
return null
}
Expand Down
Expand Up @@ -278,7 +278,7 @@ class EventMetricType<ExtraKeysEnum : Enum<ExtraKeysEnum>, ExtraObject : EventEx

val jsonRes = try {
JSONArray(ptr.getAndConsumeRustString())
} catch (e: org.json.JSONException) {
} catch (_: org.json.JSONException) {
throw NullPointerException("Could not parse metric data as JSON")
}
if (jsonRes.length() == 0) {
Expand Down
Expand Up @@ -23,6 +23,7 @@ import mozilla.telemetry.glean.testing.ErrorType
* `$category.$name/$label`. The collect method knows how to pull these special values back
* out of the individual metric storage and rearrange them correctly in the ping.
*/
@Suppress("LongParameterList")
class LabeledMetricType<T>(
private val disabled: Boolean,
category: String,
Expand Down
Expand Up @@ -156,7 +156,7 @@ class StringListMetricType(
pingName)!!
try {
jsonRes = JSONArray(ptr.getAndConsumeRustString())
} catch (e: org.json.JSONException) {
} catch (_: org.json.JSONException) {
throw NullPointerException("Could not parse metric as JSON")
}
return jsonRes.toList()
Expand Down
Expand Up @@ -29,15 +29,20 @@ internal fun Byte.toBoolean(): Boolean = this != 0.toByte()
* THEY MUST BE THE SAME ACROSS BOTH FILES!
*/
class Constants {
private constructor() {
// hiding the constructor.
// intentionally left empty otherwise.
}

companion object {
// A recoverable error.
val UPLOAD_RESULT_RECOVERABLE: Int = 0x1
const val UPLOAD_RESULT_RECOVERABLE: Int = 0x1

// An unrecoverable error.
val UPLOAD_RESULT_UNRECOVERABLE: Int = 0x2
const val UPLOAD_RESULT_UNRECOVERABLE: Int = 0x2

// A HTTP response code.
val UPLOAD_RESULT_HTTP_STATUS: Int = 0x8000
const val UPLOAD_RESULT_HTTP_STATUS: Int = 0x8000
}
}

Expand Down Expand Up @@ -95,7 +100,7 @@ internal fun loadIndirect(libraryName: String): LibGleanFFI {
@Suppress("TooManyFunctions")
internal interface LibGleanFFI : Library {
companion object {
private val JNA_LIBRARY_NAME = "glean_ffi"
private const val JNA_LIBRARY_NAME = "glean_ffi"

internal var INSTANCE: LibGleanFFI = loadIndirect(JNA_LIBRARY_NAME)
}
Expand Down
Expand Up @@ -79,7 +79,7 @@ internal class MetricsPingScheduler(
// value.
return try {
date.time.toString()
} catch (e: AssertionError) {
} catch (_: AssertionError) {
"<buggy Android 8>"
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ internal class MetricsPingScheduler(
val currentVersion = buildInfo.versionName
val lastVersion = try {
sharedPreferences.getString(LAST_VERSION_OF_APP_USED, null)
} catch (e: ClassCastException) {
} catch (_: ClassCastException) {
null
}
if (currentVersion != lastVersion) {
Expand Down Expand Up @@ -323,7 +323,7 @@ internal class MetricsPingScheduler(
internal fun getLastCollectedDate(): Date? {
val loadedDate = try {
sharedPreferences.getString(LAST_METRICS_PING_SENT_DATETIME, null)
} catch (e: ClassCastException) {
} catch (_: ClassCastException) {
null
}

Expand Down
Expand Up @@ -177,7 +177,7 @@ class GleanTest {

// Suppressing our own deprecation before we move over to the new event recording API.
@Test
@Suppress("ComplexMethod", "LongMethod", "DEPRECATION")
@Suppress("ComplexMethod", "LongMethod", "NestedBlockDepth", "DEPRECATION")
fun `test sending of foreground and background pings`() {
val server = getMockWebServer()

Expand Down Expand Up @@ -218,7 +218,7 @@ class GleanTest {
// Trigger worker task to upload the pings in the background
triggerWorkManager(context)

for (i in 0..5) {
for (ignored in 0..5) {
val request = server.takeRequest(20L, TimeUnit.SECONDS)!!
val docType = request.path!!.split("/")[3]

Expand Down Expand Up @@ -327,7 +327,7 @@ class GleanTest {
Dispatchers.API.setTaskQueueing(true)

// This will queue 3 tasks that will add to the metric value once Glean is initialized
for (i in 0..2) {
for (ignored in 0..2) {
counterMetric.add()
}

Expand Down
Expand Up @@ -178,9 +178,9 @@ internal fun getWorkerStatus(context: Context, tag: String): WorkerStatus {
return WorkerStatus(true, workInfo.id)
}
}
} catch (e: ExecutionException) {
} catch (_: ExecutionException) {
// Do nothing but will return false
} catch (e: InterruptedException) {
} catch (_: InterruptedException) {
// Do nothing but will return false
}

Expand Down Expand Up @@ -332,7 +332,8 @@ fun waitForPingContent(
): JSONObject?
{
var parsedPayload: JSONObject? = null
for (attempts in 1..maxAttempts) {
@Suppress("LoopWithTooManyJumpStatements")
for (ignored in 1..maxAttempts) {
val request = server.takeRequest(20L, java.util.concurrent.TimeUnit.SECONDS) ?: break
val docType = request.path!!.split("/")[3]
if (pingName == docType) {
Expand Down
Expand Up @@ -245,7 +245,7 @@ class EventMetricTypeTest {
try {
eventMetric.testGetValue()
fail("Expected events to be empty")
} catch (e: NullPointerException) {
} catch (_: NullPointerException) {
}
Glean.setUploadEnabled(true)
eventMetric.record(mapOf(testNameKeys.testName to "event3"))
Expand Down
Expand Up @@ -13,6 +13,7 @@ import kotlin.reflect.KClass
inline fun <reified T : Any> argumentCaptor(): KArgumentCaptor<T> {
return KArgumentCaptor(ArgumentCaptor.forClass(T::class.java), T::class)
}
@Suppress("UnusedPrivateMember")
class KArgumentCaptor<out T : Any?>(
private val captor: ArgumentCaptor<T>,
private val tClass: KClass<*>
Expand Down
Expand Up @@ -70,7 +70,8 @@ fun waitForPingContent(
): JSONObject?
{
var parsedPayload: JSONObject? = null
for (attempts in 1..maxAttempts) {
@Suppress("LoopWithTooManyJumpStatements")
for (ignored in 1..maxAttempts) {
val request = server.takeRequest(20L, TimeUnit.SECONDS) ?: break
val docType = request.path!!.split("/")[3]
if (pingName == docType) {
Expand Down

0 comments on commit 7031a50

Please sign in to comment.