tls-psk: display warning if not connected to wifi before connecting
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_wifi_off_96dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_wifi_off_96dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_wifi_off_96dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_wifi_off_96dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
OpenKeychain/src/main/res/drawable-xhdpi/ic_wifi_off_96dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-xhdpi/ic_wifi_off_96dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
OpenKeychain/src/main/res/drawable-xxhdpi/ic_wifi_off_96dp.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-xxhdpi/ic_wifi_off_96dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -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>
|
||||
Reference in New Issue
Block a user