Skip to content

Commit

Permalink
Convert WordPressDebug to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Jan 20, 2025
1 parent 1366005 commit 360bf77
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 360bf77

Please sign in to comment.