Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6580cf91 authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Moved alert setup code to onCreate"

parents 04ff54a1 ca8594a3
Loading
Loading
Loading
Loading
+41 −34
Original line number Diff line number Diff line
@@ -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,30 +43,22 @@ public class ConfirmDialog extends AlertActivity

    private IConnectivityManager mService;

    private Button mButton;

    @Override
    protected void onResume() {
        super.onResume();
        try {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPackage = getCallingPackage();

        mService = IConnectivityManager.Stub.asInterface(
                ServiceManager.getService(Context.CONNECTIVITY_SERVICE));

            if (mService.prepareVpn(mPackage, null, UserHandle.myUserId())) {
        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, VpnConfig.getVpnLabel(this, mPackage)),
                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;
@@ -72,11 +67,23 @@ public class ConfirmDialog extends AlertActivity
        setupAlert();

        getWindow().setCloseOnTouchOutside(false);
            mButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
            mButton.setFilterTouchesWhenObscured(true);
        } catch (Exception e) {
            Log.e(TAG, "onResume", e);
            finish();
        Button button = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
        button.setFilterTouchesWhenObscured(true);
    }

    private boolean prepareVpn() {
        try {
            return mService.prepareVpn(mPackage, null, UserHandle.myUserId());
        } catch (RemoteException e) {
            throw new IllegalStateException(e);
        }
    }

    private CharSequence getVpnLabel() {
        try {
            return VpnConfig.getVpnLabel(this, mPackage);
        } catch (PackageManager.NameNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }