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