From 360bf778f1e4c7195a3f106c1f11cb1a7ed3b6ed Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Mon, 20 Jan 2025 11:34:33 -0500 Subject: [PATCH] Convert WordPressDebug to Kotlin --- .../org/wordpress/android/WordPressDebug.kt | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt b/WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt index 05365be7ee12..f53c5d03cc85 100644 --- a/WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt +++ b/WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt @@ -1,51 +1,55 @@ -package org.wordpress.android; +package org.wordpress.android -import android.os.Build; -import android.os.StrictMode; -import android.os.StrictMode.VmPolicy; - -import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.AppLog.T; - -import dagger.hilt.android.HiltAndroidApp; +import android.os.Build +import android.os.StrictMode +import android.os.StrictMode.ThreadPolicy +import android.os.StrictMode.VmPolicy +import dagger.hilt.android.HiltAndroidApp +import org.wordpress.android.util.AppLog @HiltAndroidApp -public class WordPressDebug extends WordPressApp { - @Override - public void onCreate() { - super.onCreate(); - // TODO we'll want to comment this out before merging the Android 15 feature branch - enableStrictMode(); +class WordPressDebug : WordPressApp() { + override fun onCreate() { + super.onCreate() + // TODO comment this out before merging the Android 15 feature branch + enableStrictMode() } /** * enables "strict mode" for testing - should NEVER be used in release builds */ - private void enableStrictMode() { + private fun enableStrictMode() { // return if the build is not a debug build if (!BuildConfig.DEBUG) { - AppLog.e(T.UTILS, "You should not call enableStrictMode() on a non debug build"); - return; + AppLog.e(AppLog.T.UTILS, "You should not call enableStrictMode() on a non debug build") + return } - StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() - .detectDiskReads() - .detectDiskWrites() - .detectNetwork() - .penaltyLog() - .penaltyFlashScreen() - .build()); + StrictMode.setThreadPolicy( + ThreadPolicy.Builder() + .detectDiskReads() + .detectDiskWrites() + .detectNetwork() + .penaltyLog() + .penaltyFlashScreen() + .build() + ) - VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder() - .detectActivityLeaks() - .detectLeakedSqlLiteObjects() - .detectLeakedClosableObjects() - .detectLeakedRegistrationObjects() // <-- requires Jelly Bean - .penaltyLog(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - builder.detectNonSdkApiUsage(); - } - StrictMode.setVmPolicy(builder.build()); - AppLog.w(T.UTILS, "Strict mode enabled"); + StrictMode.setVmPolicy( + VmPolicy.Builder() + .detectActivityLeaks() + .detectLeakedSqlLiteObjects() + .detectLeakedClosableObjects() + .detectLeakedRegistrationObjects() + .penaltyLog() + .apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + detectNonSdkApiUsage() + } + } + .build() + ) + + AppLog.w(AppLog.T.UTILS, "Strict mode enabled") } }