From: Tobias Brunner Date: Tue, 27 Jun 2017 13:17:43 +0000 (+0200) Subject: android: Make app handling and selection of apps configurable in profile editor X-Git-Tag: 5.6.0dr1~24^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=291ef58c69d62ad5aed1817ec9ee7ee9ac3b842f;p=thirdparty%2Fstrongswan.git android: Make app handling and selection of apps configurable in profile editor --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java index d495b742a6..0bae6142d9 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2016 Tobias Brunner + * Copyright (C) 2012-2017 Tobias Brunner * Copyright (C) 2012 Giuliano Grassi * Copyright (C) 2012 Ralf Sager * HSR Hochschule fuer Technik Rapperswil @@ -57,6 +57,7 @@ import android.widget.TextView; import org.strongswan.android.R; import org.strongswan.android.data.VpnProfile; +import org.strongswan.android.data.VpnProfile.SelectedAppsHandling; import org.strongswan.android.data.VpnProfileDataSource; import org.strongswan.android.data.VpnType; import org.strongswan.android.data.VpnType.VpnTypeFeature; @@ -68,11 +69,15 @@ import org.strongswan.android.utils.Constants; import org.strongswan.android.utils.IPRangeSet; import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.UUID; public class VpnProfileDetailActivity extends AppCompatActivity { private static final int SELECT_TRUSTED_CERTIFICATE = 0; + private static final int SELECT_APPLICATIONS = 1; private VpnProfileDataSource mDataSource; private Long mId; @@ -82,6 +87,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity private String mSelectedUserId; private TrustedCertificateEntry mUserCertEntry; private VpnType mVpnType = VpnType.IKEV2_EAP; + private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE; + private SortedSet mSelectedApps = new TreeSet<>(); private VpnProfile mProfile; private MultiAutoCompleteTextView mName; private TextInputLayoutHelper mNameWrap; @@ -112,6 +119,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity private TextInputLayoutHelper mExcludedSubnetsWrap; private CheckBox mBlockIPv4; private CheckBox mBlockIPv6; + private Spinner mSelectSelectedAppsHandling; + private RelativeLayout mSelectApps; @Override public void onCreate(Bundle savedInstanceState) @@ -161,6 +170,9 @@ public class VpnProfileDetailActivity extends AppCompatActivity mBlockIPv4 = (CheckBox)findViewById(R.id.split_tunneling_v4); mBlockIPv6 = (CheckBox)findViewById(R.id.split_tunneling_v6); + mSelectSelectedAppsHandling = (Spinner)findViewById(R.id.apps_handling); + mSelectApps = (RelativeLayout)findViewById(R.id.select_applications); + final SpaceTokenizer spaceTokenizer = new SpaceTokenizer(); mName.setTokenizer(spaceTokenizer); mRemoteId.setTokenizer(spaceTokenizer); @@ -265,6 +277,32 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); + mSelectSelectedAppsHandling.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) + { + mSelectedAppsHandling = SelectedAppsHandling.values()[position]; + updateAppsSelector(); + } + + @Override + public void onNothingSelected(AdapterView parent) + { /* should not happen */ + mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE; + updateAppsSelector(); + } + }); + + mSelectApps.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) + { + Intent intent = new Intent(VpnProfileDetailActivity.this, SelectedApplicationsActivity.class); + intent.putExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps)); + startActivityForResult(intent, SELECT_APPLICATIONS); + } + }); + mId = savedInstanceState == null ? null : savedInstanceState.getLong(VpnProfileDataSource.KEY_ID); if (mId == null) { @@ -277,6 +315,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity updateCredentialView(); updateCertificateSelector(); updateAdvancedSettings(); + updateAppsSelector(); } @Override @@ -306,6 +345,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity { outState.putString(VpnProfileDataSource.KEY_CERTIFICATE, mCertEntry.getAlias()); } + outState.putStringArrayList(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps)); } @Override @@ -347,6 +387,14 @@ public class VpnProfileDetailActivity extends AppCompatActivity updateCertificateSelector(); } break; + case SELECT_APPLICATIONS: + if (resultCode == RESULT_OK) + { + ArrayList selection = data.getStringArrayListExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST); + mSelectedApps = new TreeSet<>(selection); + updateAppsSelector(); + } + break; default: super.onActivityResult(requestCode, resultCode, data); } @@ -435,6 +483,40 @@ public class VpnProfileDetailActivity extends AppCompatActivity } } + /** + * Update the application selection UI + */ + private void updateAppsSelector() + { + if (mSelectedAppsHandling == SelectedAppsHandling.SELECTED_APPS_DISABLE) + { + mSelectApps.setEnabled(false); + mSelectApps.setVisibility(View.GONE); + + } + else + { + mSelectApps.setEnabled(true); + mSelectApps.setVisibility(View.VISIBLE); + + ((TextView)mSelectApps.findViewById(android.R.id.text1)).setText(R.string.profile_select_apps); + String selected; + switch (mSelectedApps.size()) + { + case 0: + selected = getString(R.string.profile_select_no_apps); + break; + case 1: + selected = getString(R.string.profile_select_one_app); + break; + default: + selected = getString(R.string.profile_select_x_apps, mSelectedApps.size()); + break; + } + ((TextView)mSelectApps.findViewById(android.R.id.text2)).setText(selected); + } + } + /** * Update the advanced settings UI depending on whether any advanced * settings have already been made. @@ -447,7 +529,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity Integer st = mProfile.getSplitTunneling(); show = mProfile.getRemoteId() != null || mProfile.getMTU() != null || mProfile.getPort() != null || (st != null && st != 0) || - mProfile.getIncludedSubnets() != null || mProfile.getExcludedSubnets() != null; + mProfile.getIncludedSubnets() != null || mProfile.getExcludedSubnets() != null || + mProfile.getSelectedAppsHandling() != SelectedAppsHandling.SELECTED_APPS_DISABLE; } mShowAdvanced.setVisibility(!show ? View.VISIBLE : View.GONE); mAdvancedSettings.setVisibility(show ? View.VISIBLE : View.GONE); @@ -575,6 +658,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity st |= mBlockIPv4.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4 : 0; st |= mBlockIPv6.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6 : 0; mProfile.setSplitTunneling(st == 0 ? null : st); + mProfile.setSelectedAppsHandling(mSelectedAppsHandling); + mProfile.setSelectedApps(mSelectedApps); } /** @@ -604,6 +689,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity mExcludedSubnets.setText(mProfile.getExcludedSubnets()); mBlockIPv4.setChecked(mProfile.getSplitTunneling() != null && (mProfile.getSplitTunneling() & VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4) != 0); mBlockIPv6.setChecked(mProfile.getSplitTunneling() != null && (mProfile.getSplitTunneling() & VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6) != 0); + mSelectedAppsHandling = mProfile.getSelectedAppsHandling(); + mSelectedApps = mProfile.getSelectedAppsSet(); useralias = mProfile.getUserCertificateAlias(); local_id = mProfile.getLocalId(); alias = mProfile.getCertificateAlias(); @@ -646,6 +733,13 @@ public class VpnProfileDetailActivity extends AppCompatActivity mCertEntry = null; } } + + mSelectSelectedAppsHandling.setSelection(mSelectedAppsHandling.ordinal()); + if (savedInstanceState != null) + { + ArrayList selectedApps = savedInstanceState.getStringArrayList(VpnProfileDataSource.KEY_SELECTED_APPS_LIST); + mSelectedApps = new TreeSet<>(selectedApps); + } } /** diff --git a/src/frontends/android/app/src/main/res/layout/profile_detail_view.xml b/src/frontends/android/app/src/main/res/layout/profile_detail_view.xml index f9a512d968..8b153b89a3 100644 --- a/src/frontends/android/app/src/main/res/layout/profile_detail_view.xml +++ b/src/frontends/android/app/src/main/res/layout/profile_detail_view.xml @@ -250,6 +250,7 @@ android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_marginLeft="4dp" + android:layout_marginStart="4dp" android:textSize="20sp" android:text="@string/profile_split_tunneling_label" /> @@ -306,6 +307,27 @@ android:layout_height="wrap_content" android:text="@string/profile_split_tunnelingv6_title" /> + + + + + + diff --git a/src/frontends/android/app/src/main/res/values-de/arrays.xml b/src/frontends/android/app/src/main/res/values-de/arrays.xml index d051401653..1eda4f1ae0 100644 --- a/src/frontends/android/app/src/main/res/values-de/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-de/arrays.xml @@ -1,7 +1,7 @@ + + Alle Apps verwenden das VPN + Ausgewählte Apps vom VPN ausschliessen + Nur ausgewählte Apps verwenden das VPN + \ No newline at end of file diff --git a/src/frontends/android/app/src/main/res/values-de/strings.xml b/src/frontends/android/app/src/main/res/values-de/strings.xml index ca22f78b53..5c5a22a640 100644 --- a/src/frontends/android/app/src/main/res/values-de/strings.xml +++ b/src/frontends/android/app/src/main/res/values-de/strings.xml @@ -87,7 +87,11 @@ Nur Verkehr in die spezifizierten Subnetze wird via VPN geleitet, der Rest wird behandelt, als ob kein VPN vorhanden wäre (mit Leerzeichen getrennt, z.B. \"192.168.1.0/24 2001:db8::/64\") Ausgeschlossene Subnetze Verkehr in diese Subnetze wird vom VPN ausgeschlossen und behandelt, als ob kein VPN vorhanden wäre (mit Leerzeichen getrennt, z.B. \"192.168.1.0/24 2001:db8::/64\") + Apps Apps auswählen + Keine Apps ausgewählt + Eine App ausgewählt + %1$d Apps ausgewählt VPN Profile importieren VPN Profil-Import fehlgeschlagen VPN Profil-Import fehlgeschlagen: %1$s diff --git a/src/frontends/android/app/src/main/res/values-pl/arrays.xml b/src/frontends/android/app/src/main/res/values-pl/arrays.xml index 30e43f1fb1..5df0e72c4a 100644 --- a/src/frontends/android/app/src/main/res/values-pl/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-pl/arrays.xml @@ -22,4 +22,11 @@ IKEv2 EAP-TLS (certyfikat) IKEv2 EAP-TNC (użytkownik/hasło) + + + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + \ No newline at end of file diff --git a/src/frontends/android/app/src/main/res/values-pl/strings.xml b/src/frontends/android/app/src/main/res/values-pl/strings.xml index 1708f6edf9..d8965a1e45 100644 --- a/src/frontends/android/app/src/main/res/values-pl/strings.xml +++ b/src/frontends/android/app/src/main/res/values-pl/strings.xml @@ -87,7 +87,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected Import VPN profile Failed to import VPN profile Failed to import VPN profile: %1$s diff --git a/src/frontends/android/app/src/main/res/values-ru/arrays.xml b/src/frontends/android/app/src/main/res/values-ru/arrays.xml index 5fbd431683..64c234eb48 100644 --- a/src/frontends/android/app/src/main/res/values-ru/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-ru/arrays.xml @@ -21,4 +21,11 @@ IKEv2 EAP-TLS (Сертификат) IKEv2 EAP-TNC (Логин/Пароль) + + + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + diff --git a/src/frontends/android/app/src/main/res/values-ru/strings.xml b/src/frontends/android/app/src/main/res/values-ru/strings.xml index 0183e0306a..7296554d87 100644 --- a/src/frontends/android/app/src/main/res/values-ru/strings.xml +++ b/src/frontends/android/app/src/main/res/values-ru/strings.xml @@ -84,7 +84,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected Import VPN profile Failed to import VPN profile Failed to import VPN profile: %1$s diff --git a/src/frontends/android/app/src/main/res/values-ua/arrays.xml b/src/frontends/android/app/src/main/res/values-ua/arrays.xml index 1acc0d7698..8401ef91f4 100644 --- a/src/frontends/android/app/src/main/res/values-ua/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-ua/arrays.xml @@ -21,4 +21,11 @@ IKEv2 EAP-TLS (Сертифікати) IKEv2 EAP-TNC (Логін/Пароль) + + + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + diff --git a/src/frontends/android/app/src/main/res/values-ua/strings.xml b/src/frontends/android/app/src/main/res/values-ua/strings.xml index 156300d3eb..6f30fcf16e 100644 --- a/src/frontends/android/app/src/main/res/values-ua/strings.xml +++ b/src/frontends/android/app/src/main/res/values-ua/strings.xml @@ -85,7 +85,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected Import VPN profile Failed to import VPN profile Failed to import VPN profile: %1$s diff --git a/src/frontends/android/app/src/main/res/values-zh-rCN/arrays.xml b/src/frontends/android/app/src/main/res/values-zh-rCN/arrays.xml index 546000ab26..64bd21bbed 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rCN/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rCN/arrays.xml @@ -21,4 +21,11 @@ IKEv2 EAP-TLS (证书) IKEv2 EAP-TNC (用户名/密码) + + + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + \ No newline at end of file diff --git a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml index 119d462cc7..415212eab1 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml @@ -84,7 +84,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected 导入VPN配置 导入VPN配置失败 导入VPN配置失败: %1$s diff --git a/src/frontends/android/app/src/main/res/values-zh-rTW/arrays.xml b/src/frontends/android/app/src/main/res/values-zh-rTW/arrays.xml index c7a1963bbb..e4ceccc952 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rTW/arrays.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rTW/arrays.xml @@ -21,4 +21,11 @@ IKEv2 EAP-TLS (憑證) IKEv2 EAP-TNC (用戶名稱/密碼) + + + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + \ No newline at end of file diff --git a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml index 2b0ce6b2bc..e1cdf32e54 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml @@ -84,7 +84,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected 匯入VPN設定檔 匯入VPN設定檔失敗 匯入VPN設定檔失敗: %1$s diff --git a/src/frontends/android/app/src/main/res/values/arrays.xml b/src/frontends/android/app/src/main/res/values/arrays.xml index b324b594f3..be12aab1ce 100644 --- a/src/frontends/android/app/src/main/res/values/arrays.xml +++ b/src/frontends/android/app/src/main/res/values/arrays.xml @@ -1,7 +1,7 @@ + + All applications use the VPN + Exclude selected applications from the VPN + Only selected applications use the VPN + + diff --git a/src/frontends/android/app/src/main/res/values/strings.xml b/src/frontends/android/app/src/main/res/values/strings.xml index e9a62f03c3..fa38753c2d 100644 --- a/src/frontends/android/app/src/main/res/values/strings.xml +++ b/src/frontends/android/app/src/main/res/values/strings.xml @@ -87,7 +87,11 @@ Only route traffic to specific subnets via VPN, everything else is routed as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") Excluded subnets Traffic to these subnets will not be routed via VPN, but as if there was no VPN (separated by spaces, e.g. \"192.168.1.0/24 2001:db8::/64\") + Applications Select applications + No applications selected + One application selected + %1$d applications selected Import VPN profile Failed to import VPN profile Failed to import VPN profile: %1$s