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 Ralf Sager
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -26,6 +26,7 @@ import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.VpnService;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -140,11 +141,25 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
|
||||
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
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
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:
|
||||
Intent certIntent = new Intent(this, TrustedCertificatesActivity.class);
|
||||
startActivity(certIntent);
|
||||
|
||||
+37
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Tobias Brunner
|
||||
* Copyright (C) 2016-2017 Tobias Brunner
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* 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.Loader;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.security.KeyChain;
|
||||
import android.security.KeyChainAliasCallback;
|
||||
@@ -75,7 +76,9 @@ import javax.net.ssl.SSLHandshakeException;
|
||||
public class VpnProfileImportActivity extends AppCompatActivity
|
||||
{
|
||||
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 OPEN_DOCUMENT = 1;
|
||||
private static final int PROFILE_LOADER = 0;
|
||||
private static final int USER_CERT_LOADER = 1;
|
||||
|
||||
@@ -107,7 +110,7 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
||||
@Override
|
||||
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
|
||||
@@ -197,16 +200,13 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action))
|
||||
{
|
||||
mProgress = ProgressDialog.show(this, null, getString(R.string.loading),
|
||||
true, true, new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
getLoaderManager().initLoader(PROFILE_LOADER, null, mProfileLoaderCallbacks);
|
||||
loadProfile(getIntent().getData());
|
||||
}
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
openIntent.setType("*/*");
|
||||
startActivityForResult(openIntent, OPEN_DOCUMENT);
|
||||
}
|
||||
|
||||
if (savedInstanceState != null)
|
||||
@@ -279,9 +279,34 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
||||
mImportUserCert.setEnabled(false);
|
||||
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)
|
||||
{
|
||||
mProgress.dismiss();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2012-2014 Tobias Brunner
|
||||
Copyright (C) 2012-2017 Tobias Brunner
|
||||
Hochschule fuer Technik Rapperswil
|
||||
|
||||
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"
|
||||
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
|
||||
android:id="@+id/menu_manage_certs"
|
||||
android:title="@string/trusted_certs_title"
|
||||
|
||||
Reference in New Issue
Block a user