I saw your blog post. Since you only ever want to setup StrictMode at most once per Java file, would it make any sense to simplify the code to call for setup as follows?
Here's an alternate StrictModeWrapper:
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.StrictMode;
public class StrictModeWrapper {
public static void init(Context context) {
// check if android:debuggable is set to true
int applicationFlags = context.getApplicationInfo().flags;
if ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
}
}
From your code, you only need to do the following:
try {
StrictModeWrapper.init(this);
}
catch(Throwable throwable) {
Log.v("StrictMode", "... is not available. Punting...");
}
where this is the local context, such as your Activity or Application or whatever. This seems to work for pre-2.3 Android, and also gives you the power of using the other methods of the Builder classes to configure StrictMode exactly as you'd like.