OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.android_webview; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.webkit.ValueCallback; |
| 9 |
| 10 import org.chromium.base.Log; |
| 11 |
| 12 import java.lang.reflect.InvocationTargetException; |
| 13 |
| 14 /** |
| 15 * This class manages platform-specific services. (i.e. Google Services) The pla
tform |
| 16 * should extend this class and use this base class to fetch their specialized v
ersion. |
| 17 */ |
| 18 public class PlatformServiceBridge { |
| 19 private static final String TAG = "PlatformServiceBrid-"; |
| 20 private static final String PLATFORM_SERVICE_BRIDGE = |
| 21 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; |
| 22 |
| 23 private static PlatformServiceBridge sInstance; |
| 24 |
| 25 protected PlatformServiceBridge() {} |
| 26 |
| 27 public static PlatformServiceBridge getInstance(Context applicationContext)
{ |
| 28 if (sInstance != null) { |
| 29 return sInstance; |
| 30 } |
| 31 |
| 32 // Try to get a specialized service bridge. |
| 33 try { |
| 34 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); |
| 35 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte
xt.class) |
| 36 .newInstance(applicationContext); |
| 37 return sInstance; |
| 38 } catch (ClassNotFoundException e) { |
| 39 // This is not an error; it just means this device doesn't have spec
ialized services. |
| 40 } catch (IllegalAccessException | IllegalArgumentException | Instantiati
onException |
| 41 | NoSuchMethodException e) { |
| 42 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); |
| 43 } catch (InvocationTargetException e) { |
| 44 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + "
:", e.getCause()); |
| 45 } |
| 46 |
| 47 // Otherwise, get the generic service bridge. |
| 48 sInstance = new PlatformServiceBridge(); |
| 49 return sInstance; |
| 50 } |
| 51 |
| 52 public void setMetricsSettingListener(ValueCallback<Boolean> callback) {} |
| 53 } |
OLD | NEW |