Initial commit for AndroidStudio project with gradle build system.

This commit is contained in:
Wilco Baan Hofman 2017-12-22 15:46:43 +01:00
commit 0a4f9f6102
28 changed files with 1114 additions and 0 deletions

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

114
app/app.iml Normal file
View file

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

19
app/build.gradle Normal file
View file

@ -0,0 +1,19 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "nl.eventinfra.wifisetup"
minSdkVersion 18
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

3
app/lint.xml Normal file
View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
</lint>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.eventinfra.wifisetup" android:installLocation="auto" android:versionCode="20171222" android:versionName="0.20">
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<uses-feature android:name="android.hardware.wifi" android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="false" android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="nl.eventinfra.wifisetup.WifiSetup"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,443 @@
/* Copyright 2013-2016 Wilco Baan Hofman <wilco@baanhofman.nl>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.eventinfra.wifisetup;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.provider.Settings.Secure;
import android.security.KeyChain;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
/* import android.util.Base64; */
import org.json.JSONException;
import org.json.JSONObject;
import nl.eventinfra.wifisetup.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CheckBox;
import android.widget.ViewFlipper;
// API level 18 and up
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
public class WifiSetup extends Activity {
// FIXME This should be a configuration setting somehow
private static final String INT_EAP = "eap";
private static final String INT_PHASE2 = "phase2";
private static final String INT_ENGINE = "engine";
private static final String INT_ENGINE_ID = "engine_id";
private static final String INT_CLIENT_CERT = "client_cert";
private static final String INT_CA_CERT = "ca_cert";
private static final String INT_PRIVATE_KEY = "private_key";
private static final String INT_PRIVATE_KEY_ID = "key_id";
private static final String INT_SUBJECT_MATCH = "subject_match";
private static final String INT_ALTSUBJECT_MATCH = "altsubject_match";
private static final String INT_PASSWORD = "password";
private static final String INT_IDENTITY = "identity";
private static final String INT_ANONYMOUS_IDENTITY = "anonymous_identity";
private static final String INT_ENTERPRISEFIELD_NAME = "android.net.wifi.WifiConfiguration$EnterpriseField";
// Because android.security.Credentials cannot be resolved...
private static final String INT_KEYSTORE_URI = "keystore://";
private static final String INT_CA_PREFIX = INT_KEYSTORE_URI + "CACERT_";
private static final String INT_PRIVATE_KEY_PREFIX = INT_KEYSTORE_URI + "USRPKEY_";
private static final String INT_PRIVATE_KEY_ID_PREFIX = "USRPKEY_";
private static final String INT_CLIENT_CERT_PREFIX = INT_KEYSTORE_URI + "USRCERT_";
protected static final int SHOW_PREFERENCES = 0;
private Handler mHandler = new Handler();
private EditText username;
private EditText password;
private CheckBox check5g;
private Button btn;
private String subject_match;
private String altsubject_match;
private String realm;
private String ssid;
private boolean busy = false;
private Toast toast = null;
private int logoclicks = 0;
private String s_username;
private String s_password;
private ViewFlipper flipper;
private void toastText(final String text) {
if (toast != null)
toast.cancel();
toast = Toast.makeText(getBaseContext(), text, Toast.LENGTH_SHORT);
toast.show();
}
/*
* Unfortunately, this returns false on a LOT of devices :(
*
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean get5G() {
WifiManager wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE);
return wifiManager.is5GHzBandSupported();
}
*/
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logon);
flipper = (ViewFlipper) findViewById(R.id.viewflipper);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
check5g = (CheckBox) findViewById(R.id.check5g);
check5g.setChecked(true);
/*
TextView label5g = (TextView) findViewById(R.id.label5g);
if (android.os.Build.VERSION.SDK_INT >= 21) {
check5g.setChecked(get5G());
label5g.setText("(autodetected value)");
} else {
check5g.setChecked(true);
label5g.setText("(Android 5.0 is needed to autodetect this)");
}
*/
ImageView img = (ImageView) findViewById(R.id.logo);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
logoclicks++;
if (logoclicks == 4) {
toastText("You're cute!");
}
if (logoclicks == 6) {
toastText("Stop that!");
}
if (logoclicks == 7) {
View logindata = findViewById(R.id.logindata);
logindata.setVisibility(View.VISIBLE);
}
}
});
btn = (Button) findViewById(R.id.button1);
if (btn == null)
throw new RuntimeException("button1 not found. Odd");
btn.setOnClickListener(new Button.OnClickListener() {
public void onClick(View _v) {
if (busy) {
return;
}
busy = true;
_v.setClickable(false);
// Most of this stuff runs in the background
Thread t = new Thread() {
@Override
public void run() {
try {
if (android.os.Build.VERSION.SDK_INT >= 18) {
saveWifiConfig();
resultStatus(true, "You should now have a wifi connection entry with correct security settings and certificate verification.\n\nMake sure to actually use it!");
// Clear the password field in the UI thread
/*
mHandler.post(new Runnable() {
@Override
public void run() {
password.setText("");
};
});
*/
} else {
throw new RuntimeException("What version is this?! API Mismatch");
}
} catch (RuntimeException e) {
resultStatus(false, "Something went wrong: " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
busy = false;
mHandler.post(new Runnable() {
@Override
public void run() {
btn.setClickable(true);
}
});
}
};
t.start();
}
});
}
private void saveWifiConfig() {
WifiManager wifiManager = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE);
if (!wifimanager) {
return;
}
wifiManager.setWifiEnabled(true);
WifiConfiguration currentConfig = new WifiConfiguration();
List<WifiConfiguration> configs = null;
for (int i = 0; i < 10 && configs == null; i++) {
configs = wifiManager.getConfiguredNetworks();
try {
Thread.sleep(1);
}
catch(InterruptedException e) {
// Do nothing ;-)
}
}
if (check5g.isChecked()) {
ssid = "34C3";
} else {
ssid = "34C3-legacy";
}
subject_match = "/CN=radius.c3noc.net";
altsubject_match = "DNS:radius.c3noc.net";
s_username = username.getText().toString();
s_password = password.getText().toString();
realm = "";
if (s_username.equals("") && s_password.equals("")) {
s_username = "34c3";
s_password = "34c3";
} else {
if (s_username.contains("@")) {
int idx = s_username.indexOf("@");
realm = s_username.substring(idx);
}
}
// Use the existing eduroam profile if it exists.
boolean ssidExists = false;
if (configs != null) {
for (WifiConfiguration config : configs) {
if (config.SSID.equals(surroundWithQuotes(ssid))) {
currentConfig = config;
ssidExists = true;
break;
}
}
}
currentConfig.SSID = surroundWithQuotes(ssid);
currentConfig.hiddenSSID = false;
currentConfig.priority = 40;
currentConfig.status = WifiConfiguration.Status.DISABLED;
currentConfig.allowedKeyManagement.clear();
currentConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
// GroupCiphers (Allow most ciphers)
currentConfig.allowedGroupCiphers.clear();
currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
// PairwiseCiphers (CCMP = WPA2 only)
currentConfig.allowedPairwiseCiphers.clear();
currentConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
// Authentication Algorithms (OPEN)
currentConfig.allowedAuthAlgorithms.clear();
currentConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
// Protocols (RSN/WPA2 only)
currentConfig.allowedProtocols.clear();
currentConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
// Enterprise Settings
HashMap<String,String> configMap = new HashMap<>();
configMap.put(INT_SUBJECT_MATCH, subject_match);
configMap.put(INT_ALTSUBJECT_MATCH, altsubject_match);
configMap.put(INT_ANONYMOUS_IDENTITY, "anonymous" + realm);
configMap.put(INT_IDENTITY, s_username);
configMap.put(INT_PASSWORD, s_password);
configMap.put(INT_EAP, "TTLS");
configMap.put(INT_PHASE2, "auth=PAP");
configMap.put(INT_ENGINE, "0");
// configMap.put(INT_CA_CERT, INT_CA_PREFIX + ca_name);
applyAndroid43EnterpriseSettings(currentConfig, configMap);
if (!ssidExists) {
int networkId = wifiManager.addNetwork(currentConfig);
wifiManager.enableNetwork(networkId, false);
} else {
wifiManager.updateNetwork(currentConfig);
wifiManager.enableNetwork(currentConfig.networkId, false);
}
wifiManager.saveConfiguration();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void applyAndroid43EnterpriseSettings(WifiConfiguration currentConfig, HashMap<String,String> configMap) {
try {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = getResources().openRawResource(R.raw.cacert);
// InputStream in = new ByteArrayInputStream(Base64.decode(ca.replaceAll("-----(BEGIN|END) CERTIFICATE-----", ""), 0));
X509Certificate caCert = (X509Certificate) certFactory.generateCertificate(in);
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
enterpriseConfig.setPhase2Method(Phase2.PAP);
enterpriseConfig.setAnonymousIdentity(configMap.get(INT_ANONYMOUS_IDENTITY));
enterpriseConfig.setEapMethod(Eap.TTLS);
enterpriseConfig.setCaCertificate(caCert);
enterpriseConfig.setIdentity(s_username);
enterpriseConfig.setPassword(s_password);
enterpriseConfig.setSubjectMatch(configMap.get(INT_SUBJECT_MATCH));
currentConfig.enterpriseConfig = enterpriseConfig;
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Builder builder = new AlertDialog.Builder(this);
switch (item.getItemId()) {
case R.id.about:
PackageInfo pi = null;
try{
pi = getPackageManager().getPackageInfo(getClass().getPackage().getName(), 0);
} catch(Exception e){
e.printStackTrace();
return false;
}
builder.setTitle(getString(R.string.ABOUT_TITLE));
builder.setMessage(getString(R.string.ABOUT_CONTENT)+
"\n\n"+pi.packageName+"\n"+
"V"+pi.versionName+
"C"+pi.versionCode+"-equi");
builder.setPositiveButton(getString(android.R.string.ok), null);
builder.show();
return true;
case R.id.exit:
System.exit(0);
}
return false;
}
/* Update the status in the main thread */
protected void resultStatus(final boolean success, final String text) {
mHandler.post(new Runnable() {
@Override
public void run() {
TextView res_title = (TextView) findViewById(R.id.resulttitle);
TextView res_text = (TextView) findViewById(R.id.result);
System.out.println(text);
res_text.setText(text);
if (success)
res_title.setText("Success!");
else
res_title.setText("ERROR!");
if (toast != null)
toast.cancel();
/* toast = Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG);
toast.show(); */
flipper.showNext();
}
});
}
static String removeQuotes(String str) {
int len = str.length();
if ((len > 1) && (str.charAt(0) == '"') && (str.charAt(len - 1) == '"')) {
return str.substring(1, len - 1);
}
return str;
}
static String surroundWithQuotes(String string) {
return "\"" + string + "\"";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

View file

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".WifiSetup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewflipper"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/FirstView"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/logonLayout"
android:orientation="vertical"
android:gravity="center_horizontal|top">
<ImageView
android:id="@+id/logo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="fitCenter"
android:contentDescription="@string/LOGO"
android:src="@drawable/ccc34c3logo"
android:padding="0dp" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:autoLink="web"
android:layout_marginTop="15dp"
android:text="@string/twitter"/>
<CheckBox android:id="@+id/check5g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="@string/c5ghz"/>
<TextView
android:id="@+id/label5g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:text="@string/l5ghz"/>
<TextView
android:layout_marginTop="5dp"
android:id="@+id/labelkeystore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:text="@string/lkeystore"/>
<LinearLayout
android:id="@+id/logindata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal|top"
android:visibility="gone">
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:padding="5dp"
android:layout_marginTop="15dp"
android:hint="@string/Username"
>
<requestFocus />
</EditText>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:padding="5dp"
android:layout_marginTop="5dp"
android:hint="@string/Password"
/>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Logon"
android:layout_margin="15dp"/>
<Space
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/logonLayout2"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:id="@+id/resulttitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textAlignment="center"
android:textSize="24sp"
/>
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15sp"
android:textAlignment="center"
/>
</LinearLayout>
</ViewFlipper>

View file

@ -0,0 +1,5 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/about" android:title="@string/ABOUT_TITLE"/>
<item android:id="@+id/exit" android:title="@string/EXIT_TITLE"/>
</menu>

Binary file not shown.

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">34C3 Wifi Setup</string>
<string name="TITLE_LOGON">Please logon</string>
<string name="Username">username@realm</string>
<string name="Password">password</string>
<string name="Logon">Create connection entry</string>
<string name="twitter">https://twitter.com/sha2017noc</string>
<string name="c5ghz">This device supports the 5GHz band</string>
<string name="l5ghz">(Unfortunately, autodetecting 5GHz support is broken...)</string>
<string name="lkeystore">Note: if you have no screen lock, Android refuses to store the security settings!</string>
<string name="ABOUT_TITLE">About</string>
<string name="EXIT_TITLE">Exit</string>
<string name="ABOUT_CONTENT">This small helper app creates a Wifi connection entry for the CCC/EMF/SHA2017 networks. It configures the correct SSL CA and subject name match, making it a little more secure than a hand-created entry.</string>
<string name="LOGO">34C3 Logo</string>
</resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/TITLE_LOGON">
<PreferenceCategory android:title="SSID"
android:orderingFromXml="true">
<EditTextPreference android:key="Username"
android:summary="@string/Username" android:title="@string/Username"></EditTextPreference>
<EditTextPreference android:key="Password" android:summary="@string/Username" android:title="@string/Password" android:password="true"></EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>

15
build.gradle Normal file
View file

@ -0,0 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
jcenter()
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
#Fri Dec 22 12:53:58 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

160
gradlew vendored Executable file
View file

@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Normal file
View file

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

38
import-summary.txt Normal file
View file

@ -0,0 +1,38 @@
ECLIPSE ANDROID PROJECT IMPORT SUMMARY
======================================
Ignored Files:
--------------
The following files were *not* copied into the new Gradle project; you
should evaluate whether these are still needed in your project and if
so manually move them:
* 0001-Add-33c3-configuration-No-CA-yet.patch
* android.iml
* patches.txt
Moved Files:
------------
Android Gradle projects use a different directory structure than ADT
Eclipse projects. Here's how the projects were restructured:
* AndroidManifest.xml => app/src/main/AndroidManifest.xml
* assets/ => app/src/main/assets
* lint.xml => app/lint.xml
* res/ => app/src/main/res/
* src/ => app/src/main/java/
Next Steps:
-----------
You can now build the project. The Gradle project needs network
connectivity to download dependencies.
Bugs:
-----
If for some reason your project does not build, and you determine that
it is due to a bug or limitation of the Eclipse to Gradle importer,
please file a bug at http://b.android.com with category
Component-Tools.
(This import summary is for your information only, and can be deleted
after import once you are satisfied with the results.)

1
settings.gradle Normal file
View file

@ -0,0 +1 @@
include ':app'

19
wifisetup.iml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="wifisetup" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>