tls-psk: display warning if not connected to wifi before connecting

This commit is contained in:
Vincent Breitmoser 2017-05-30 22:37:53 +02:00
parent 13873e934f
commit a441df2bd7
9 changed files with 101 additions and 6 deletions

View File

@ -23,6 +23,8 @@ import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
@ -76,6 +78,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
private KeyTransferInteractor keyTransferServerInteractor;
private boolean wasConnected = false;
private boolean waitingForWifi = false;
public TransferPresenter(Context context, LoaderManager loaderManager, int loaderId, TransferMvpView view) {
this.context = context;
@ -95,7 +98,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
loaderManager.restartLoader(loaderId, null, this);
if (keyTransferServerInteractor == null && keyTransferClientInteractor == null && !wasConnected) {
connectionResetAndStartListen();
checkWifiResetAndStartListen();
}
}
@ -115,7 +118,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
public void onUiBackStackPop() {
if (wasConnected) {
connectionResetAndStartListen();
checkWifiResetAndStartListen();
}
}
@ -175,6 +178,11 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
op.cryptoOperation();
}
public void onWifiConnected() {
if (waitingForWifi) {
resetAndStartListen();
}
}
@Override
public void onServerStarted(String qrCodeData) {
@ -200,7 +208,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
Log.d(Constants.TAG, "Lost connection!");
if (!wasConnected) {
view.showErrorConnectionFailed();
connectionResetAndStartListen();
checkWifiResetAndStartListen();
} else {
view.showViewDisconnected();
secretKeyAdapter.setAllDisabled(true);
@ -249,7 +257,18 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
keyTransferClientInteractor.connectToServer(qrCodeContent, this);
}
private void connectionResetAndStartListen() {
private void checkWifiResetAndStartListen() {
if (!isWifiConnected()) {
waitingForWifi = true;
view.showNotOnWifi();
return;
}
resetAndStartListen();
}
private void resetAndStartListen() {
waitingForWifi = false;
wasConnected = false;
connectionClear();
@ -259,6 +278,13 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
view.showWaitingForConnection();
}
private boolean isWifiConnected() {
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetwork = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return wifiNetwork.isConnected();
}
private void connectionClear() {
if (keyTransferServerInteractor != null) {
keyTransferServerInteractor.closeConnection();
@ -296,6 +322,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
public interface TransferMvpView {
void showNotOnWifi();
void showWaitingForConnection();
void showConnectionEstablished(String hostname);
void showReceivingKeys();

View File

@ -19,8 +19,13 @@ package org.sufficientlysecure.keychain.ui.transfer.view;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Parcelable;
@ -58,6 +63,7 @@ public class TransferFragment extends Fragment implements TransferMvpView {
public static final int VIEW_WAITING = 0;
public static final int VIEW_CONNECTED = 1;
public static final int VIEW_RECEIVING = 2;
public static final int VIEW_NO_WIFI = 3;
public static final int REQUEST_CODE_SCAN = 1;
public static final int LOADER_ID = 1;
@ -72,6 +78,17 @@ public class TransferFragment extends Fragment implements TransferMvpView {
private RecyclerView vReceivedKeyList;
private CryptoOperationHelper currentCryptoOperationHelper;
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (networkInfo != null && networkInfo.isConnected()) {
presenter.onWifiConnected();
}
}
}
};
@Override
@ -108,6 +125,22 @@ public class TransferFragment extends Fragment implements TransferMvpView {
presenter.onUiStart();
}
@Override
public void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
getContext().registerReceiver(broadcastReceiver, intentFilter);
}
@Override
public void onPause() {
super.onPause();
getContext().unregisterReceiver(broadcastReceiver);
}
@Override
public void onStop() {
super.onStop();
@ -115,6 +148,11 @@ public class TransferFragment extends Fragment implements TransferMvpView {
presenter.onUiStop();
}
@Override
public void showNotOnWifi() {
vTransferAnimator.setDisplayedChild(VIEW_NO_WIFI);
}
@Override
public void showWaitingForConnection() {
vTransferAnimator.setDisplayedChild(VIEW_WAITING);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -8,7 +8,7 @@
android:id="@+id/transfer_animator"
android:inAnimation="@anim/fade_in_delayed"
android:outAnimation="@anim/fade_out"
custom:initialView="02">
custom:initialView="03">
<LinearLayout
android:layout_width="match_parent"
@ -140,4 +140,30 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_wifi_off_96dp"
android:tint="@color/md_grey_600"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="This feature can only be used on Wifi."
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>

View File

@ -0,0 +1,4 @@
<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M23.64 7c-.45-.34-4.93-4-11.64-4-1.5 0-2.89.19-4.15.48L18.18 13.8 23.64 7zm-6.6 8.22L3.27 1.44 2 2.72l2.05 2.06C1.91 5.76.59 6.82.36 7l11.63 14.49.01.01.01-.01 3.9-4.86 3.32 3.32 1.27-1.27-3.46-3.46z"/>
</svg>

After

Width:  |  Height:  |  Size: 363 B

View File

@ -32,7 +32,7 @@ inkscape -w 72 -h 72 -e "$XXDPI_DIR/${NAME}_24dp.png" "$SRC_DIR/$NAME.svg"
inkscape -w 96 -h 96 -e "$XXXDPI_DIR/${NAME}_24dp.png" "$SRC_DIR/$NAME.svg"
done
for NAME in "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "status_signature_verified_inner"
for NAME in "ic_wifi_off" "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "status_signature_verified_inner"
do
echo $NAME
inkscape -w 96 -h 96 -e "$MDPI_DIR/${NAME}_96dp.png" "$SRC_DIR/$NAME.svg"