tls-psk: display warning if not connected to wifi before connecting
This commit is contained in:
parent
13873e934f
commit
a441df2bd7
|
@ -23,6 +23,8 @@ import java.util.List;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -76,6 +78,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
private KeyTransferInteractor keyTransferServerInteractor;
|
private KeyTransferInteractor keyTransferServerInteractor;
|
||||||
|
|
||||||
private boolean wasConnected = false;
|
private boolean wasConnected = false;
|
||||||
|
private boolean waitingForWifi = false;
|
||||||
|
|
||||||
public TransferPresenter(Context context, LoaderManager loaderManager, int loaderId, TransferMvpView view) {
|
public TransferPresenter(Context context, LoaderManager loaderManager, int loaderId, TransferMvpView view) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -95,7 +98,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
loaderManager.restartLoader(loaderId, null, this);
|
loaderManager.restartLoader(loaderId, null, this);
|
||||||
|
|
||||||
if (keyTransferServerInteractor == null && keyTransferClientInteractor == null && !wasConnected) {
|
if (keyTransferServerInteractor == null && keyTransferClientInteractor == null && !wasConnected) {
|
||||||
connectionResetAndStartListen();
|
checkWifiResetAndStartListen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +118,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
|
|
||||||
public void onUiBackStackPop() {
|
public void onUiBackStackPop() {
|
||||||
if (wasConnected) {
|
if (wasConnected) {
|
||||||
connectionResetAndStartListen();
|
checkWifiResetAndStartListen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +178,11 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
op.cryptoOperation();
|
op.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onWifiConnected() {
|
||||||
|
if (waitingForWifi) {
|
||||||
|
resetAndStartListen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerStarted(String qrCodeData) {
|
public void onServerStarted(String qrCodeData) {
|
||||||
|
@ -200,7 +208,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
Log.d(Constants.TAG, "Lost connection!");
|
Log.d(Constants.TAG, "Lost connection!");
|
||||||
if (!wasConnected) {
|
if (!wasConnected) {
|
||||||
view.showErrorConnectionFailed();
|
view.showErrorConnectionFailed();
|
||||||
connectionResetAndStartListen();
|
checkWifiResetAndStartListen();
|
||||||
} else {
|
} else {
|
||||||
view.showViewDisconnected();
|
view.showViewDisconnected();
|
||||||
secretKeyAdapter.setAllDisabled(true);
|
secretKeyAdapter.setAllDisabled(true);
|
||||||
|
@ -249,7 +257,18 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
keyTransferClientInteractor.connectToServer(qrCodeContent, this);
|
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;
|
wasConnected = false;
|
||||||
connectionClear();
|
connectionClear();
|
||||||
|
|
||||||
|
@ -259,6 +278,13 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
view.showWaitingForConnection();
|
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() {
|
private void connectionClear() {
|
||||||
if (keyTransferServerInteractor != null) {
|
if (keyTransferServerInteractor != null) {
|
||||||
keyTransferServerInteractor.closeConnection();
|
keyTransferServerInteractor.closeConnection();
|
||||||
|
@ -296,6 +322,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
||||||
|
|
||||||
|
|
||||||
public interface TransferMvpView {
|
public interface TransferMvpView {
|
||||||
|
void showNotOnWifi();
|
||||||
void showWaitingForConnection();
|
void showWaitingForConnection();
|
||||||
void showConnectionEstablished(String hostname);
|
void showConnectionEstablished(String hostname);
|
||||||
void showReceivingKeys();
|
void showReceivingKeys();
|
||||||
|
|
|
@ -19,8 +19,13 @@ package org.sufficientlysecure.keychain.ui.transfer.view;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
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_WAITING = 0;
|
||||||
public static final int VIEW_CONNECTED = 1;
|
public static final int VIEW_CONNECTED = 1;
|
||||||
public static final int VIEW_RECEIVING = 2;
|
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 REQUEST_CODE_SCAN = 1;
|
||||||
public static final int LOADER_ID = 1;
|
public static final int LOADER_ID = 1;
|
||||||
|
@ -72,6 +78,17 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
||||||
private RecyclerView vReceivedKeyList;
|
private RecyclerView vReceivedKeyList;
|
||||||
|
|
||||||
private CryptoOperationHelper currentCryptoOperationHelper;
|
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
|
@Override
|
||||||
|
@ -108,6 +125,22 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
||||||
presenter.onUiStart();
|
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
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
@ -115,6 +148,11 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
||||||
presenter.onUiStop();
|
presenter.onUiStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showNotOnWifi() {
|
||||||
|
vTransferAnimator.setDisplayedChild(VIEW_NO_WIFI);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showWaitingForConnection() {
|
public void showWaitingForConnection() {
|
||||||
vTransferAnimator.setDisplayedChild(VIEW_WAITING);
|
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:id="@+id/transfer_animator"
|
||||||
android:inAnimation="@anim/fade_in_delayed"
|
android:inAnimation="@anim/fade_in_delayed"
|
||||||
android:outAnimation="@anim/fade_out"
|
android:outAnimation="@anim/fade_out"
|
||||||
custom:initialView="02">
|
custom:initialView="03">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -140,4 +140,30 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</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>
|
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
|
4
graphics/drawables/ic_wifi_off.svg
Normal file
4
graphics/drawables/ic_wifi_off.svg
Normal 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 |
|
@ -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"
|
inkscape -w 96 -h 96 -e "$XXXDPI_DIR/${NAME}_24dp.png" "$SRC_DIR/$NAME.svg"
|
||||||
done
|
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
|
do
|
||||||
echo $NAME
|
echo $NAME
|
||||||
inkscape -w 96 -h 96 -e "$MDPI_DIR/${NAME}_96dp.png" "$SRC_DIR/$NAME.svg"
|
inkscape -w 96 -h 96 -e "$MDPI_DIR/${NAME}_96dp.png" "$SRC_DIR/$NAME.svg"
|
||||||
|
|
Loading…
Reference in a new issue