1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.vpn2;
18
19import android.app.AlertDialog;
20import android.content.Context;
21import android.content.DialogInterface;
22import android.content.pm.PackageInfo;
23import android.content.pm.PackageManager;
24import android.os.Bundle;
25import android.view.View;
26import android.widget.TextView;
27
28import com.android.internal.net.VpnConfig;
29import com.android.settings.R;
30
31/**
32 * UI for managing the connection controlled by an app.
33 *
34 * Among the actions available are (depending on context):
35 * <ul>
36 *   <li><strong>Forget</strong>: revoke the managing app's VPN permission</li>
37 *   <li><strong>Dismiss</strong>: continue to use the VPN</li>
38 * </ul>
39 *
40 * {@see ConfigDialog}
41 */
42class AppDialog extends AlertDialog implements DialogInterface.OnClickListener {
43    private final Listener mListener;
44    private final PackageInfo mPackageInfo;
45    private final String mLabel;
46
47    AppDialog(Context context, Listener listener, PackageInfo pkgInfo, String label) {
48        super(context);
49
50        mListener = listener;
51        mPackageInfo = pkgInfo;
52        mLabel = label;
53    }
54
55    public final PackageInfo getPackageInfo() {
56        return mPackageInfo;
57    }
58
59    @Override
60    protected void onCreate(Bundle savedState) {
61        setTitle(mLabel);
62        setMessage(getContext().getString(R.string.vpn_version, mPackageInfo.versionName));
63
64        createButtons();
65        super.onCreate(savedState);
66    }
67
68    protected void createButtons() {
69        Context context = getContext();
70
71        // Forget the network
72        setButton(DialogInterface.BUTTON_NEGATIVE,
73                context.getString(R.string.vpn_forget), this);
74
75        // Dismiss
76        setButton(DialogInterface.BUTTON_POSITIVE,
77                context.getString(R.string.vpn_done), this);
78    }
79
80    @Override
81    public void onClick(DialogInterface dialog, int which) {
82        if (which == DialogInterface.BUTTON_NEGATIVE) {
83            mListener.onForget(dialog);
84        }
85        dismiss();
86    }
87
88    public interface Listener {
89        public void onForget(DialogInterface dialog);
90    }
91}
92