diff options
-rw-r--r-- | packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java | 75 |
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); } } |