2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
15 package com.android.settings;
17 import android.annotation.Nullable;
18 import android.app.AlertDialog;
19 import android.content.DialogInterface;
20 import android.content.DialogInterface.OnCancelListener;
21 import android.content.DialogInterface.OnClickListener;
22 import android.content.DialogInterface.OnDismissListener;
23 import android.os.Bundle;
24 import android.os.RemoteException;
25 import android.os.ServiceManager;
26 import android.os.UserManager;
27 import android.util.Log;
28 import android.webkit.IWebViewUpdateService;
29 import android.webkit.WebViewProviderInfo;
30 import com.android.internal.logging.MetricsProto.MetricsEvent;
32 import java.util.ArrayList;
34 public class WebViewImplementation extends InstrumentedActivity implements
35 OnCancelListener, OnDismissListener {
37 private static final String TAG = "WebViewImplementation";
39 private IWebViewUpdateService mWebViewUpdateService;
42 protected void onCreate(@Nullable Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44 if (!UserManager.get(this).isAdminUser()) {
48 mWebViewUpdateService =
49 IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
51 WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
52 if (providers == null) {
53 Log.e(TAG, "No WebView providers available");
58 String currentValue = mWebViewUpdateService.getCurrentWebViewPackageName();
59 if (currentValue == null) {
63 int currentIndex = -1;
64 ArrayList<String> options = new ArrayList<>();
65 final ArrayList<String> values = new ArrayList<>();
66 for (WebViewProviderInfo provider : providers) {
67 if (Utils.isPackageEnabled(this, provider.packageName)) {
68 options.add(provider.description);
69 values.add(provider.packageName);
70 if (currentValue.contentEquals(provider.packageName)) {
71 currentIndex = values.size() - 1;
76 new AlertDialog.Builder(this)
77 .setTitle(R.string.select_webview_provider_dialog_title)
78 .setSingleChoiceItems(options.toArray(new String[0]), currentIndex,
79 new OnClickListener() {
81 public void onClick(DialogInterface dialog, int which) {
83 mWebViewUpdateService.changeProviderAndSetting(values.get(which));
84 } catch (RemoteException e) {
85 Log.w(TAG, "Problem reaching webviewupdate service", e);
89 }).setNegativeButton(android.R.string.cancel, null)
90 .setOnCancelListener(this)
91 .setOnDismissListener(this)
93 } catch (RemoteException e) {
94 Log.w(TAG, "Problem reaching webviewupdate service", e);
100 protected int getMetricsCategory() {
101 return MetricsEvent.WEBVIEW_IMPLEMENTATION;
105 public void onCancel(DialogInterface dialog) {
110 public void onDismiss(DialogInterface dialog) {