From 075d38117ae19ee8832f3f16eb9340a1786674b6 Mon Sep 17 00:00:00 2001 From: Bas Bosman Date: Fri, 19 Jan 2018 13:48:22 +0100 Subject: [PATCH] CB-13800: (android) Drop pre-KitKat specific code --- .../org/apache/cordova/CordovaActivity.java | 2 +- .../cordova/engine/SystemWebChromeClient.java | 15 ----- .../cordova/engine/SystemWebViewClient.java | 11 +--- .../cordova/engine/SystemWebViewEngine.java | 58 ++++--------------- 4 files changed, 13 insertions(+), 73 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index e2ed1cb8..dbbb48f6 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -123,7 +123,7 @@ public class CordovaActivity extends Activity { if (preferences.getBoolean("Fullscreen", false)) { // NOTE: use the FullscreenNotImmersive configuration key to set the activity in a REAL full screen // (as was the case in previous cordova versions) - if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && !preferences.getBoolean("FullscreenNotImmersive", false)) { + if (!preferences.getBoolean("FullscreenNotImmersive", false)) { immersiveMode = true; } else { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 3ea5e576..a27fc6af 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -149,21 +149,6 @@ public class SystemWebChromeClient extends WebChromeClient { quotaUpdater.updateQuota(MAX_QUOTA); } - // console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html - // Expect this to not compile in a future Android release! - @SuppressWarnings("deprecation") - @Override - public void onConsoleMessage(String message, int lineNumber, String sourceID) - { - //This is only for Android 2.1 - if(android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) - { - LOG.d(LOG_TAG, "%s: Line %d : %s", sourceID, lineNumber, message); - super.onConsoleMessage(message, lineNumber, sourceID); - } - } - - @TargetApi(8) @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index d1765024..0b6a577e 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java @@ -112,7 +112,7 @@ public class SystemWebViewClient extends WebViewClient { * @param request */ @Override - @TargetApi(21) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest (WebView view, ClientCertRequest request) { @@ -219,7 +219,6 @@ public class SystemWebViewClient extends WebViewClient { * @param handler An SslErrorHandler object that will handle the user's response. * @param error The SSL error object. */ - @TargetApi(8) @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { @@ -316,7 +315,6 @@ public class SystemWebViewClient extends WebViewClient { this.authenticationTokens.clear(); } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { @@ -349,7 +347,7 @@ public class SystemWebViewClient extends WebViewClient { } private static boolean needsKitKatContentUrlFix(Uri uri) { - return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && "content".equals(uri.getScheme()); + return "content".equals(uri.getScheme()); } private static boolean needsSpecialsInAssetUrlFix(Uri uri) { @@ -364,11 +362,6 @@ public class SystemWebViewClient extends WebViewClient { return false; } - switch(android.os.Build.VERSION.SDK_INT){ - case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH: - case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1: - return true; - } return false; } } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index d15b0eee..1cbd7f8b 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -121,9 +121,8 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); - if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) - nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); - bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); + nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); + bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); } @@ -153,26 +152,8 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); - // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2) - try { - Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class }); - - String manufacturer = android.os.Build.MANUFACTURER; - LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && - android.os.Build.MANUFACTURER.contains("HTC")) - { - gingerbread_getMethod.invoke(settings, true); - } - } catch (NoSuchMethodException e) { - LOG.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8"); - } catch (IllegalArgumentException e) { - LOG.d(TAG, "Doing the NavDump failed with bad arguments"); - } catch (IllegalAccessException e) { - LOG.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore"); - } catch (InvocationTargetException e) { - LOG.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore."); - } + String manufacturer = android.os.Build.MANUFACTURER; + LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); //We don't save any form data in the application settings.setSaveFormData(false); @@ -180,12 +161,9 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { - settings.setAllowUniversalAccessFromFileURLs(true); - } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { - settings.setMediaPlaybackRequiresUserGesture(false); - } + settings.setAllowUniversalAccessFromFileURLs(true); + settings.setMediaPlaybackRequiresUserGesture(false); + // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); @@ -195,8 +173,7 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { //Determine whether we're in debug or release mode, and turn on Debugging! ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo(); - if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && - android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { + if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { enableRemoteDebugging(); } @@ -244,7 +221,6 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { // end CB-1405 } - @TargetApi(Build.VERSION_CODES.KITKAT) private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); @@ -254,17 +230,9 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { } } - // Yeah, we know, which is why we makes ure that we don't do this if the bridge is - // below JELLYBEAN_MR1. It'd be great if lint was just a little smarter. + // Yeah, we know. It'd be great if lint was just a little smarter. @SuppressLint("AddJavascriptInterface") private static void exposeJsInterface(WebView webView, CordovaBridge bridge) { - if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)) { - LOG.i(TAG, "Disabled addJavascriptInterface() bridge since Android version is old."); - // Bug being that Java Strings do not get converted to JS strings automatically. - // This isn't hard to work-around on the JS side, but it's easier to just - // use the prompt bridge instead. - return; - } SystemExposedJsApi exposedJsApi = new SystemExposedJsApi(bridge); webView.addJavascriptInterface(exposedJsApi, "_cordovaNative"); } @@ -346,12 +314,6 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { @Override public void evaluateJavascript(String js, ValueCallback callback) { - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript(js, callback); - } - else - { - LOG.d(TAG, "This webview is using the old bridge"); - } + webView.evaluateJavascript(js, callback); } }