/*
- * 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
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;
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);
/*
- * 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
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;
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;
@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
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)
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();
<?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
<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"