|
@@ -1,5 +1,6 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
|
|
@@ -12,6 +13,8 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
|
+import android.net.LocalSocket;
|
|
|
+import android.net.LocalSocketAddress;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
@@ -57,13 +60,13 @@ public class MainActivity extends Activity {
|
|
|
private ListView listView;
|
|
|
private ListViewAdapter adapter;
|
|
|
|
|
|
+ private boolean running;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
- startService(getServiceIntent());
|
|
|
-
|
|
|
initViewAnimator();
|
|
|
initListView();
|
|
|
}
|
|
@@ -78,13 +81,17 @@ public class MainActivity extends Activity {
|
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
|
registerReceiver();
|
|
|
- bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
|
|
|
+ if (isServiceRunning()) {
|
|
|
+ bindService(getServiceIntent(), mConnection, BIND_ABOVE_CLIENT);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
|
- unbindService(mConnection);
|
|
|
+ if (isServiceRunning()) {
|
|
|
+ unbindService(mConnection);
|
|
|
+ }
|
|
|
unregisterReceiver();
|
|
|
}
|
|
|
|
|
@@ -95,18 +102,24 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
public void buttonOnOffClick(View view) {
|
|
|
if (((ToggleButton) view).isChecked()) {
|
|
|
- if (isParanoid()) {
|
|
|
- mService.startListeners();
|
|
|
- } else {
|
|
|
- mService.startListener("SMB");
|
|
|
- }
|
|
|
- findViewById(R.id.checkBoxParanoid).setEnabled(false);
|
|
|
+ startAndBind();
|
|
|
} else {
|
|
|
- mService.stopListeners();
|
|
|
- findViewById(R.id.checkBoxParanoid).setEnabled(true);
|
|
|
+ stopAndUnbind();
|
|
|
+ running = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void startAndBind() {
|
|
|
+ startService(getServiceIntent());
|
|
|
+ bindService(getServiceIntent(), mConnection, BIND_ABOVE_CLIENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopAndUnbind() {
|
|
|
+ mService.stopListeners();
|
|
|
+ unbindService(mConnection);
|
|
|
+ stopService(getServiceIntent());
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isParanoid() {
|
|
|
return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
|
|
|
}
|
|
@@ -152,7 +165,9 @@ public class MainActivity extends Activity {
|
|
|
int position, long id) {
|
|
|
String protocolName = ((HashMap<String, String>) adapter
|
|
|
.getItem(position)).get("protocol");
|
|
|
- mService.toggleListener(protocolName);
|
|
|
+ if (isServiceRunning()) {
|
|
|
+ mService.toggleListener(protocolName);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
});
|
|
@@ -210,6 +225,15 @@ public class MainActivity extends Activity {
|
|
|
@Override
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
mService = ((LocalBinder) service).getService();
|
|
|
+ if (!running) {
|
|
|
+ if (isParanoid()) {
|
|
|
+ mService.startListeners();
|
|
|
+ } else {
|
|
|
+ mService.startListener("SMB");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ running = true;
|
|
|
+ updateUI();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -234,6 +258,7 @@ public class MainActivity extends Activity {
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
updateUI();
|
|
|
}
|
|
|
+
|
|
|
};
|
|
|
|
|
|
private void updateUI() {
|