android: Add menu item to import VPN profile via Storage Access Framework
This is useful in case the proper MIME type was not set for a downloaded profile.
This commit is contained in:
+16
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012 Tobias Brunner
|
* Copyright (C) 2012-2017 Tobias Brunner
|
||||||
* Copyright (C) 2012 Giuliano Grassi
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
* Copyright (C) 2012 Ralf Sager
|
* Copyright (C) 2012 Ralf Sager
|
||||||
* Hochschule fuer Technik Rapperswil
|
* Hochschule fuer Technik Rapperswil
|
||||||
@@ -26,6 +26,7 @@ import android.content.Intent;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -140,11 +141,25 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
|
||||||
|
{
|
||||||
|
menu.removeItem(R.id.menu_import_profile);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
switch (item.getItemId())
|
switch (item.getItemId())
|
||||||
{
|
{
|
||||||
|
case R.id.menu_import_profile:
|
||||||
|
Intent intent = new Intent(this, VpnProfileImportActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
case R.id.menu_manage_certs:
|
case R.id.menu_manage_certs:
|
||||||
Intent certIntent = new Intent(this, TrustedCertificatesActivity.class);
|
Intent certIntent = new Intent(this, TrustedCertificatesActivity.class);
|
||||||
startActivity(certIntent);
|
startActivity(certIntent);
|
||||||
|
|||||||
+37
-12
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Tobias Brunner
|
* Copyright (C) 2016-2017 Tobias Brunner
|
||||||
* HSR Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
@@ -25,6 +25,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.Loader;
|
import android.content.Loader;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.security.KeyChain;
|
import android.security.KeyChain;
|
||||||
import android.security.KeyChainAliasCallback;
|
import android.security.KeyChainAliasCallback;
|
||||||
@@ -75,7 +76,9 @@ import javax.net.ssl.SSLHandshakeException;
|
|||||||
public class VpnProfileImportActivity extends AppCompatActivity
|
public class VpnProfileImportActivity extends AppCompatActivity
|
||||||
{
|
{
|
||||||
private static final String PKCS12_INSTALLED = "PKCS12_INSTALLED";
|
private static final String PKCS12_INSTALLED = "PKCS12_INSTALLED";
|
||||||
|
private static final String PROFILE_URI = "PROFILE_URI";
|
||||||
private static final int INSTALL_PKCS12 = 0;
|
private static final int INSTALL_PKCS12 = 0;
|
||||||
|
private static final int OPEN_DOCUMENT = 1;
|
||||||
private static final int PROFILE_LOADER = 0;
|
private static final int PROFILE_LOADER = 0;
|
||||||
private static final int USER_CERT_LOADER = 1;
|
private static final int USER_CERT_LOADER = 1;
|
||||||
|
|
||||||
@@ -107,7 +110,7 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
public Loader<ProfileLoadResult> onCreateLoader(int id, Bundle args)
|
public Loader<ProfileLoadResult> onCreateLoader(int id, Bundle args)
|
||||||
{
|
{
|
||||||
return new ProfileLoader(VpnProfileImportActivity.this, getIntent().getData());
|
return new ProfileLoader(VpnProfileImportActivity.this, (Uri)args.getParcelable(PROFILE_URI));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -197,16 +200,13 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (Intent.ACTION_VIEW.equals(action))
|
if (Intent.ACTION_VIEW.equals(action))
|
||||||
{
|
{
|
||||||
mProgress = ProgressDialog.show(this, null, getString(R.string.loading),
|
loadProfile(getIntent().getData());
|
||||||
true, true, new DialogInterface.OnCancelListener() {
|
}
|
||||||
@Override
|
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||||
public void onCancel(DialogInterface dialog)
|
{
|
||||||
{
|
Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||||
finish();
|
openIntent.setType("*/*");
|
||||||
}
|
startActivityForResult(openIntent, OPEN_DOCUMENT);
|
||||||
});
|
|
||||||
|
|
||||||
getLoaderManager().initLoader(PROFILE_LOADER, null, mProfileLoaderCallbacks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
@@ -279,9 +279,34 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
mImportUserCert.setEnabled(false);
|
mImportUserCert.setEnabled(false);
|
||||||
mSelectUserCert.performClick();
|
mSelectUserCert.performClick();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case OPEN_DOCUMENT:
|
||||||
|
if (resultCode == Activity.RESULT_OK && data != null)
|
||||||
|
{
|
||||||
|
loadProfile(data.getData());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadProfile(Uri uri)
|
||||||
|
{
|
||||||
|
mProgress = ProgressDialog.show(this, null, getString(R.string.loading),
|
||||||
|
true, true, new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog)
|
||||||
|
{
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable(PROFILE_URI, uri);
|
||||||
|
getLoaderManager().initLoader(PROFILE_LOADER, args, mProfileLoaderCallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
public void handleProfile(ProfileLoadResult data)
|
public void handleProfile(ProfileLoadResult data)
|
||||||
{
|
{
|
||||||
mProgress.dismiss();
|
mProgress.dismiss();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2012-2014 Tobias Brunner
|
Copyright (C) 2012-2017 Tobias Brunner
|
||||||
Hochschule fuer Technik Rapperswil
|
Hochschule fuer Technik Rapperswil
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
||||||
@@ -16,6 +16,11 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_import_profile"
|
||||||
|
android:title="@string/profile_import"
|
||||||
|
app:showAsAction="withText" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_manage_certs"
|
android:id="@+id/menu_manage_certs"
|
||||||
android:title="@string/trusted_certs_title"
|
android:title="@string/trusted_certs_title"
|
||||||
|
|||||||
Reference in New Issue
Block a user