This commit is contained in:
Daniel Pollithy 2018-01-22 13:26:24 +01:00
parent e7e5f8d6fe
commit 42276ec3fe
7 changed files with 59 additions and 16 deletions

View File

@ -36,6 +36,7 @@ public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
{
private static final String TAG = "MainAct";
private String password;
private String seed;
@ -52,6 +53,7 @@ public class MainActivity extends AppCompatActivity
private void subscribeToBroadcasts() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.flashwifi.wifip2p.start_roaming");
filter.addAction("com.flashwifi.wifip2p.stop_roaming");
updateUIReceiver = new BroadcastReceiver() {
@Override
@ -66,6 +68,9 @@ public class MainActivity extends AppCompatActivity
startRoamingView(intent.getStringExtra("peer_mac_address"),
intent.getStringExtra("ssid"),
intent.getStringExtra("key"));
} else if (intent.getAction().equals("com.flashwifi.wifip2p.stop_roaming")) {
Log.d(TAG, "onReceive: Reset billing state");
mService.resetBillingState();
}
}
};

View File

@ -100,6 +100,7 @@ public class RoamingActivity extends AppCompatActivity {
CheckBox flashEstablished = (CheckBox)findViewById(R.id.flashEstablished);
if (message.equals("AP SUCCESS")) {
apConnected.setChecked(true);
mService.resetBillingState();
// when the AP is setup we can start the server
startBillingProtocol();
} else if (message.equals("AP FAILED")) {
@ -124,6 +125,7 @@ public class RoamingActivity extends AppCompatActivity {
Toast.makeText(getApplicationContext(), "Can't connect", Toast.LENGTH_LONG).show();
exitRoaming();
}
// ToDo: add a critical error that uses exitRoaming()
}
}
@ -208,6 +210,8 @@ public class RoamingActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_roaming);
Accountant.getInstance().reset();
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
name = intent.getStringExtra("name");
@ -330,6 +334,7 @@ public class RoamingActivity extends AppCompatActivity {
}
private void exitRoaming() {
Accountant.getInstance().setCloseAfterwards(true);
endRoamingFlag = true;
cancelNotification();
if (mService.isInRoleHotspot()){
@ -350,6 +355,8 @@ public class RoamingActivity extends AppCompatActivity {
stopRoamingBroadcast();
Toast.makeText(getApplicationContext(), "Press BACK now", Toast.LENGTH_LONG).show();
initiatedEnd = false;
//finish();
}
@Override

View File

@ -206,7 +206,8 @@ public class SearchFragment extends Fragment {
ToggleButton toggle = (ToggleButton) getActivity().findViewById(R.id.startSearchButton);
toggle.setChecked(false);
} else if (intent.getAction().equals("com.flashwifi.wifip2p.stop_roaming")) {
peerListAdapter.clear();
PeerStore.getInstance().clear();
busy = false;
ToggleButton toggle = (ToggleButton) getActivity().findViewById(R.id.startSearchButton);
toggle.setChecked(false);
} else {

View File

@ -31,21 +31,19 @@ public class Accountant {
}
public void start(int bookedMegabytes, int timeoutMinutes, int bookedMinutes, int totalIotaDeposit, int iotaPerMegaByte){
if (closed) {
bills = new ArrayList<Bill>();
this.bookedMegabytes = bookedMegabytes;
this.timeoutMinutes = timeoutMinutes;
this.totalIotaDeposit = totalIotaDeposit;
this.iotaPerMegaByte = iotaPerMegaByte;
totalBytes = 0;
totalIotaPrice = 0;
totalDurance = 0;
flashChannelHelper = new FlashChannelHelper();
closeAfterwards = false;
startTime = System.currentTimeMillis() / 1000L;
this.bookedMinutes = bookedMinutes;
closed = false;
}
bills = new ArrayList<Bill>();
this.bookedMegabytes = bookedMegabytes;
this.timeoutMinutes = timeoutMinutes;
this.totalIotaDeposit = totalIotaDeposit;
this.iotaPerMegaByte = iotaPerMegaByte;
totalBytes = 0;
totalIotaPrice = 0;
totalDurance = 0;
flashChannelHelper = new FlashChannelHelper();
closeAfterwards = false;
startTime = System.currentTimeMillis() / 1000L;
this.bookedMinutes = bookedMinutes;
closed = false;
}
public long getLastTime() {
@ -56,6 +54,17 @@ public class Accountant {
}
}
public void reset() {
this.bookedMegabytes = 0;
this.timeoutMinutes = 0;
this.totalIotaDeposit = 0;
this.iotaPerMegaByte = 0;
totalBytes = 0;
totalIotaPrice = 0;
totalDurance = 0;
bookedMinutes = 0;
}
public boolean isCloseAfterwards() {
return closeAfterwards;
}

View File

@ -200,6 +200,17 @@ public class BillingServer {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
socketWrapper.close();
} catch (IOException e) {
}
try {
serverSocket.close();
} catch (IOException e) {
}
}
}

View File

@ -101,6 +101,11 @@ public class WiFiDirectBroadcastService extends Service {
}
}
public void resetBillingState() {
billingClientIsRunning = false;
billingServerIsRunning = false;
}
public void startBillingServer(){
if (!billingServerIsRunning) {
billingServerIsRunning = true;
@ -127,6 +132,8 @@ public class WiFiDirectBroadcastService extends Service {
//AsyncTask.execute(thread);
threads.add(thread);
thread.start();
} else {
Log.d(TAG, "startBillingServer: blocked");
}
}
@ -153,6 +160,8 @@ public class WiFiDirectBroadcastService extends Service {
threads.add(thread);
thread.start();
//AsyncTask.execute(thread);
} else {
Log.d(TAG, "startBillingClient: blocked");
}
}

View File

@ -119,4 +119,5 @@ public class PeerStore {
public void setIPAddress(String macAddress, InetAddress IPAddress) {
getOrCreatePeer(macAddress.toLowerCase()).setIPAddress(IPAddress.getHostAddress());
}
}