summaryrefslogtreecommitdiff
path: root/packages/VpnDialogs
diff options
context:
space:
mode:
authorFyodor Kupolov <fkupolov@google.com>2015-09-28 16:22:20 -0700
committerFyodor Kupolov <fkupolov@google.com>2015-10-02 16:13:05 -0700
commitca8594a3411f7aeaf5cd22e7e95a5b19f490ae6c (patch)
treed934ebfd2582fefb27bb3549228c9814ca9e54cd /packages/VpnDialogs
parente81b323af1cea0cbba80171968c27f6023ffc7e0 (diff)
Moved alert setup code to onCreate
setupAlert() was called multiple times and this was causing an error. Bug: 24412662 Change-Id: I5ff91f9f65d3298fc3b6996e147e3133c0bea882
Diffstat (limited to 'packages/VpnDialogs')
-rw-r--r--packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java75
1 files changed, 41 insertions, 34 deletions
diff --git a/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java b/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
index 48e05823f625..f0ca44162dad 100644
--- a/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
+++ b/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
@@ -18,8 +18,11 @@ package com.android.vpndialogs;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.IConnectivityManager;
+import android.os.Bundle;
+import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.text.Html;
@@ -40,43 +43,47 @@ public class ConfirmDialog extends AlertActivity
private IConnectivityManager mService;
- private Button mButton;
-
@Override
- protected void onResume() {
- super.onResume();
- try {
- mPackage = getCallingPackage();
-
- mService = IConnectivityManager.Stub.asInterface(
- ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
-
- if (mService.prepareVpn(mPackage, null, UserHandle.myUserId())) {
- setResult(RESULT_OK);
- finish();
- return;
- }
-
- View view = View.inflate(this, R.layout.confirm, null);
-
- ((TextView) view.findViewById(R.id.warning)).setText(
- Html.fromHtml(
- getString(R.string.warning, VpnConfig.getVpnLabel(this, mPackage)),
- this, null /* tagHandler */));
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mPackage = getCallingPackage();
+ mService = IConnectivityManager.Stub.asInterface(
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+
+ if (prepareVpn()) {
+ setResult(RESULT_OK);
+ finish();
+ return;
+ }
+ View view = View.inflate(this, R.layout.confirm, null);
+ ((TextView) view.findViewById(R.id.warning)).setText(
+ Html.fromHtml(getString(R.string.warning, getVpnLabel()),
+ this, null /* tagHandler */));
+ mAlertParams.mTitle = getText(R.string.prompt);
+ mAlertParams.mPositiveButtonText = getText(android.R.string.ok);
+ mAlertParams.mPositiveButtonListener = this;
+ mAlertParams.mNegativeButtonText = getText(android.R.string.cancel);
+ mAlertParams.mView = view;
+ setupAlert();
+
+ getWindow().setCloseOnTouchOutside(false);
+ Button button = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
+ button.setFilterTouchesWhenObscured(true);
+ }
- mAlertParams.mTitle = getText(R.string.prompt);
- mAlertParams.mPositiveButtonText = getText(android.R.string.ok);
- mAlertParams.mPositiveButtonListener = this;
- mAlertParams.mNegativeButtonText = getText(android.R.string.cancel);
- mAlertParams.mView = view;
- setupAlert();
+ private boolean prepareVpn() {
+ try {
+ return mService.prepareVpn(mPackage, null, UserHandle.myUserId());
+ } catch (RemoteException e) {
+ throw new IllegalStateException(e);
+ }
+ }
- getWindow().setCloseOnTouchOutside(false);
- mButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
- mButton.setFilterTouchesWhenObscured(true);
- } catch (Exception e) {
- Log.e(TAG, "onResume", e);
- finish();
+ private CharSequence getVpnLabel() {
+ try {
+ return VpnConfig.getVpnLabel(this, mPackage);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new IllegalStateException(e);
}
}