diff options
author | Jason Monk <jmonk@google.com> | 2016-05-06 15:09:32 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2016-05-11 11:20:55 -0400 |
commit | 751995428636c7f1434999233ccf6fb1e1bb1511 (patch) | |
tree | 4d8acc3c2dfef78e9798ccb7ffabaeaeeee6426b /src/com/android/settings/WebViewImplementation.java | |
parent | ab30931d4156afb8ee56c8df3b48fad4703712a7 (diff) | |
download | packages_apps_Settings-751995428636c7f1434999233ccf6fb1e1bb1511.tar.gz packages_apps_Settings-751995428636c7f1434999233ccf6fb1e1bb1511.tar.bz2 packages_apps_Settings-751995428636c7f1434999233ccf6fb1e1bb1511.zip |
Expose dialog for current webview setting.
Change-Id: I91c796b2c75c0ac8047ba0c2555a1036e8c6c616
Fixes: 28554048
Diffstat (limited to 'src/com/android/settings/WebViewImplementation.java')
-rw-r--r-- | src/com/android/settings/WebViewImplementation.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/com/android/settings/WebViewImplementation.java b/src/com/android/settings/WebViewImplementation.java new file mode 100644 index 0000000000..c949a39e35 --- /dev/null +++ b/src/com/android/settings/WebViewImplementation.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.android.settings; + +import android.annotation.Nullable; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnCancelListener; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnDismissListener; +import android.os.Bundle; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.os.UserManager; +import android.util.Log; +import android.webkit.IWebViewUpdateService; +import android.webkit.WebViewProviderInfo; +import com.android.internal.logging.MetricsProto.MetricsEvent; + +import java.util.ArrayList; + +public class WebViewImplementation extends InstrumentedActivity implements + OnCancelListener, OnDismissListener { + + private static final String TAG = "WebViewImplementation"; + + private IWebViewUpdateService mWebViewUpdateService; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (!UserManager.get(this).isAdminUser()) { + finish(); + return; + } + mWebViewUpdateService = + IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate")); + try { + WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages(); + if (providers == null) { + Log.e(TAG, "No WebView providers available"); + finish(); + return; + } + + String currentValue = mWebViewUpdateService.getCurrentWebViewPackageName(); + if (currentValue == null) { + currentValue = ""; + } + + int currentIndex = -1; + ArrayList<String> options = new ArrayList<>(); + final ArrayList<String> values = new ArrayList<>(); + for (WebViewProviderInfo provider : providers) { + if (Utils.isPackageEnabled(this, provider.packageName)) { + options.add(provider.description); + values.add(provider.packageName); + if (currentValue.contentEquals(provider.packageName)) { + currentIndex = values.size() - 1; + } + } + } + + new AlertDialog.Builder(this) + .setTitle(R.string.select_webview_provider_dialog_title) + .setSingleChoiceItems(options.toArray(new String[0]), currentIndex, + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + try { + mWebViewUpdateService.changeProviderAndSetting(values.get(which)); + } catch (RemoteException e) { + Log.w(TAG, "Problem reaching webviewupdate service", e); + } + finish(); + } + }).setNegativeButton(android.R.string.cancel, null) + .setOnCancelListener(this) + .setOnDismissListener(this) + .show(); + } catch (RemoteException e) { + Log.w(TAG, "Problem reaching webviewupdate service", e); + finish(); + } + } + + @Override + protected int getMetricsCategory() { + return MetricsEvent.WEBVIEW_IMPLEMENTATION; + } + + @Override + public void onCancel(DialogInterface dialog) { + finish(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + finish(); + } +} |