Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java

Issue 2611883002: Prepare to call GMS APIs from WebView (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.pm.ApplicationInfo; 8 import android.content.pm.ApplicationInfo;
9 import android.content.pm.PackageManager; 9 import android.content.pm.PackageManager;
10 import android.webkit.ValueCallback; 10 import android.webkit.ValueCallback;
11 11
12 import org.chromium.base.Log; 12 import org.chromium.base.Log;
13 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
14 14
15 /** 15 /**
16 * Java twin of the homonymous C++ class. The Java side is only responsible for 16 * Java twin of the homonymous C++ class. The Java side is only responsible for
17 * switching metrics on and off. Since the setting is a platform feature, it 17 * switching metrics on and off. Since the setting is a platform feature, it
18 * must be obtained through PlatformServiceBridge. 18 * must be obtained through PlatformServiceBridge.
19 */ 19 */
20 @JNINamespace("android_webview") 20 @JNINamespace("android_webview")
21 public class AwMetricsServiceClient { 21 public class AwMetricsServiceClient {
22 private static final String TAG = "AwMetricsServiceCli-"; 22 private static final String TAG = "AwMetricsServiceCli-";
23 23
24 // Individual apps can use this meta-data tag in their manifest to opt out o f metrics 24 // Individual apps can use this meta-data tag in their manifest to opt out o f metrics
25 // reporting. See https://developer.android.com/reference/android/webkit/Web View.html 25 // reporting. See https://developer.android.com/reference/android/webkit/Web View.html
26 private static final String OPT_OUT_META_DATA_STR = "android.webkit.WebView. MetricsOptOut"; 26 private static final String OPT_OUT_META_DATA_STR = "android.webkit.WebView. MetricsOptOut";
27 27
28 private static boolean isAppOptedOut(Context applicationContext) { 28 private static boolean isAppOptedOut(Context appContext) {
29 try { 29 try {
30 ApplicationInfo info = applicationContext.getPackageManager().getApp licationInfo( 30 ApplicationInfo info = appContext.getPackageManager().getApplication Info(
31 applicationContext.getPackageName(), PackageManager.GET_META _DATA); 31 appContext.getPackageName(), PackageManager.GET_META_DATA);
32 if (info.metaData == null) { 32 if (info.metaData == null) {
33 // null means no such tag was found. 33 // null means no such tag was found.
34 return false; 34 return false;
35 } 35 }
36 // getBoolean returns false if the key is not found, which is what w e want. 36 // getBoolean returns false if the key is not found, which is what w e want.
37 return info.metaData.getBoolean(OPT_OUT_META_DATA_STR); 37 return info.metaData.getBoolean(OPT_OUT_META_DATA_STR);
38 } catch (PackageManager.NameNotFoundException e) { 38 } catch (PackageManager.NameNotFoundException e) {
39 // This should never happen. 39 // This should never happen.
40 Log.e(TAG, "App could not find itself by package name!"); 40 Log.e(TAG, "App could not find itself by package name!");
41 // The conservative thing is to assume the app HAS opted out. 41 // The conservative thing is to assume the app HAS opted out.
42 return true; 42 return true;
43 } 43 }
44 } 44 }
45 45
46 public AwMetricsServiceClient(Context applicationContext) { 46 public AwMetricsServiceClient(Context appContext) {
47 if (isAppOptedOut(applicationContext)) { 47 if (isAppOptedOut(appContext)) {
48 return; 48 return;
49 } 49 }
50 50
51 // Check if the user has consented. 51 // Check if the user has consented.
52 PlatformServiceBridge.getInstance(applicationContext) 52 PlatformServiceBridge.getInstance(appContext)
53 .setMetricsSettingListener(new ValueCallback<Boolean>() { 53 .queryMetricsEnabled(new ValueCallback<Boolean>() {
54 public void onReceiveValue(Boolean enabled) { 54 public void onReceiveValue(Boolean enabled) {
55 nativeSetMetricsEnabled(enabled); 55 nativeSetMetricsEnabled(enabled);
56 } 56 }
57 }); 57 });
58 } 58 }
59 59
60 public static native void nativeSetMetricsEnabled(boolean enabled); 60 public static native void nativeSetMetricsEnabled(boolean enabled);
61 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698