mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Eliminate needless use of reflection
The minSdkVersion was recently increased from 8 to 15. WebSettings.setBlockNetworkLoads has been publicly available since API level 8 (Froyo). StrictMode has been publicly available since API level 9 (Gingerbread).
This commit is contained in:
parent
4955e34886
commit
e91e3f4e7d
@ -2,7 +2,6 @@
|
||||
package com.fsck.k9;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -25,6 +24,7 @@ import android.os.Debug;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.StrictMode;
|
||||
import android.text.format.Time;
|
||||
import android.util.Log;
|
||||
|
||||
@ -570,7 +570,10 @@ public class K9 extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
maybeSetupStrictMode();
|
||||
if (K9.DEVELOPER_MODE) {
|
||||
StrictMode.enableDefaults();
|
||||
}
|
||||
|
||||
PRNGFixes.apply();
|
||||
|
||||
super.onCreate();
|
||||
@ -817,24 +820,6 @@ public class K9 extends Application {
|
||||
K9.setUseFixedMessageViewTheme(sprefs.getBoolean("fixedMessageViewTheme", true));
|
||||
}
|
||||
|
||||
private void maybeSetupStrictMode() {
|
||||
if (!K9.DEVELOPER_MODE)
|
||||
return;
|
||||
|
||||
try {
|
||||
Class<?> strictMode = Class.forName("android.os.StrictMode");
|
||||
Method enableDefaults = strictMode.getMethod("enableDefaults");
|
||||
enableDefaults.invoke(strictMode);
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
// Discard , as it means we're not running on a device with strict mode
|
||||
Log.v(K9.LOG_TAG, "Failed to turn on strict mode", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* since Android invokes Application.onCreate() only after invoking all
|
||||
* other components' onCreate(), here is a way to notify interested
|
||||
@ -1174,19 +1159,6 @@ public class K9 extends Application {
|
||||
mMessageViewShowNext = messageViewShowNext;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> classObject, String methodName) {
|
||||
try {
|
||||
return classObject.getMethod(methodName, boolean.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.i(K9.LOG_TAG, "Can't get method " +
|
||||
classObject.toString() + "." + methodName);
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Error while using reflection to get method " +
|
||||
classObject.toString() + "." + methodName, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FontSizes getFontSizes() {
|
||||
return fontSizes;
|
||||
}
|
||||
|
@ -8,26 +8,15 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.helper.HtmlConverter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MessageWebView extends RigidWebView {
|
||||
|
||||
|
||||
/**
|
||||
* We use WebSettings.getBlockNetworkLoads() to prevent the WebView that displays email
|
||||
* bodies from loading external resources over the network. Unfortunately this method
|
||||
* isn't exposed via the official Android API. That's why we use reflection to be able
|
||||
* to call the method.
|
||||
*/
|
||||
public static final Method mGetBlockNetworkLoads = K9.getMethod(WebSettings.class, "setBlockNetworkLoads");
|
||||
|
||||
/**
|
||||
* Check whether the single column layout algorithm can be used on this version of Android.
|
||||
*
|
||||
@ -67,22 +56,13 @@ public class MessageWebView extends RigidWebView {
|
||||
* @param shouldBlockNetworkData True if network data should be blocked, false to allow network data.
|
||||
*/
|
||||
public void blockNetworkData(final boolean shouldBlockNetworkData) {
|
||||
// Sanity check to make sure we don't blow up.
|
||||
if (getSettings() == null) {
|
||||
return;
|
||||
}
|
||||
WebSettings webSettings = getSettings();
|
||||
|
||||
// Block network loads.
|
||||
if (mGetBlockNetworkLoads != null) {
|
||||
try {
|
||||
mGetBlockNetworkLoads.invoke(getSettings(), shouldBlockNetworkData);
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Error on invoking WebSettings.setBlockNetworkLoads()", e);
|
||||
}
|
||||
}
|
||||
webSettings.setBlockNetworkLoads(shouldBlockNetworkData);
|
||||
|
||||
// Block network images.
|
||||
getSettings().setBlockNetworkImage(shouldBlockNetworkData);
|
||||
webSettings.setBlockNetworkImage(shouldBlockNetworkData);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user