mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Bluetooth-only invitations: simpler and more reliable.
Of course, not all devices support Bluetooth...
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
||||
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||
import static android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -33,13 +28,7 @@ import org.briarproject.api.invitation.InvitationTask;
|
||||
import org.briarproject.api.invitation.InvitationTaskFactory;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -56,9 +45,6 @@ implements InvitationListener {
|
||||
private InvitationTask task = null;
|
||||
private long taskHandle = -1;
|
||||
private AuthorId localAuthorId = null;
|
||||
private String networkName = null;
|
||||
private boolean bluetoothEnabled = false;
|
||||
private BluetoothWifiStateReceiver receiver = null;
|
||||
private int localInvitationCode = -1, remoteInvitationCode = -1;
|
||||
private int localConfirmationCode = -1, remoteConfirmationCode = -1;
|
||||
private boolean connected = false, connectionFailed = false;
|
||||
@@ -76,7 +62,7 @@ implements InvitationListener {
|
||||
super.onCreate(state);
|
||||
if(state == null) {
|
||||
// This is a new activity
|
||||
setView(new NetworkSetupView(this));
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else {
|
||||
// Restore the activity's state
|
||||
byte[] b = state.getByteArray("briar.LOCAL_AUTHOR_ID");
|
||||
@@ -96,7 +82,7 @@ implements InvitationListener {
|
||||
}
|
||||
// Set the appropriate view for the state
|
||||
if(localInvitationCode == -1) {
|
||||
setView(new NetworkSetupView(this));
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else if(remoteInvitationCode == -1) {
|
||||
setView(new InvitationCodeView(this));
|
||||
} else if(connectionFailed) {
|
||||
@@ -123,7 +109,7 @@ implements InvitationListener {
|
||||
contactName = s.getContactName();
|
||||
// Set the appropriate view for the state
|
||||
if(localInvitationCode == -1) {
|
||||
setView(new NetworkSetupView(this));
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else if(remoteInvitationCode == -1) {
|
||||
setView(new InvitationCodeView(this));
|
||||
} else if(connectionFailed) {
|
||||
@@ -148,25 +134,6 @@ implements InvitationListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for Bluetooth and WiFi state changes
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_STATE_CHANGED);
|
||||
filter.addAction(ACTION_SCAN_MODE_CHANGED);
|
||||
filter.addAction(NETWORK_STATE_CHANGED_ACTION);
|
||||
receiver = new BluetoothWifiStateReceiver();
|
||||
registerReceiver(receiver, filter);
|
||||
|
||||
// Get the current Bluetooth and WiFi state
|
||||
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
||||
if(bluetooth != null) bluetoothEnabled = bluetooth.isEnabled();
|
||||
view.bluetoothStateChanged();
|
||||
WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
if(wifi != null && wifi.isWifiEnabled()) {
|
||||
WifiInfo info = wifi.getConnectionInfo();
|
||||
if(info.getNetworkId() != -1) networkName = info.getSSID();
|
||||
}
|
||||
view.wifiStateChanged();
|
||||
}
|
||||
|
||||
private void showToastAndFinish() {
|
||||
@@ -198,7 +165,13 @@ implements InvitationListener {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(task != null) task.removeListener(this);
|
||||
if(receiver != null) unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
// This is the result of enabling Bluetooth
|
||||
if(result != RESULT_CANCELED)
|
||||
reset(new InvitationCodeView(this));
|
||||
}
|
||||
|
||||
void setView(AddContactView view) {
|
||||
@@ -208,7 +181,7 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
void reset(AddContactView view) {
|
||||
// Don't reset localAuthorId, networkName or bluetoothEnabled
|
||||
// Don't reset localAuthorId
|
||||
task = null;
|
||||
taskHandle = -1;
|
||||
localInvitationCode = -1;
|
||||
@@ -264,23 +237,20 @@ implements InvitationListener {
|
||||
return localAuthorId;
|
||||
}
|
||||
|
||||
String getNetworkName() {
|
||||
return networkName;
|
||||
}
|
||||
|
||||
boolean isBluetoothEnabled() {
|
||||
return bluetoothEnabled;
|
||||
}
|
||||
|
||||
int getLocalInvitationCode() {
|
||||
if(localInvitationCode == -1)
|
||||
localInvitationCode = crypto.generateInvitationCode();
|
||||
return localInvitationCode;
|
||||
}
|
||||
|
||||
int getRemoteInvitationCode() {
|
||||
return remoteInvitationCode;
|
||||
}
|
||||
|
||||
void remoteInvitationCodeEntered(int code) {
|
||||
if(localAuthorId == null) throw new IllegalStateException();
|
||||
if(localInvitationCode == -1) throw new IllegalStateException();
|
||||
remoteInvitationCode = code;
|
||||
setView(new ConnectionView(this));
|
||||
task = invitationTaskFactory.createTask(localAuthorId,
|
||||
localInvitationCode, code);
|
||||
@@ -392,30 +362,6 @@ implements InvitationListener {
|
||||
});
|
||||
}
|
||||
|
||||
private class BluetoothWifiStateReceiver extends BroadcastReceiver {
|
||||
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if(action.equals(ACTION_STATE_CHANGED)) {
|
||||
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||
bluetoothEnabled = state == STATE_ON;
|
||||
view.bluetoothStateChanged();
|
||||
} else if(action.equals(ACTION_SCAN_MODE_CHANGED)) {
|
||||
view.bluetoothStateChanged();
|
||||
} else if(action.equals(NETWORK_STATE_CHANGED_ACTION)) {
|
||||
WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
if(wifi == null || !wifi.isWifiEnabled()) {
|
||||
networkName = null;
|
||||
} else {
|
||||
WifiInfo info = wifi.getConnectionInfo();
|
||||
if(info.getNetworkId() == -1) networkName = null;
|
||||
else networkName = info.getSSID();
|
||||
}
|
||||
view.wifiStateChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the reference to the invitation task when the task completes.
|
||||
* This class is static to prevent memory leaks.
|
||||
|
||||
@@ -28,8 +28,4 @@ abstract class AddContactView extends LinearLayout {
|
||||
}
|
||||
|
||||
abstract void populate();
|
||||
|
||||
void wifiStateChanged() {}
|
||||
|
||||
void bluetoothStateChanged() {}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.provider.Settings.ACTION_BLUETOOTH_SETTINGS;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
class BluetoothStatusView extends LinearLayout implements OnClickListener {
|
||||
|
||||
private final int pad;
|
||||
|
||||
public BluetoothStatusView(Context ctx) {
|
||||
super(ctx);
|
||||
pad = LayoutUtils.getPadding(ctx);
|
||||
}
|
||||
|
||||
void init() {
|
||||
setOrientation(HORIZONTAL);
|
||||
setGravity(CENTER);
|
||||
populate();
|
||||
}
|
||||
|
||||
void populate() {
|
||||
removeAllViews();
|
||||
Context ctx = getContext();
|
||||
TextView status = new TextView(ctx);
|
||||
status.setLayoutParams(WRAP_WRAP_1);
|
||||
status.setTextSize(14);
|
||||
status.setPadding(pad, pad, pad, pad);
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if(adapter == null) {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.bluetooth_not_available);
|
||||
addView(status);
|
||||
} else if(adapter.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
ImageView ok = new ImageView(ctx);
|
||||
ok.setPadding(pad, pad, pad, pad);
|
||||
ok.setImageResource(R.drawable.navigation_accept);
|
||||
addView(ok);
|
||||
status.setText(R.string.bluetooth_discoverable);
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
} else if(adapter.isEnabled()) {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.bluetooth_not_discoverable);
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
} else {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.bluetooth_disabled);
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(new Intent(ACTION_BLUETOOTH_SETTINGS));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static org.briarproject.android.identity.LocalAuthorItem.NEW;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
@@ -9,7 +11,6 @@ import org.briarproject.R;
|
||||
import org.briarproject.android.identity.CreateIdentityActivity;
|
||||
import org.briarproject.android.identity.LocalAuthorItem;
|
||||
import org.briarproject.android.identity.LocalAuthorSpinnerAdapter;
|
||||
import org.briarproject.api.AuthorId;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -22,16 +23,14 @@ import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
class NetworkSetupView extends AddContactView
|
||||
class ChooseIdentityView extends AddContactView
|
||||
implements OnItemSelectedListener, OnClickListener {
|
||||
|
||||
private LocalAuthorSpinnerAdapter adapter = null;
|
||||
private Spinner spinner = null;
|
||||
private WifiStatusView wifi = null;
|
||||
private BluetoothStatusView bluetooth = null;
|
||||
private Button continueButton = null;
|
||||
|
||||
NetworkSetupView(Context ctx) {
|
||||
ChooseIdentityView(Context ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
@@ -58,48 +57,19 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
innerLayout.addView(spinner);
|
||||
addView(innerLayout);
|
||||
|
||||
wifi = new WifiStatusView(ctx);
|
||||
wifi.init();
|
||||
addView(wifi);
|
||||
|
||||
bluetooth = new BluetoothStatusView(ctx);
|
||||
bluetooth.init();
|
||||
addView(bluetooth);
|
||||
|
||||
TextView faceToFace = new TextView(ctx);
|
||||
faceToFace.setGravity(CENTER);
|
||||
faceToFace.setTextSize(14);
|
||||
faceToFace.setPadding(pad, pad, pad, pad);
|
||||
faceToFace.setText(R.string.fact_to_face);
|
||||
faceToFace.setText(R.string.face_to_face);
|
||||
addView(faceToFace);
|
||||
|
||||
continueButton = new Button(ctx);
|
||||
continueButton.setLayoutParams(WRAP_WRAP);
|
||||
continueButton.setText(R.string.continue_button);
|
||||
continueButton.setOnClickListener(this);
|
||||
enableOrDisableContinueButton();
|
||||
addView(continueButton);
|
||||
}
|
||||
|
||||
void wifiStateChanged() {
|
||||
if(wifi != null) wifi.populate();
|
||||
enableOrDisableContinueButton();
|
||||
}
|
||||
|
||||
void bluetoothStateChanged() {
|
||||
if(bluetooth != null) bluetooth.populate();
|
||||
enableOrDisableContinueButton();
|
||||
}
|
||||
|
||||
private void enableOrDisableContinueButton() {
|
||||
if(continueButton == null) return; // Activity not created yet
|
||||
AuthorId localAuthorId = container.getLocalAuthorId();
|
||||
boolean bluetoothEnabled = container.isBluetoothEnabled();
|
||||
String networkName = container.getNetworkName();
|
||||
boolean networkAvailable = bluetoothEnabled || networkName != null;
|
||||
continueButton.setEnabled(localAuthorId != null && networkAvailable);
|
||||
}
|
||||
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
LocalAuthorItem item = adapter.getItem(position);
|
||||
@@ -110,7 +80,6 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
} else {
|
||||
container.setLocalAuthorId(item.getLocalAuthor().getId());
|
||||
}
|
||||
enableOrDisableContinueButton();
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
@@ -118,6 +87,8 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
container.setView(new InvitationCodeView(container));
|
||||
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
|
||||
i.putExtra(EXTRA_DISCOVERABLE_DURATION, 120);
|
||||
container.startActivityForResult(i, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
|
||||
import org.briarproject.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
@@ -38,6 +41,7 @@ class CodesDoNotMatchView extends AddContactView implements OnClickListener {
|
||||
addView(innerLayout);
|
||||
|
||||
TextView interfering = new TextView(ctx);
|
||||
interfering.setGravity(CENTER);
|
||||
interfering.setTextSize(14);
|
||||
interfering.setPadding(pad, 0, pad, pad);
|
||||
interfering.setText(R.string.interfering);
|
||||
@@ -51,7 +55,8 @@ class CodesDoNotMatchView extends AddContactView implements OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
// Try again
|
||||
container.reset(new NetworkSetupView(container));
|
||||
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
|
||||
i.putExtra(EXTRA_DISCOVERABLE_DURATION, 120);
|
||||
container.startActivityForResult(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
|
||||
import org.briarproject.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
@@ -15,8 +18,6 @@ import android.widget.TextView;
|
||||
|
||||
class ConnectionFailedView extends AddContactView implements OnClickListener {
|
||||
|
||||
private WifiStatusView wifi = null;
|
||||
private BluetoothStatusView bluetooth = null;
|
||||
private Button tryAgainButton = null;
|
||||
|
||||
ConnectionFailedView(Context ctx) {
|
||||
@@ -41,47 +42,23 @@ class ConnectionFailedView extends AddContactView implements OnClickListener {
|
||||
innerLayout.addView(failed);
|
||||
addView(innerLayout);
|
||||
|
||||
TextView checkNetwork = new TextView(ctx);
|
||||
checkNetwork.setTextSize(14);
|
||||
checkNetwork.setPadding(pad, 0, pad, pad);
|
||||
checkNetwork.setText(R.string.check_same_network);
|
||||
addView(checkNetwork);
|
||||
|
||||
wifi = new WifiStatusView(ctx);
|
||||
wifi.init();
|
||||
addView(wifi);
|
||||
|
||||
bluetooth = new BluetoothStatusView(ctx);
|
||||
bluetooth.init();
|
||||
addView(bluetooth);
|
||||
TextView couldNotFind = new TextView(ctx);
|
||||
couldNotFind.setGravity(CENTER);
|
||||
couldNotFind.setTextSize(14);
|
||||
couldNotFind.setPadding(pad, 0, pad, pad);
|
||||
couldNotFind.setText(R.string.could_not_find_contact);
|
||||
addView(couldNotFind);
|
||||
|
||||
tryAgainButton = new Button(ctx);
|
||||
tryAgainButton.setLayoutParams(WRAP_WRAP);
|
||||
tryAgainButton.setText(R.string.try_again_button);
|
||||
tryAgainButton.setOnClickListener(this);
|
||||
enableOrDisableTryAgainButton();
|
||||
addView(tryAgainButton);
|
||||
}
|
||||
|
||||
void wifiStateChanged() {
|
||||
if(wifi != null) wifi.populate();
|
||||
enableOrDisableTryAgainButton();
|
||||
}
|
||||
|
||||
void bluetoothStateChanged() {
|
||||
if(bluetooth != null) bluetooth.populate();
|
||||
enableOrDisableTryAgainButton();
|
||||
}
|
||||
|
||||
private void enableOrDisableTryAgainButton() {
|
||||
if(tryAgainButton == null) return; // Activity not created yet
|
||||
boolean bluetoothEnabled = container.isBluetoothEnabled();
|
||||
String networkName = container.getNetworkName();
|
||||
tryAgainButton.setEnabled(bluetoothEnabled || networkName != null);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
// Try again
|
||||
container.reset(new InvitationCodeView(container));
|
||||
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
|
||||
i.putExtra(EXTRA_DISCOVERABLE_DURATION, 120);
|
||||
container.startActivityForResult(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,41 +34,21 @@ class ConnectionView extends AddContactView {
|
||||
code.setText(String.format("%06d", localCode));
|
||||
addView(code);
|
||||
|
||||
String networkName = container.getNetworkName();
|
||||
if(networkName != null) {
|
||||
LinearLayout innerLayout = new LinearLayout(ctx);
|
||||
innerLayout.setOrientation(HORIZONTAL);
|
||||
innerLayout.setGravity(CENTER);
|
||||
LinearLayout innerLayout = new LinearLayout(ctx);
|
||||
innerLayout.setOrientation(HORIZONTAL);
|
||||
innerLayout.setGravity(CENTER);
|
||||
|
||||
ProgressBar progress = new ProgressBar(ctx);
|
||||
progress.setIndeterminate(true);
|
||||
progress.setPadding(pad, pad, pad, pad);
|
||||
innerLayout.addView(progress);
|
||||
ProgressBar progress = new ProgressBar(ctx);
|
||||
progress.setPadding(pad, pad, pad, pad);
|
||||
progress.setIndeterminate(true);
|
||||
innerLayout.addView(progress);
|
||||
|
||||
TextView connecting = new TextView(ctx);
|
||||
String format = getResources().getString(
|
||||
R.string.format_connecting_wifi);
|
||||
connecting.setText(String.format(format, networkName));
|
||||
innerLayout.addView(connecting);
|
||||
TextView connecting = new TextView(ctx);
|
||||
int remoteCode = container.getRemoteInvitationCode();
|
||||
String format = ctx.getResources().getString(R.string.searching_format);
|
||||
connecting.setText(String.format(format, remoteCode));
|
||||
innerLayout.addView(connecting);
|
||||
|
||||
addView(innerLayout);
|
||||
}
|
||||
|
||||
if(container.isBluetoothEnabled()) {
|
||||
LinearLayout innerLayout = new LinearLayout(ctx);
|
||||
innerLayout.setOrientation(HORIZONTAL);
|
||||
innerLayout.setGravity(CENTER);
|
||||
|
||||
ProgressBar progress = new ProgressBar(ctx);
|
||||
progress.setPadding(pad, pad, pad, pad);
|
||||
progress.setIndeterminate(true);
|
||||
innerLayout.addView(progress);
|
||||
|
||||
TextView connecting = new TextView(ctx);
|
||||
connecting.setText(R.string.connecting_bluetooth);
|
||||
innerLayout.addView(connecting);
|
||||
|
||||
addView(innerLayout);
|
||||
}
|
||||
addView(innerLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package org.briarproject.android.invitation;
|
||||
|
||||
import static android.content.Context.WIFI_SERVICE;
|
||||
import static android.provider.Settings.ACTION_WIFI_SETTINGS;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
class WifiStatusView extends LinearLayout implements OnClickListener {
|
||||
|
||||
private final int pad;
|
||||
|
||||
public WifiStatusView(Context ctx) {
|
||||
super(ctx);
|
||||
pad = LayoutUtils.getPadding(ctx);
|
||||
}
|
||||
|
||||
void init() {
|
||||
setOrientation(HORIZONTAL);
|
||||
setGravity(CENTER);
|
||||
populate();
|
||||
}
|
||||
|
||||
void populate() {
|
||||
removeAllViews();
|
||||
Context ctx = getContext();
|
||||
TextView status = new TextView(ctx);
|
||||
status.setTextSize(14);
|
||||
status.setPadding(pad, pad, pad, pad);
|
||||
status.setLayoutParams(WRAP_WRAP_1);
|
||||
WifiManager wifi = (WifiManager) ctx.getSystemService(WIFI_SERVICE);
|
||||
if(wifi == null) {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.wifi_not_available);
|
||||
addView(status);
|
||||
} else if(wifi.isWifiEnabled()) {
|
||||
WifiInfo info = wifi.getConnectionInfo();
|
||||
String networkName = info.getSSID();
|
||||
int networkId = info.getNetworkId();
|
||||
if(networkName == null || networkId == -1) {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.wifi_disconnected);
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
} else {
|
||||
ImageView ok = new ImageView(ctx);
|
||||
ok.setPadding(pad, pad, pad, pad);
|
||||
ok.setImageResource(R.drawable.navigation_accept);
|
||||
addView(ok);
|
||||
String format = getResources().getString(
|
||||
R.string.format_wifi_connected);
|
||||
status.setText(String.format(format, networkName));
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
}
|
||||
} else {
|
||||
ImageView warning = new ImageView(ctx);
|
||||
warning.setPadding(pad, pad, pad, pad);
|
||||
warning.setImageResource(R.drawable.alerts_and_states_warning);
|
||||
addView(warning);
|
||||
status.setText(R.string.wifi_disabled);
|
||||
addView(status);
|
||||
ImageButton settings = new ImageButton(ctx);
|
||||
settings.setImageResource(R.drawable.action_settings);
|
||||
settings.setOnClickListener(this);
|
||||
addView(settings);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(new Intent(ACTION_WIFI_SETTINGS));
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
|
||||
import org.briarproject.plugins.tcp.DroidLanTcpPluginFactory;
|
||||
import org.briarproject.plugins.tcp.LanTcpPluginFactory;
|
||||
import org.briarproject.plugins.tor.TorPluginFactory;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -45,8 +45,7 @@ public class AndroidPluginsModule extends AbstractModule {
|
||||
crypto.getSecureRandom());
|
||||
DuplexPluginFactory tor = new TorPluginFactory(pluginExecutor,
|
||||
appContext, shutdownManager);
|
||||
DuplexPluginFactory lan = new DroidLanTcpPluginFactory(pluginExecutor,
|
||||
appContext);
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(pluginExecutor);
|
||||
final Collection<DuplexPluginFactory> factories =
|
||||
Arrays.asList(droidtooth, tor, lan);
|
||||
return new DuplexPluginConfig() {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.briarproject.plugins.tcp;
|
||||
|
||||
import static android.content.Context.WIFI_SERVICE;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.briarproject.api.crypto.PseudoRandom;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.api.system.Clock;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.MulticastLock;
|
||||
|
||||
class DroidLanTcpPlugin extends LanTcpPlugin {
|
||||
|
||||
private final Context appContext;
|
||||
|
||||
DroidLanTcpPlugin(Executor pluginExecutor, Context appContext, Clock clock,
|
||||
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||
long pollingInterval) {
|
||||
super(pluginExecutor, clock, callback, maxFrameLength, maxLatency,
|
||||
pollingInterval);
|
||||
this.appContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createInvitationConnection(PseudoRandom r,
|
||||
long timeout) {
|
||||
Object o = appContext.getSystemService(WIFI_SERVICE);
|
||||
WifiManager wifi = (WifiManager) o;
|
||||
if(wifi == null || !wifi.isWifiEnabled()) return null;
|
||||
MulticastLock lock = wifi.createMulticastLock("invitation");
|
||||
lock.acquire();
|
||||
try {
|
||||
return super.createInvitationConnection(r, timeout);
|
||||
} finally {
|
||||
lock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.briarproject.plugins.tcp;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.system.SystemClock;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class DroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_FRAME_LENGTH = 1024;
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Context appContext;
|
||||
private final Clock clock;
|
||||
|
||||
public DroidLanTcpPluginFactory(Executor pluginExecutor,
|
||||
Context appContext) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.appContext = appContext;
|
||||
clock = new SystemClock();
|
||||
}
|
||||
|
||||
public TransportId getId() {
|
||||
return LanTcpPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
return new DroidLanTcpPlugin(pluginExecutor, appContext, clock,
|
||||
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user