Merge branch 'master' into 'master'

improved, but still rudimentary, hotspot handling in swap

My previous merge request fdroid/fdroidclient!78 was based on one broken assumption: `WIFI_STATE_UNKNOWN` means that the hotspot is active.  Apparently, that's not always the case.  Also, sometimes when the hotspot is active, its `WIFI_STATE_DISABLED`.  Even worse, there is no broadcast message sent on final config of the hotspot.  There is only a `WIFI_STATE_DISABLING` from turning off the wifi, but then never a broadcast for `WIFI_STATE_UNKNOWN` and/or `WIFI_STATE_DISABLED`.  But I found some tricks that seem to work for now.  We'll need to use your library, @mvdan, to really get good support of hotspots.

This also includes some basic UI tweaks to represent the hotspot mode in the swap wifi screen.

See merge request !79
This commit is contained in:
Peter Serwylo 2015-05-10 22:39:12 +00:00
commit c33cacedaf
7 changed files with 39 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -300,6 +300,7 @@
<string name="app_description">F-Droid is an installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform. The client makes it easy to browse, install, and keep track of updates on your device.</string>
<string name="swap_nfc_description">If your friend has <b>F-Droid and NFC turned on</b> touch your phones together.</string>
<string name="swap_join_same_wifi">Join the same Wifi as your friend</string>
<string name="swap_join_this_hotspot">Help your friend join your hotspot</string>
<string name="swap_use_bluetooth">Use Bluetooth instead</string>
<string name="swap_wifi_help">Learn more about Wifi</string>
<string name="menu_swap">Swap apps</string>
@ -307,7 +308,9 @@
<string name="swap_repo_name">Swap</string>
<string name="swap_success">Swap success!</string>
<string name="swap_no_wifi_network">No network yet</string>
<string name="swap_active_hotspot">Your hotspot is active</string>
<string name="swap_view_available_networks">(Tap to open available networks)</string>
<string name="swap_switch_to_wifi">(Tap to switch to a WiFi network)</string>
<string name="swap_wifi_qr_not_working">It\'s not working</string>
<string name="open_qr_code_scanner">Open QR Code Scanner</string>
<string name="swap_welcome">Welcome to F-Droid!</string>

View File

@ -46,6 +46,8 @@ public class WifiStateChangeService extends Service {
NetworkInfo is only passed via WifiStateChangeReceiver */
Log.i(TAG, "ni == " + ni + " wifiState == " + printWifiState(wifiState));
if (wifiState == WifiManager.WIFI_STATE_ENABLED
|| wifiState == WifiManager.WIFI_STATE_DISABLING // might be switching to hotspot
|| wifiState == WifiManager.WIFI_STATE_DISABLED // might be hotspot
|| wifiState == WifiManager.WIFI_STATE_UNKNOWN) { // might be hotspot
if (asyncTask != null) {
asyncTask.cancel(true);
@ -73,9 +75,15 @@ public class WifiStateChangeService extends Service {
if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
wifiInfo = wifiManager.getConnectionInfo();
FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress());
} else
} else if (wifiState == WifiManager.WIFI_STATE_DISABLED
|| wifiState == WifiManager.WIFI_STATE_DISABLING) {
// try once to see if its a hotspot
FDroidApp.ipAddressString = getIpAddressFromNetworkInterface();
// TODO turning off a hotspot leaves wifiState as UNKNOWN with no IP, and this goes until next wifi change
if (FDroidApp.ipAddressString == null)
return null;
} else { // a hotspot can be active during WIFI_STATE_UNKNOWN
FDroidApp.ipAddressString = getIpAddressFromNetworkInterface();
}
Thread.sleep(1000);
if (BuildConfig.DEBUG) {
Log.d(TAG, "waiting for an IP address...");

View File

@ -17,6 +17,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.fdroid.fdroid.FDroidApp;
@ -74,10 +75,31 @@ public class JoinWifiFragment extends Fragment {
}
private void refreshWifiState() {
if (getView() != null) {
TextView ssidView = (TextView) getView().findViewById(R.id.wifi_ssid);
String text = TextUtils.isEmpty(FDroidApp.ssid) ? getString(R.string.swap_no_wifi_network) : FDroidApp.ssid;
ssidView.setText(text);
View view = getView();
if (view != null) {
TextView descriptionView = (TextView) view.findViewById(R.id.text_description);
ImageView wifiIcon = (ImageView) view.findViewById(R.id.wifi_icon);
TextView ssidView = (TextView) view.findViewById(R.id.wifi_ssid);
TextView tapView = (TextView) view.findViewById(R.id.wifi_available_networks_prompt);
if (TextUtils.isEmpty(FDroidApp.bssid) && !TextUtils.isEmpty(FDroidApp.ipAddressString)) {
// empty bssid with an ipAddress means hotspot mode
descriptionView.setText(R.string.swap_join_this_hotspot);
wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.hotspot));
ssidView.setText(R.string.swap_active_hotspot);
tapView.setText(R.string.swap_switch_to_wifi);
} else if (TextUtils.isEmpty(FDroidApp.ssid)) {
// not connected to or setup with any wifi network
descriptionView.setText(R.string.swap_join_same_wifi);
wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi));
ssidView.setText(R.string.swap_no_wifi_network);
tapView.setText(R.string.swap_view_available_networks);
} else {
// connected to a regular wifi network
descriptionView.setText(R.string.swap_join_same_wifi);
wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi));
ssidView.setText(FDroidApp.ssid);
tapView.setText(R.string.swap_view_available_networks);
}
}
}