Merge branch 'master' of https://github.com/HackspaceJena/tueroeffner
Conflicts: app/src/main/java/me/datenknoten/tueroeffner/MainActivity.java
This commit is contained in:
commit
b37e0f25f5
6 changed files with 100 additions and 120 deletions
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
Eine kleine Android Anwendung zum einfachen öffnen der [Tür](https://www.krautspace.de/hswiki:fernschliessanlage).
|
Eine kleine Android Anwendung zum einfachen öffnen der [Tür](https://www.krautspace.de/hswiki:fernschliessanlage).
|
||||||
|
|
||||||
Aktuelle Builds gibts unter https://login.datenknoten.me/~tim/tueroeffner/.
|
[![Build Status](http://buildserver.datenknoten.me/buildStatus/icon?job=tueroeffner)](http://buildserver.datenknoten.me/job/tueroeffner/)
|
||||||
|
|
||||||
|
|
|
@ -85,8 +85,12 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
|
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" exported="" name="androidasync-2.0.5" level="project" />
|
||||||
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
|
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="ion-2.0.5" level="project" />
|
||||||
<orderEntry type="library" exported="" name="support-annotations-21.0.2" level="project" />
|
<orderEntry type="library" exported="" name="support-annotations-21.0.2" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="AndroidPinning-1.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
|
<orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -30,4 +30,6 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
compile 'com.android.support:appcompat-v7:21.0.2'
|
compile 'com.android.support:appcompat-v7:21.0.2'
|
||||||
|
compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
|
||||||
|
compile 'com.koushikdutta.ion:ion:2.+'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* "THE VODKA-WARE LICENSE" (Revision 42):
|
|
||||||
* Tim <tim@datenknoten.me> wrote this file. As long as you retain this notice you
|
|
||||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
||||||
* this stuff is worth it, you can buy me a vodka in return — Tim Schumacher
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
package me.datenknoten.tueroeffner;
|
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by tim on 27.01.2015.
|
|
||||||
*/
|
|
||||||
public class CommandExecuter extends AsyncTask<String, Integer, Boolean> {
|
|
||||||
private String key = "";
|
|
||||||
|
|
||||||
public CommandExecuter(String Key) {
|
|
||||||
this.key = Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean doInBackground(String... params) {
|
|
||||||
int count = params.length;
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (String param : params) {
|
|
||||||
executeCommand(param);
|
|
||||||
// Escape early if cancel() is called
|
|
||||||
if (isCancelled()) break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a command to the door server.
|
|
||||||
*
|
|
||||||
* @param cmd
|
|
||||||
*/
|
|
||||||
private Boolean executeCommand(String cmd) throws IOException, URISyntaxException {
|
|
||||||
HttpClient client = new DefaultHttpClient();
|
|
||||||
HttpGet request = new HttpGet();
|
|
||||||
URI uri = new URI("https://tuer.hackspace-jena.de/cgi-bin/kraut.space?secret="+key+"&cmd="+cmd);
|
|
||||||
request.setURI(uri);
|
|
||||||
HttpResponse response = client.execute(request);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,6 +21,7 @@ import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -38,17 +39,30 @@ import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.thoughtcrime.ssl.pinning.PinningTrustManager;
|
||||||
|
import org.thoughtcrime.ssl.pinning.SystemKeyStore;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import com.koushikdutta.async.future.FutureCallback;
|
||||||
|
import com.koushikdutta.ion.Ion;
|
||||||
|
import com.koushikdutta.ion.future.ResponseFuture;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity {
|
public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
static String networkSSID = "KrautSpace";
|
final static String networkSSID = "KrautSpace";
|
||||||
|
private DerivBroadcastReceiver receiver = null;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -62,9 +76,16 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) ;
|
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
registerReceiver(new DerivBroadcastReceiver(this, networkSSID),intentFilter);
|
receiver = new DerivBroadcastReceiver(this, networkSSID);
|
||||||
|
registerReceiver(receiver, intentFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
unregisterReceiver(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,8 +124,8 @@ public class MainActivity extends ActionBarActivity {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
|
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
|
||||||
|
|
||||||
final SharedPreferences door_pref = getActivity().getSharedPreferences("tueroeffner",Context.MODE_PRIVATE);
|
final SharedPreferences door_pref = getActivity().getSharedPreferences("tueroeffner", Context.MODE_PRIVATE);
|
||||||
String door_key = door_pref.getString(getString(R.string.door_key),"");
|
String door_key = door_pref.getString(getString(R.string.door_key), "");
|
||||||
final EditText key_editor = (EditText) rootView.findViewById(R.id.txtPass);
|
final EditText key_editor = (EditText) rootView.findViewById(R.id.txtPass);
|
||||||
key_editor.setText(door_key);
|
key_editor.setText(door_key);
|
||||||
|
|
||||||
|
@ -114,14 +135,16 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
// you can call or do what you want with your EditText here
|
// you can call or do what you want with your EditText here
|
||||||
SharedPreferences.Editor editor = door_pref.edit();
|
SharedPreferences.Editor editor = door_pref.edit();
|
||||||
editor.putString(getString(R.string.door_key),key_editor.getText().toString());
|
editor.putString(getString(R.string.door_key), key_editor.getText().toString());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Switch s = (Switch) rootView.findViewById(R.id.switchWLAN);
|
Switch s = (Switch) rootView.findViewById(R.id.switchWLAN);
|
||||||
|
@ -130,10 +153,12 @@ public class MainActivity extends ActionBarActivity {
|
||||||
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
String escaped_ssid = "\"" + networkSSID + "\"";
|
||||||
Context context = rootView.getContext();
|
Context context = rootView.getContext();
|
||||||
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
|
||||||
|
|
||||||
WifiConfiguration wifiConfig = new WifiConfiguration();
|
WifiConfiguration wifiConfig = new WifiConfiguration();
|
||||||
wifiConfig.SSID = String.format("\"%s\"", networkSSID);
|
wifiConfig.SSID = String.format("\"%s\"", networkSSID);
|
||||||
|
|
||||||
|
@ -142,34 +167,8 @@ public class MainActivity extends ActionBarActivity {
|
||||||
wifiManager.enableNetwork(netId, true);
|
wifiManager.enableNetwork(netId, true);
|
||||||
wifiManager.reconnect();
|
wifiManager.reconnect();
|
||||||
|
|
||||||
/*WifiConfiguration conf = new WifiConfiguration();
|
|
||||||
conf.SSID = networkSSID;
|
|
||||||
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
|
||||||
int retval = wifiManager.addNetwork(conf);
|
|
||||||
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
|
||||||
|
|
||||||
|
|
||||||
for( WifiConfiguration i : list ) {
|
|
||||||
if(i.SSID != null && i.SSID.equals(networkSSID)) {
|
|
||||||
wifiManager.enableNetwork(i.networkId, false);
|
|
||||||
} else {
|
|
||||||
wifiManager.disableNetwork(i.networkId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wifiManager.disconnect();
|
|
||||||
wifiManager.reconnect();*/
|
|
||||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_activated), Toast.LENGTH_SHORT).show();
|
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_activated), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
/*List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
|
||||||
for( WifiConfiguration i : list ) {
|
|
||||||
if(i.SSID != null && i.SSID.equals(networkSSID)) {
|
|
||||||
wifiManager.removeNetwork(i.networkId);
|
|
||||||
} else {
|
|
||||||
wifiManager.enableNetwork(i.networkId,false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wifiManager.disconnect();
|
|
||||||
wifiManager.reconnect();*/
|
|
||||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_deactivated), Toast.LENGTH_SHORT).show();
|
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_deactivated), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,12 +190,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
* @param v
|
* @param v
|
||||||
*/
|
*/
|
||||||
public void buttonOpenOuterDoor(View v) {
|
public void buttonOpenOuterDoor(View v) {
|
||||||
try {
|
executeCommand("outdoor_buzz", v.getContext());
|
||||||
new CommandExecuter(getDoorKey()).doInBackground("outdoor_buzz");
|
|
||||||
Toast.makeText(v.getContext(), getString(R.string.buzzer_success), Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(v.getContext(), "Konnte Befehl „Buzzer“ nicht ausführen.", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,12 +199,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
* @param v
|
* @param v
|
||||||
*/
|
*/
|
||||||
public void buttonOpenInnerDoor(View v) {
|
public void buttonOpenInnerDoor(View v) {
|
||||||
try {
|
executeCommand("indoor_unlock", v.getContext());
|
||||||
new CommandExecuter(getDoorKey()).doInBackground("indoor_unlock");
|
|
||||||
Toast.makeText(v.getContext(), getString(R.string.door_unlock), Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(v.getContext(), "Konnte Befehl „Tür aufschließen“ nicht ausführen.", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -219,20 +208,47 @@ public class MainActivity extends ActionBarActivity {
|
||||||
* @param v
|
* @param v
|
||||||
*/
|
*/
|
||||||
public void buttonUnlockInnerDoor(View v) {
|
public void buttonUnlockInnerDoor(View v) {
|
||||||
try {
|
executeCommand("indoor_open", v.getContext());
|
||||||
new CommandExecuter(getDoorKey()).doInBackground("indoor_open");
|
|
||||||
Toast.makeText(v.getContext(), getString(R.string.door_open), Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(v.getContext(), "Konnte Befehl „Tür öffnen“ nicht ausführen.", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buttonLockInnerDoor(View v) {
|
public void buttonLockInnerDoor(View v) {
|
||||||
try {
|
executeCommand("indoor_lock", v.getContext());
|
||||||
new CommandExecuter(getDoorKey()).doInBackground("indoor_lock");
|
|
||||||
Toast.makeText(v.getContext(), getString(R.string.door_open), Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(v.getContext(), "Konnte Befehl „Tür schließen“ nicht ausführen.", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void executeCommand(String cmd, Context context) {
|
||||||
|
// Trust Manager
|
||||||
|
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
||||||
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
//Install the all-trusting trust manager
|
||||||
|
SSLContext sc = null;
|
||||||
|
try {
|
||||||
|
sc = SSLContext.getInstance("TLS");
|
||||||
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
|
sc.setDefault(sc);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** TODO it would be better to get the PinningTrustManager to get running, because its more safe. */
|
||||||
|
/*TrustManager[] trustManagers = new TrustManager[]{new PinningTrustManager(SystemKeyStore.getInstance(context),
|
||||||
|
new String[]{"F1E2BB0724ACF34E60557DE95BD3DD30BCD08817"}, 0)};*/
|
||||||
|
|
||||||
|
Ion.getDefault(context).getHttpClient().getSSLSocketMiddleware().setTrustManagers(trustAllCerts);
|
||||||
|
Ion.getDefault(context).getHttpClient().getSSLSocketMiddleware().setSSLContext(sc);
|
||||||
|
|
||||||
|
Ion.getDefault(context).getHttpClient().getSSLSocketMiddleware().setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
|
||||||
|
Ion.getDefault(this).configure().setLogging("iontest", Log.VERBOSE);
|
||||||
|
|
||||||
|
Ion.with(this).load("https://tuer.hackspace-jena.de/cgi-bin/kraut.space?secret=" + this.getDoorKey() + "&cmd=" + cmd).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
tueroeffner.iml
Normal file
21
tueroeffner.iml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module 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" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$/build/classes/main" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
Reference in a new issue