| Index: android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java b/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..83bd7e99cb494dc4fe09668b6363d72858b8a398
|
| --- /dev/null
|
| +++ b/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.android_webview;
|
| +
|
| +import android.content.Context;
|
| +import android.webkit.ValueCallback;
|
| +
|
| +import org.chromium.base.Log;
|
| +import org.chromium.base.annotations.JNINamespace;
|
| +
|
| +import java.lang.reflect.InvocationTargetException;
|
| +
|
| +/**
|
| + * Java twin of the homonymous C++ class. The Java side is only responsible for
|
| + * switching metrics on and off. Since the setting is a platform feature, it
|
| + * must be obtained through PlatformServiceBridge.
|
| + */
|
| +@JNINamespace("android_webview")
|
| +public class AwMetricsServiceClient {
|
| + private static final String TAG = "AwMetricsServiceClient";
|
| + private static final String PLATFORM_SERVICE_BRIDGE_CLASS =
|
| + "com.android.webview.chromium.PlatformServiceBridgeGoogle";
|
| +
|
| + private PlatformServiceBridge mPlatformServiceBridge;
|
| +
|
| + public AwMetricsServiceClient(Context applicationContext) {
|
| + mPlatformServiceBridge = getPlatformServiceBridge(applicationContext);
|
| +
|
| + mPlatformServiceBridge.setMetricsSettingListener(new ValueCallback<Boolean>() {
|
| + public void onReceiveValue(Boolean enabled) {
|
| + Log.d("aoeu", "AwMetricsServiceClient onReceiveValue " + enabled);
|
| + nativeSetMetricsEnabled(enabled.booleanValue());
|
| + }
|
| + });
|
| + }
|
| +
|
| + private static PlatformServiceBridge getPlatformServiceBridge(Context applicationContext) {
|
| + // If this is gmail, try to get the Google service bridge.
|
| + if ("com.google.android.gm".equals(applicationContext.getPackageName())) {
|
| + Log.i(TAG, "Package is gmail; getting " + PLATFORM_SERVICE_BRIDGE_CLASS);
|
| + try {
|
| + Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE_CLASS);
|
| + return (PlatformServiceBridge)
|
| + cls.getDeclaredConstructor(Context.class).newInstance(applicationContext);
|
| + } catch (InvocationTargetException e) {
|
| + Log.d(TAG, "instantiation failed invocation", e.getCause());
|
| + } catch (Exception e) {
|
| + Log.d(TAG, "instantiation failed", e);
|
| + }
|
| + }
|
| +
|
| + // If this is not gmail or getting the preferred service
|
| + // bridge failed, get the generic service bridge.
|
| + return new PlatformServiceBridge();
|
| + }
|
| +
|
| + public static native void nativeSetMetricsEnabled(boolean enabled);
|
| +}
|
|
|