From: Tobias Brunner Date: Fri, 30 May 2014 14:15:25 +0000 (+0200) Subject: android: Allow selection of local certificates X-Git-Tag: 5.2.1dr1~117^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f21a69dbece0bb1dd7ed720ddcb14fa8e1553fcf;p=thirdparty%2Fstrongswan.git android: Allow selection of local certificates --- diff --git a/src/frontends/android/res/values-de/strings.xml b/src/frontends/android/res/values-de/strings.xml index db76981351..1f283bbf5d 100644 --- a/src/frontends/android/res/values-de/strings.xml +++ b/src/frontends/android/res/values-de/strings.xml @@ -78,6 +78,7 @@ Keine Zertifikate System Benutzer + Importiert Status: diff --git a/src/frontends/android/res/values-pl/strings.xml b/src/frontends/android/res/values-pl/strings.xml index 7aa9c51a7f..8b13d4abee 100644 --- a/src/frontends/android/res/values-pl/strings.xml +++ b/src/frontends/android/res/values-pl/strings.xml @@ -78,6 +78,7 @@ Brak certyfikatów System Użytkownik + Imported Status: diff --git a/src/frontends/android/res/values-ru/strings.xml b/src/frontends/android/res/values-ru/strings.xml index 3838485afe..4a20a9b86e 100644 --- a/src/frontends/android/res/values-ru/strings.xml +++ b/src/frontends/android/res/values-ru/strings.xml @@ -75,6 +75,7 @@ Нет доступных сертификатов Система Пользователь + Imported Статус: diff --git a/src/frontends/android/res/values-ua/strings.xml b/src/frontends/android/res/values-ua/strings.xml index df016ff8ff..18759f3eac 100644 --- a/src/frontends/android/res/values-ua/strings.xml +++ b/src/frontends/android/res/values-ua/strings.xml @@ -76,6 +76,7 @@ Немає сертифікатів Система Користувач + Imported Статус: diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml index 1809489690..e5f47fc6cc 100644 --- a/src/frontends/android/res/values/strings.xml +++ b/src/frontends/android/res/values/strings.xml @@ -78,6 +78,7 @@ No certificates System User + Imported Status: diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java index 918393fe65..ba4445fcf6 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Tobias Brunner + * Copyright (C) 2012-2014 Tobias Brunner * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -46,9 +46,10 @@ import android.widget.SearchView.OnQueryTextListener; public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks>, OnQueryTextListener { + public static final String EXTRA_CERTIFICATE_SOURCE = "certificate_source"; private OnTrustedCertificateSelectedListener mListener; private TrustedCertificateAdapter mAdapter; - private boolean mUser; + private TrustedCertificateSource mSource = TrustedCertificateSource.SYSTEM; /** * The activity containing this fragment should implement this interface @@ -70,8 +71,11 @@ public class TrustedCertificateListFragment extends ListFragment implements Load setListShown(false); - /* non empty arguments mean we list user certificate */ - mUser = getArguments() != null; + Bundle arguments = getArguments(); + if (arguments != null) + { + mSource = (TrustedCertificateSource)arguments.getSerializable(EXTRA_CERTIFICATE_SOURCE); + } getLoaderManager().initLoader(0, null, this); } @@ -122,7 +126,7 @@ public class TrustedCertificateListFragment extends ListFragment implements Load @Override public Loader> onCreateLoader(int id, Bundle args) { /* we don't need the id as we have only one loader */ - return new CertificateListLoader(getActivity(), mUser); + return new CertificateListLoader(getActivity(), mSource); } @Override @@ -158,22 +162,21 @@ public class TrustedCertificateListFragment extends ListFragment implements Load public static class CertificateListLoader extends AsyncTaskLoader> { private List mData; - private final boolean mUser; + private final TrustedCertificateSource mSource; - public CertificateListLoader(Context context, boolean user) + public CertificateListLoader(Context context, TrustedCertificateSource source) { super(context); - mUser = user; + mSource = source; } @Override public List loadInBackground() { TrustedCertificateManager certman = TrustedCertificateManager.getInstance().load(); - Hashtable certificates; + Hashtable certificates = certman.getCACertificates(mSource); List selected; - certificates = mUser ? certman.getCACertificates(TrustedCertificateSource.USER) : certman.getCACertificates(TrustedCertificateSource.SYSTEM); selected = new ArrayList(); for (Entry entry : certificates.entrySet()) { diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java index 2874207e82..3ee3781964 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java @@ -17,6 +17,7 @@ package org.strongswan.android.ui; import org.strongswan.android.R; import org.strongswan.android.data.VpnProfileDataSource; +import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource; import org.strongswan.android.security.TrustedCertificateEntry; import android.app.ActionBar; @@ -43,11 +44,15 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert actionBar.addTab(actionBar .newTab() .setText(R.string.system_tab) - .setTabListener(new TrustedCertificatesTabListener(this, "system", false))); + .setTabListener(new TrustedCertificatesTabListener(this, "system", TrustedCertificateSource.SYSTEM))); actionBar.addTab(actionBar .newTab() .setText(R.string.user_tab) - .setTabListener(new TrustedCertificatesTabListener(this, "user", true))); + .setTabListener(new TrustedCertificatesTabListener(this, "user", TrustedCertificateSource.USER))); + actionBar.addTab(actionBar + .newTab() + .setText(R.string.local_tab) + .setTabListener(new TrustedCertificatesTabListener(this, "local", TrustedCertificateSource.LOCAL))); if (savedInstanceState != null) { @@ -87,13 +92,13 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert public static class TrustedCertificatesTabListener implements ActionBar.TabListener { private final String mTag; - private final boolean mUser; + private final TrustedCertificateSource mSource; private Fragment mFragment; - public TrustedCertificatesTabListener(Activity activity, String tag, boolean user) + public TrustedCertificatesTabListener(Activity activity, String tag, TrustedCertificateSource source) { mTag = tag; - mUser = user; + mSource = source; /* check to see if we already have a fragment for this tab, probably * from a previously saved state. if so, deactivate it, because the * initial state is that no tab is shown */ @@ -112,10 +117,9 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert if (mFragment == null) { mFragment = new TrustedCertificateListFragment(); - if (mUser) - { /* use non empty arguments to indicate this */ - mFragment.setArguments(new Bundle()); - } + Bundle args = new Bundle(); + args.putSerializable(TrustedCertificateListFragment.EXTRA_CERTIFICATE_SOURCE, mSource); + mFragment.setArguments(args); ft.add(android.R.id.content, mFragment, mTag); } else