]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Add simple activity that requests a password
authorTobias Brunner <tobias@strongswan.org>
Tue, 17 Mar 2020 16:00:42 +0000 (17:00 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 30 Oct 2020 14:03:01 +0000 (15:03 +0100)
The password (if entered) is broadcast locally via LocalBroadcastManager.

src/frontends/android/app/src/main/AndroidManifest.xml
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnLoginActivity.java [new file with mode: 0644]
src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java

index 3f6302d0701b110afe94b7fd73c2d1d4e891a8af..d6bbc3aadb269baf5387d6930c3db2c2acc537a7 100644 (file)
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
+        <activity
+            android:name=".ui.VpnLoginActivity"
+            android:theme="@style/TransparentActivity"
+            android:taskAffinity=""
+            android:excludeFromRecents="true"
+            android:launchMode="singleTask" >
+        </activity>
         <activity
             android:name=".ui.VpnProfileDetailActivity" >
         </activity>
diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnLoginActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnLoginActivity.java
new file mode 100644 (file)
index 0000000..c1d94c5
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2020 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.ui;
+
+import android.content.Intent;
+import android.os.Bundle;
+
+import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.utils.Constants;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+
+public class VpnLoginActivity extends AppCompatActivity
+{
+       private static final String DIALOG_TAG = "Dialog";
+
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+
+               LoginDialogFragment login = LoginDialogFragment.newInstance(getIntent().getExtras(), password -> {
+                       if (password != null)
+                       {
+                               Intent intent = new Intent(Constants.VPN_PASSWORD_ENTERED);
+                               intent.putExtra(VpnProfileDataSource.KEY_PASSWORD, password);
+                               LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
+                       }
+                       finish();
+               });
+               login.show(getSupportFragmentManager(), DIALOG_TAG);
+       }
+}
index 71b6e0fceb2872d5a4392e15fd2452c63ba9f094..27f33e089846d3f584f5779554e89ec7b688d613 100644 (file)
@@ -22,6 +22,11 @@ public final class Constants
         */
        public static final String VPN_PROFILES_CHANGED = "org.strongswan.android.VPN_PROFILES_CHANGED";
 
+       /**
+        * Intent action used to pass around an entered password
+        */
+       public static final String VPN_PASSWORD_ENTERED = "org.strongswan.android.VPN_PASSWORD_ENTERED";
+
        /**
         * Used in the intent above to notify about edits or inserts of a VPN profile (long)
         */