vpn2: show third-party VPN services
VPN apps are shown alongside configured VPNs now. The requirement that a password is set is now only enforced when setting up a configured VPN as this is not necessary for apps. Some UI redesign. Bug: 19573824 Bug: 17474682 Bug: 19575658 Change-Id: I02bd977136929647d65b9784fb4cc5df24b45428
This commit is contained in:
136
src/com/android/settings/vpn2/AppDialogFragment.java
Normal file
136
src/com/android/settings/vpn2/AppDialogFragment.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.vpn2;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.IConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.net.VpnConfig;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Fragment wrapper around an {@link AppDialog}.
|
||||
*/
|
||||
public class AppDialogFragment extends DialogFragment implements AppDialog.Listener {
|
||||
private static final String TAG_APP_DIALOG = "vpnappdialog";
|
||||
private static final String TAG = "AppDialogFragment";
|
||||
|
||||
private static final String ARG_MANAGING = "managing";
|
||||
private static final String ARG_PACKAGE = "package";
|
||||
private static final String ARG_CONNECTED = "connected";
|
||||
|
||||
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
|
||||
public static void show(VpnSettings parent, PackageInfo pkgInfo, boolean managing,
|
||||
boolean connected) {
|
||||
if (!parent.isAdded()) return;
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_PACKAGE, pkgInfo);
|
||||
args.putBoolean(ARG_MANAGING, managing);
|
||||
args.putBoolean(ARG_CONNECTED, connected);
|
||||
|
||||
final AppDialogFragment frag = new AppDialogFragment();
|
||||
frag.setArguments(args);
|
||||
frag.setTargetFragment(parent, 0);
|
||||
frag.show(parent.getFragmentManager(), TAG_APP_DIALOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
PackageInfo pkgInfo = (PackageInfo) args.getParcelable(ARG_PACKAGE);
|
||||
boolean managing = args.getBoolean(ARG_MANAGING);
|
||||
boolean connected = args.getBoolean(ARG_CONNECTED);
|
||||
|
||||
if (managing) {
|
||||
return new AppDialog(getActivity(), this, pkgInfo, connected);
|
||||
} else {
|
||||
// Build an AlertDialog with an option to disconnect.
|
||||
|
||||
CharSequence vpnName;
|
||||
try {
|
||||
vpnName = VpnConfig.getVpnLabel(getActivity(), pkgInfo.packageName);
|
||||
} catch (PackageManager.NameNotFoundException ex) {
|
||||
vpnName = pkgInfo.packageName;
|
||||
}
|
||||
|
||||
AlertDialog.Builder dlog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(vpnName)
|
||||
.setMessage(getActivity().getString(R.string.vpn_disconnect_confirm))
|
||||
.setNegativeButton(getActivity().getString(R.string.vpn_cancel), null);
|
||||
|
||||
if (connected) {
|
||||
dlog.setPositiveButton(getActivity().getString(R.string.vpn_disconnect),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onDisconnect(dialog);
|
||||
}
|
||||
});
|
||||
}
|
||||
return dlog.create();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
((VpnSettings) getTargetFragment()).update();
|
||||
super.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
dismiss();
|
||||
super.onCancel(dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForget(final DialogInterface dialog) {
|
||||
PackageInfo pkgInfo = (PackageInfo) getArguments().getParcelable(ARG_PACKAGE);
|
||||
final String pkg = pkgInfo.packageName;
|
||||
try {
|
||||
VpnConfig vpnConfig = mService.getVpnConfig();
|
||||
if (vpnConfig != null && pkg.equals(vpnConfig.user) && !vpnConfig.legacy) {
|
||||
mService.setVpnPackageAuthorization(false);
|
||||
onDisconnect(dialog);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to forget authorization for " + pkg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void onDisconnect(final DialogInterface dialog) {
|
||||
PackageInfo pkgInfo = (PackageInfo) getArguments().getParcelable(ARG_PACKAGE);
|
||||
try {
|
||||
mService.prepareVpn(pkgInfo.packageName, VpnConfig.LEGACY_VPN);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to disconnect package " + pkgInfo.packageName, e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user