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 
17 package com.android.settings.vpn2;
18 
19 import android.app.AlertDialog;
20 import android.content.Context;
21 import android.content.DialogInterface;
22 import android.content.pm.PackageInfo;
23 import android.os.Bundle;
24 
25 import com.android.settings.R;
26 
27 /**
28  * UI for managing the connection controlled by an app.
29  *
30  * Among the actions available are (depending on context):
31  * <ul>
32  *   <li><strong>Forget</strong>: revoke the managing app's VPN permission</li>
33  *   <li><strong>Dismiss</strong>: continue to use the VPN</li>
34  * </ul>
35  *
36  * {@see ConfigDialog}
37  */
38 class AppDialog extends AlertDialog implements DialogInterface.OnClickListener {
39     private final Listener mListener;
40     private final PackageInfo mPackageInfo;
41     private final String mLabel;
42 
AppDialog(Context context, Listener listener, PackageInfo pkgInfo, String label)43     AppDialog(Context context, Listener listener, PackageInfo pkgInfo, String label) {
44         super(context);
45 
46         mListener = listener;
47         mPackageInfo = pkgInfo;
48         mLabel = label;
49     }
50 
getPackageInfo()51     public final PackageInfo getPackageInfo() {
52         return mPackageInfo;
53     }
54 
55     @Override
onCreate(Bundle savedState)56     protected void onCreate(Bundle savedState) {
57         setTitle(mLabel);
58         setMessage(getContext().getString(R.string.vpn_version, mPackageInfo.versionName));
59 
60         createButtons();
61         super.onCreate(savedState);
62     }
63 
createButtons()64     protected void createButtons() {
65         Context context = getContext();
66 
67         // Forget the network
68         setButton(DialogInterface.BUTTON_NEGATIVE,
69                 context.getString(R.string.vpn_forget), this);
70 
71         // Dismiss
72         setButton(DialogInterface.BUTTON_POSITIVE,
73                 context.getString(R.string.vpn_done), this);
74     }
75 
76     @Override
onClick(DialogInterface dialog, int which)77     public void onClick(DialogInterface dialog, int which) {
78         if (which == DialogInterface.BUTTON_NEGATIVE) {
79             mListener.onForget(dialog);
80         }
81         dismiss();
82     }
83 
84     public interface Listener {
onForget(DialogInterface dialog)85         public void onForget(DialogInterface dialog);
86     }
87 }
88