-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
36 deletions.
There are no files selected for viewing
76 changes: 40 additions & 36 deletions
76
WordPress/src/debug/java/org/wordpress/android/WordPressDebug.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |