Commit 088e6832 authored by James Wallace-Lee's avatar James Wallace-Lee Committed by Commit Bot

Make PlatformServiceBridge instantiate PlatformServiceBridgeImpl

PlatformServiceBridge, instead of using reflection, should load
an instance of PlatformServiceBridgeImpl that is determined by GN.
A downstream cl, which should land first, provides an alternate
implementation of PlatformServiceBridgeImpl.

Bug: 682070
Change-Id: I642603ccb4e4dd4a602803772acd343bfe6cf0dd
Reviewed-on: https://chromium-review.googlesource.com/897994
Commit-Queue: James Wallace-Lee <jamwalla@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarPaul Miller <paulmiller@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540752}
parent 90f8a719
...@@ -941,15 +941,23 @@ java_strings_grd("strings_grd") { ...@@ -941,15 +941,23 @@ java_strings_grd("strings_grd") {
} }
# Separate target to allow for a dependency on GmsCore without pulling in all of # Separate target to allow for a dependency on GmsCore without pulling in all of
# android_webview_java. # android_webview_java. It compiles the abstract class; implementations are
# compiled separately.
android_library("android_webview_platform_services_java") { android_library("android_webview_platform_services_java") {
java_files = java_files = [
[ "java/src/org/chromium/android_webview/PlatformServiceBridge.java" ] "java/src/org/chromium/android_webview/PlatformServiceBridge.java",
"java/src/org/chromium/android_webview/PlatformServiceBridgeImpl.java",
]
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//third_party/android_tools:android_support_annotations_java", "//third_party/android_tools:android_support_annotations_java",
] ]
# The appropriate .class file will be loaded via a dependency to a library
# like :platform_service_bridge_upstream_implementation_java below. We only include the
# .java file because other files in the target depend on it.
jar_excluded_patterns = [ "*/PlatformServiceBridgeImpl.class" ]
} }
# This target compiles the implementation of PlatformServiceBridge for AOSP targets. # This target compiles the implementation of PlatformServiceBridge for AOSP targets.
...@@ -1010,6 +1018,7 @@ if (public_android_sdk) { ...@@ -1010,6 +1018,7 @@ if (public_android_sdk) {
android_manifest = system_webview_android_manifest android_manifest = system_webview_android_manifest
android_manifest_dep = ":system_webview_manifest" android_manifest_dep = ":system_webview_manifest"
deps = [ deps = [
":platform_service_bridge_upstream_implementation_java",
":system_webview_resources", ":system_webview_resources",
"//android_webview/glue", "//android_webview/glue",
"//android_webview/support_library:support_lib_glue_java", "//android_webview/support_library:support_lib_glue_java",
......
...@@ -8,17 +8,13 @@ import android.content.Context; ...@@ -8,17 +8,13 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.StrictModeContext;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import java.lang.reflect.InvocationTargetException;
/** /**
* This class manages platform-specific services. (i.e. Google Services) The platform * This class manages platform-specific services. (i.e. Google Services) The platform
* should extend this class and use this base class to fetch their specialized version. * should extend this class and use this base class to fetch their specialized version.
*/ */
public class PlatformServiceBridge { public abstract class PlatformServiceBridge {
private static final String TAG = "PlatformServiceBrid-"; private static final String TAG = "PlatformServiceBrid-";
private static final String PLATFORM_SERVICE_BRIDGE = private static final String PLATFORM_SERVICE_BRIDGE =
"com.android.webview.chromium.PlatformServiceBridgeGoogle"; "com.android.webview.chromium.PlatformServiceBridgeGoogle";
...@@ -31,27 +27,12 @@ public class PlatformServiceBridge { ...@@ -31,27 +27,12 @@ public class PlatformServiceBridge {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static PlatformServiceBridge getInstance() { public static PlatformServiceBridge getInstance() {
synchronized (sInstanceLock) { synchronized (sInstanceLock) {
if (sInstance != null) return sInstance; if (sInstance == null) {
// Load an instance of PlatformServiceBridgeImpl. Because this can change
// Try to get a specialized service bridge. Starting with Android O, failed reflection // depending on the GN configuration, this may not be the PlatformServiceBridgeImpl
// may cause file reads. The reflection will go away soon: https://crbug.com/682070 // defined upstream.
try (StrictModeContext unused = StrictModeContext.allowDiskReads()) { sInstance = new PlatformServiceBridgeImpl();
Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor().newInstance();
return sInstance;
} catch (ClassNotFoundException e) {
// This is not an error; it just means this device doesn't have specialized
// services.
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException
| NoSuchMethodException e) {
Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e);
} catch (InvocationTargetException e) {
Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + ": ",
e.getCause());
} }
// Otherwise, get the generic service bridge.
sInstance = new PlatformServiceBridge();
return sInstance; return sInstance;
} }
} }
......
...@@ -22,6 +22,7 @@ android_apk("webview_instrumentation_apk") { ...@@ -22,6 +22,7 @@ android_apk("webview_instrumentation_apk") {
":android_webview_apk_resources", ":android_webview_apk_resources",
"//android_webview:android_webview_java", "//android_webview:android_webview_java",
"//android_webview:locale_pak_assets", "//android_webview:locale_pak_assets",
"//android_webview:platform_service_bridge_upstream_implementation_java",
"//base:base_java", "//base:base_java",
"//base:base_java_test_support", "//base:base_java_test_support",
"//components/policy/android:policy_java_test_support", "//components/policy/android:policy_java_test_support",
......
...@@ -1115,6 +1115,7 @@ monochrome_public_apk_tmpl("monochrome_public_apk") { ...@@ -1115,6 +1115,7 @@ monochrome_public_apk_tmpl("monochrome_public_apk") {
deps = [ deps = [
":monochrome_java", ":monochrome_java",
"//android_webview:platform_service_bridge_upstream_implementation_java",
"//base:base_java", "//base:base_java",
"//chrome/android:app_hooks_java", "//chrome/android:app_hooks_java",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment