mirror of
https://github.com/DanielPollithy/flashwifi.git
synced 2025-10-16 11:45:32 +00:00
fix #47
This commit is contained in:
parent
e7e5f8d6fe
commit
42276ec3fe
@ -36,6 +36,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
implements NavigationView.OnNavigationItemSelectedListener
|
implements NavigationView.OnNavigationItemSelectedListener
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String TAG = "MainAct";
|
||||||
private String password;
|
private String password;
|
||||||
private String seed;
|
private String seed;
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
private void subscribeToBroadcasts() {
|
private void subscribeToBroadcasts() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction("com.flashwifi.wifip2p.start_roaming");
|
filter.addAction("com.flashwifi.wifip2p.start_roaming");
|
||||||
|
filter.addAction("com.flashwifi.wifip2p.stop_roaming");
|
||||||
|
|
||||||
updateUIReceiver = new BroadcastReceiver() {
|
updateUIReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@ -66,6 +68,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
startRoamingView(intent.getStringExtra("peer_mac_address"),
|
startRoamingView(intent.getStringExtra("peer_mac_address"),
|
||||||
intent.getStringExtra("ssid"),
|
intent.getStringExtra("ssid"),
|
||||||
intent.getStringExtra("key"));
|
intent.getStringExtra("key"));
|
||||||
|
} else if (intent.getAction().equals("com.flashwifi.wifip2p.stop_roaming")) {
|
||||||
|
Log.d(TAG, "onReceive: Reset billing state");
|
||||||
|
mService.resetBillingState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -100,6 +100,7 @@ public class RoamingActivity extends AppCompatActivity {
|
|||||||
CheckBox flashEstablished = (CheckBox)findViewById(R.id.flashEstablished);
|
CheckBox flashEstablished = (CheckBox)findViewById(R.id.flashEstablished);
|
||||||
if (message.equals("AP SUCCESS")) {
|
if (message.equals("AP SUCCESS")) {
|
||||||
apConnected.setChecked(true);
|
apConnected.setChecked(true);
|
||||||
|
mService.resetBillingState();
|
||||||
// when the AP is setup we can start the server
|
// when the AP is setup we can start the server
|
||||||
startBillingProtocol();
|
startBillingProtocol();
|
||||||
} else if (message.equals("AP FAILED")) {
|
} 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();
|
Toast.makeText(getApplicationContext(), "Can't connect", Toast.LENGTH_LONG).show();
|
||||||
exitRoaming();
|
exitRoaming();
|
||||||
}
|
}
|
||||||
|
// ToDo: add a critical error that uses exitRoaming()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -208,6 +210,8 @@ public class RoamingActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_roaming);
|
setContentView(R.layout.activity_roaming);
|
||||||
|
|
||||||
|
Accountant.getInstance().reset();
|
||||||
|
|
||||||
// Get the Intent that started this activity and extract the string
|
// Get the Intent that started this activity and extract the string
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
name = intent.getStringExtra("name");
|
name = intent.getStringExtra("name");
|
||||||
@ -330,6 +334,7 @@ public class RoamingActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exitRoaming() {
|
private void exitRoaming() {
|
||||||
|
Accountant.getInstance().setCloseAfterwards(true);
|
||||||
endRoamingFlag = true;
|
endRoamingFlag = true;
|
||||||
cancelNotification();
|
cancelNotification();
|
||||||
if (mService.isInRoleHotspot()){
|
if (mService.isInRoleHotspot()){
|
||||||
@ -350,6 +355,8 @@ public class RoamingActivity extends AppCompatActivity {
|
|||||||
stopRoamingBroadcast();
|
stopRoamingBroadcast();
|
||||||
|
|
||||||
Toast.makeText(getApplicationContext(), "Press BACK now", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "Press BACK now", Toast.LENGTH_LONG).show();
|
||||||
|
initiatedEnd = false;
|
||||||
|
//finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -206,7 +206,8 @@ public class SearchFragment extends Fragment {
|
|||||||
ToggleButton toggle = (ToggleButton) getActivity().findViewById(R.id.startSearchButton);
|
ToggleButton toggle = (ToggleButton) getActivity().findViewById(R.id.startSearchButton);
|
||||||
toggle.setChecked(false);
|
toggle.setChecked(false);
|
||||||
} else if (intent.getAction().equals("com.flashwifi.wifip2p.stop_roaming")) {
|
} 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);
|
ToggleButton toggle = (ToggleButton) getActivity().findViewById(R.id.startSearchButton);
|
||||||
toggle.setChecked(false);
|
toggle.setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -31,7 +31,6 @@ public class Accountant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start(int bookedMegabytes, int timeoutMinutes, int bookedMinutes, int totalIotaDeposit, int iotaPerMegaByte){
|
public void start(int bookedMegabytes, int timeoutMinutes, int bookedMinutes, int totalIotaDeposit, int iotaPerMegaByte){
|
||||||
if (closed) {
|
|
||||||
bills = new ArrayList<Bill>();
|
bills = new ArrayList<Bill>();
|
||||||
this.bookedMegabytes = bookedMegabytes;
|
this.bookedMegabytes = bookedMegabytes;
|
||||||
this.timeoutMinutes = timeoutMinutes;
|
this.timeoutMinutes = timeoutMinutes;
|
||||||
@ -46,7 +45,6 @@ public class Accountant {
|
|||||||
this.bookedMinutes = bookedMinutes;
|
this.bookedMinutes = bookedMinutes;
|
||||||
closed = false;
|
closed = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastTime() {
|
public long getLastTime() {
|
||||||
if (bills.isEmpty()) {
|
if (bills.isEmpty()) {
|
||||||
@ -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() {
|
public boolean isCloseAfterwards() {
|
||||||
return closeAfterwards;
|
return closeAfterwards;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,6 +200,17 @@ public class BillingServer {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
socketWrapper.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
serverSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -101,6 +101,11 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetBillingState() {
|
||||||
|
billingClientIsRunning = false;
|
||||||
|
billingServerIsRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void startBillingServer(){
|
public void startBillingServer(){
|
||||||
if (!billingServerIsRunning) {
|
if (!billingServerIsRunning) {
|
||||||
billingServerIsRunning = true;
|
billingServerIsRunning = true;
|
||||||
@ -127,6 +132,8 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
//AsyncTask.execute(thread);
|
//AsyncTask.execute(thread);
|
||||||
threads.add(thread);
|
threads.add(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "startBillingServer: blocked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +160,8 @@ public class WiFiDirectBroadcastService extends Service {
|
|||||||
threads.add(thread);
|
threads.add(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
//AsyncTask.execute(thread);
|
//AsyncTask.execute(thread);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "startBillingClient: blocked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -119,4 +119,5 @@ public class PeerStore {
|
|||||||
public void setIPAddress(String macAddress, InetAddress IPAddress) {
|
public void setIPAddress(String macAddress, InetAddress IPAddress) {
|
||||||
getOrCreatePeer(macAddress.toLowerCase()).setIPAddress(IPAddress.getHostAddress());
|
getOrCreatePeer(macAddress.toLowerCase()).setIPAddress(IPAddress.getHostAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user