fdo#61873 - add WiFi experimental feature alert.
fixes reconnect crash. Won't crash when server-end disconnect. seperate Client construction and initialization so that Client() will release its mutex lock and won't block service.run(). Otherwise onBackPressed() will be blocked in PairingActivity Change-Id: I424a470aa02b0c74b28cb9f9ba79489aa0d4ab1b
This commit is contained in:
committed by
Michael Meeks
parent
e5fb76a402
commit
38cc47f8b1
@@ -57,6 +57,11 @@
|
|||||||
android:icon="@drawable/icon_options"
|
android:icon="@drawable/icon_options"
|
||||||
android:label="@string/options" >
|
android:label="@string/options" >
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".communication.ReconnectionActivity"
|
||||||
|
android:logo="@drawable/actionbar_icon_computer"
|
||||||
|
android:label="@string/reconnect" >
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -40,7 +40,17 @@
|
|||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/reconnect_description2"
|
android:text="@string/reconnect_description2"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/countDownTV"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@@ -3,8 +3,18 @@
|
|||||||
android:id="@+id/addserver_root"
|
android:id="@+id/addserver_root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:padding="12dp"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/wifiAlertMsg"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:text="@string/wifiAlertMsg"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:typeface="serif" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/addserver_namelabel"
|
android:id="@+id/addserver_namelabel"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -43,4 +53,4 @@
|
|||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/addserver_remember" />
|
android:text="@string/addserver_remember" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
<string name="presentation_ui_resizehandle">Handle to resize view.</string>
|
<string name="presentation_ui_resizehandle">Handle to resize view.</string>
|
||||||
<string name="presentation_blank_screen">Blank Screen</string>
|
<string name="presentation_blank_screen">Blank Screen</string>
|
||||||
<string name="options">Options</string>
|
<string name="options">Options</string>
|
||||||
|
<string name="reconnect">Reconnect...</string>
|
||||||
<string name="actionbar_timeformat">h:mmaa</string>
|
<string name="actionbar_timeformat">h:mmaa</string>
|
||||||
<string name="actionbar_timerformat">mm:ss</string>
|
<string name="actionbar_timerformat">mm:ss</string>
|
||||||
<string name="clock_timer_start">Start</string>
|
<string name="clock_timer_start">Start</string>
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
<string name="clock_timer_reset">Reset</string>
|
<string name="clock_timer_reset">Reset</string>
|
||||||
<string name="clock_timer_resume">Resume</string>
|
<string name="clock_timer_resume">Resume</string>
|
||||||
<string name="options_autodecline">Decline Calls</string>
|
<string name="options_autodecline">Decline Calls</string>
|
||||||
|
<string name="help">Help</string>
|
||||||
|
<string name="ConnectionFailedHelp">#1 Verify Impress is running \n#2 For Bluetooth user, enable \"Preference\"-\"LibreOffice Impress\"-\"General\"-\"Enable remote control\"\n#3 For WiFi user, tick \"Preferece\"-\"LibreOffice\"-\"Advanced\"-\"Enable Experimental Features\" \n </string>
|
||||||
<string name="options_description">Automatically decline all incoming calls.</string>
|
<string name="options_description">Automatically decline all incoming calls.</string>
|
||||||
<string name="options_volumeswitching">Volume Switching</string>
|
<string name="options_volumeswitching">Volume Switching</string>
|
||||||
<string name="options_volumeswitching_descripton">Change slides using volume buttons</string>
|
<string name="options_volumeswitching_descripton">Change slides using volume buttons</string>
|
||||||
@@ -49,6 +52,7 @@
|
|||||||
<string name="addserver_add">Add</string>
|
<string name="addserver_add">Add</string>
|
||||||
<string name="addserver_cancel">Cancel</string>
|
<string name="addserver_cancel">Cancel</string>
|
||||||
<string name="reconnect_description1">Your connection has been dropped.</string>
|
<string name="reconnect_description1">Your connection has been dropped.</string>
|
||||||
<string name="reconnect_description2">Attempting to reconnect…</string>
|
<string name="reconnect_description2">Please try to reconnect</string>
|
||||||
|
<string name="wifiAlertMsg">This is still an experimental feature. You need to \"enable experimental features\" in \"Preference\"-\"LibreOffice\"-\"Advanced\" on your computer. \nThe use over Bluetooth is recommanded.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -10,18 +10,25 @@ package org.libreoffice.impressremote;
|
|||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import org.libreoffice.impressremote.communication.CommunicationService;
|
||||||
|
import org.libreoffice.impressremote.communication.CommunicationService.State;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class PairingActivity extends SherlockActivity {
|
public class PairingActivity extends SherlockActivity {
|
||||||
private ActivityChangeBroadcastProcessor mBroadcastProcessor;
|
private ActivityChangeBroadcastProcessor mBroadcastProcessor;
|
||||||
|
private CommunicationService mCommunicationService;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
@@ -29,8 +36,8 @@ public class PairingActivity extends SherlockActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.activity_pairing);
|
setContentView(R.layout.activity_pairing);
|
||||||
|
bindService(new Intent(this, CommunicationService.class), mConnection,
|
||||||
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
Context.BIND_IMPORTANT);
|
||||||
|
|
||||||
IntentFilter aFilter = new IntentFilter();
|
IntentFilter aFilter = new IntentFilter();
|
||||||
|
|
||||||
@@ -55,6 +62,22 @@ public class PairingActivity extends SherlockActivity {
|
|||||||
getSupportActionBar().setTitle(aServerName);
|
getSupportActionBar().setTitle(aServerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause(){
|
||||||
|
super.onPause();
|
||||||
|
unbindService(mConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
mCommunicationService.getClient().closeConnection();
|
||||||
|
|
||||||
|
Intent aIntent = new Intent(this, SelectorActivity.class);
|
||||||
|
aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(aIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private BroadcastReceiver mListener = new BroadcastReceiver() {
|
private BroadcastReceiver mListener = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,6 +86,32 @@ public class PairingActivity extends SherlockActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName aClassName,
|
||||||
|
IBinder aService) {
|
||||||
|
mCommunicationService = ((CommunicationService.CBinder) aService)
|
||||||
|
.getService();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName aClassName) {
|
||||||
|
mCommunicationService = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -63,6 +63,8 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_selector);
|
setContentView(R.layout.activity_selector);
|
||||||
|
|
||||||
|
if (mCommunicationService != null)
|
||||||
|
mCommunicationService.disconnect();
|
||||||
IntentFilter aFilter = new IntentFilter(
|
IntentFilter aFilter = new IntentFilter(
|
||||||
CommunicationService.MSG_SERVERLIST_CHANGED);
|
CommunicationService.MSG_SERVERLIST_CHANGED);
|
||||||
aFilter.addAction(CommunicationService.STATUS_CONNECTION_FAILED);
|
aFilter.addAction(CommunicationService.STATUS_CONNECTION_FAILED);
|
||||||
@@ -223,26 +225,50 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
if (mProgressDialog != null) {
|
if (mProgressDialog != null) {
|
||||||
mProgressDialog.dismiss();
|
mProgressDialog.dismiss();
|
||||||
|
|
||||||
String aFormat = getResources().getString(
|
if (mCommunicationService != null) {
|
||||||
R.string.selector_dialog_connectionfailed);
|
String aFormat = getResources().getString(
|
||||||
String aDialogText = MessageFormat.format(aFormat,
|
R.string.selector_dialog_connectionfailed);
|
||||||
mCommunicationService
|
String aDialogText = MessageFormat.format(aFormat,
|
||||||
.getPairingDeviceName());
|
mCommunicationService.getPairingDeviceName());
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
SelectorActivity.this);
|
SelectorActivity.this);
|
||||||
builder.setMessage(aDialogText)
|
builder.setMessage(aDialogText)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(
|
.setNeutralButton(R.string.help,
|
||||||
R.string.selector_dialog_connectionfailed_ok,
|
new DialogInterface.OnClickListener() {
|
||||||
new DialogInterface.OnClickListener() {
|
public void onClick(
|
||||||
public void onClick(
|
DialogInterface dialog,
|
||||||
DialogInterface dialog,
|
int id) {
|
||||||
int id) {
|
dialog.dismiss();
|
||||||
dialog.dismiss();
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
}
|
SelectorActivity.this);
|
||||||
});
|
builder.setMessage(
|
||||||
builder.show();
|
R.string.ConnectionFailedHelp)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.selector_dialog_connectionfailed_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(
|
||||||
|
DialogInterface dialog,
|
||||||
|
int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.selector_dialog_connectionfailed_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(
|
||||||
|
DialogInterface dialog,
|
||||||
|
int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mBroadcastProcessor.onReceive(aContext, aIntent);
|
mBroadcastProcessor.onReceive(aContext, aIntent);
|
||||||
|
@@ -10,6 +10,7 @@ package org.libreoffice.impressremote;
|
|||||||
|
|
||||||
import org.libreoffice.impressremote.communication.CommunicationService;
|
import org.libreoffice.impressremote.communication.CommunicationService;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -18,6 +19,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -37,6 +39,7 @@ public class StartPresentationActivity extends SherlockActivity {
|
|||||||
bindService(new Intent(this, CommunicationService.class), mConnection,
|
bindService(new Intent(this, CommunicationService.class), mConnection,
|
||||||
Context.BIND_IMPORTANT);
|
Context.BIND_IMPORTANT);
|
||||||
|
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
IntentFilter aFilter = new IntentFilter(
|
IntentFilter aFilter = new IntentFilter(
|
||||||
CommunicationService.MSG_SLIDESHOW_STARTED);
|
CommunicationService.MSG_SLIDESHOW_STARTED);
|
||||||
|
|
||||||
@@ -97,6 +100,18 @@ public class StartPresentationActivity extends SherlockActivity {
|
|||||||
mBroadcastProcessor.onReceive(aContext, aIntent);
|
mBroadcastProcessor.onReceive(aContext, aIntent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(
|
||||||
|
com.actionbarsherlock.view.MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
onBackPressed();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -58,6 +58,27 @@ public class BluetoothClient extends Client {
|
|||||||
|
|
||||||
mSocket.connect();
|
mSocket.connect();
|
||||||
Log.i(Globals.TAG, "BluetoothClient: connected");
|
Log.i(Globals.TAG, "BluetoothClient: connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeConnection() {
|
||||||
|
try {
|
||||||
|
if (mSocket != null)
|
||||||
|
mSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onDisconnect() {
|
||||||
|
if (!mBluetoothWasEnabled) {
|
||||||
|
mAdapter.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validating() throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
mInputStream = mSocket.getInputStream();
|
mInputStream = mSocket.getInputStream();
|
||||||
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
||||||
@@ -80,22 +101,6 @@ public class BluetoothClient extends Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeConnection() {
|
|
||||||
try {
|
|
||||||
if (mSocket != null)
|
|
||||||
mSocket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onDisconnect() {
|
|
||||||
if (!mBluetoothWasEnabled) {
|
|
||||||
mAdapter.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -15,7 +15,11 @@ import java.io.OutputStream;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.libreoffice.impressremote.Globals;
|
||||||
|
import org.libreoffice.impressremote.communication.CommunicationService.State;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic Client for the remote control. To implement a Client for a specific
|
* Generic Client for the remote control. To implement a Client for a specific
|
||||||
@@ -37,6 +41,7 @@ public abstract class Client {
|
|||||||
|
|
||||||
public abstract void closeConnection();
|
public abstract void closeConnection();
|
||||||
|
|
||||||
|
public abstract void validating() throws IOException;
|
||||||
private Receiver mReceiver;
|
private Receiver mReceiver;
|
||||||
|
|
||||||
protected Server mServer;
|
protected Server mServer;
|
||||||
@@ -75,11 +80,11 @@ public abstract class Client {
|
|||||||
aList.add(aTemp);
|
aList.add(aTemp);
|
||||||
}
|
}
|
||||||
if (aTemp == null) {
|
if (aTemp == null) {
|
||||||
mCommunicationService.connectTo(mServer);
|
|
||||||
Intent aIntent = new Intent(
|
Intent aIntent = new Intent(
|
||||||
mCommunicationService
|
mCommunicationService
|
||||||
.getApplicationContext(),
|
.getApplicationContext(),
|
||||||
ReconnectionActivity.class);
|
ReconnectionActivity.class);
|
||||||
|
aIntent.putExtra("server", mServer);
|
||||||
aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
mCommunicationService.getApplicationContext()
|
mCommunicationService.getApplicationContext()
|
||||||
.startActivity(aIntent);
|
.startActivity(aIntent);
|
||||||
|
@@ -102,30 +102,36 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
case NETWORK:
|
case NETWORK:
|
||||||
mClient = new NetworkClient(mServerDesired,
|
mClient = new NetworkClient(mServerDesired,
|
||||||
this, mReceiver);
|
this, mReceiver);
|
||||||
|
mClient.validating();
|
||||||
break;
|
break;
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
mClient = new BluetoothClient(mServerDesired,
|
mClient = new BluetoothClient(mServerDesired,
|
||||||
this, mReceiver,
|
this, mReceiver,
|
||||||
mBluetoothPreviouslyEnabled);
|
mBluetoothPreviouslyEnabled);
|
||||||
|
mClient.validating();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mTransmitter = new Transmitter(mClient);
|
mTransmitter = new Transmitter(mClient);
|
||||||
mState = State.CONNECTED;
|
mState = State.CONNECTED;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.i(Globals.TAG, "CommunicationService.run: " + e);
|
Log.i(Globals.TAG, "CommunicationService.run: " + e);
|
||||||
mClient = null;
|
connextionFailed();
|
||||||
mState = State.DISCONNECTED;
|
|
||||||
Intent aIntent = new Intent(
|
|
||||||
CommunicationService.STATUS_CONNECTION_FAILED);
|
|
||||||
LocalBroadcastManager.getInstance(this)
|
|
||||||
.sendBroadcast(aIntent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.i(Globals.TAG, "CommunicationService.finished work");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void connextionFailed() {
|
||||||
|
mClient = null;
|
||||||
|
mState = State.DISCONNECTED;
|
||||||
|
Intent aIntent = new Intent(
|
||||||
|
CommunicationService.STATUS_CONNECTION_FAILED);
|
||||||
|
LocalBroadcastManager.getInstance(this).sendBroadcast(aIntent);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean mBluetoothPreviouslyEnabled;
|
private boolean mBluetoothPreviouslyEnabled;
|
||||||
|
|
||||||
public void startSearching() {
|
public void startSearching() {
|
||||||
@@ -174,6 +180,7 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
|
Log.d(Globals.TAG, "Service Disconnected");
|
||||||
synchronized (mConnectionVariableMutex) {
|
synchronized (mConnectionVariableMutex) {
|
||||||
mStateDesired = State.DISCONNECTED;
|
mStateDesired = State.DISCONNECTED;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -328,6 +335,10 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
return mClient;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -31,73 +31,38 @@ public class NetworkClient extends Client {
|
|||||||
private static final int PORT = 1599;
|
private static final int PORT = 1599;
|
||||||
|
|
||||||
private Socket mSocket;
|
private Socket mSocket;
|
||||||
|
private Intent mIntent;
|
||||||
|
private String mPin;
|
||||||
|
private Server mServer;
|
||||||
|
|
||||||
public NetworkClient(Server aServer,
|
public NetworkClient(Server aServer,
|
||||||
CommunicationService aCommunicationService,
|
CommunicationService aCommunicationService, Receiver aReceiver)
|
||||||
Receiver aReceiver) throws UnknownHostException,
|
throws UnknownHostException, IOException {
|
||||||
IOException {
|
|
||||||
super(aServer, aCommunicationService, aReceiver);
|
super(aServer, aCommunicationService, aReceiver);
|
||||||
mSocket = new Socket(aServer.getAddress(), PORT);
|
mServer = aServer;
|
||||||
|
mSocket = new Socket(mServer.getAddress(), PORT);
|
||||||
mInputStream = mSocket.getInputStream();
|
mInputStream = mSocket.getInputStream();
|
||||||
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
||||||
CHARSET));
|
CHARSET));
|
||||||
mOutputStream = mSocket.getOutputStream();
|
mOutputStream = mSocket.getOutputStream();
|
||||||
|
|
||||||
// Pairing.
|
// Pairing.
|
||||||
String aPin = setupPin(aServer);
|
mPin = setupPin(mServer);
|
||||||
Intent aIntent = new Intent(CommunicationService.MSG_PAIRING_STARTED);
|
mIntent = new Intent(CommunicationService.MSG_PAIRING_STARTED);
|
||||||
aIntent.putExtra("PIN", aPin);
|
mIntent.putExtra("PIN", mPin);
|
||||||
mPin = aPin;
|
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
||||||
aIntent);
|
mIntent);
|
||||||
// Send out
|
// Send out
|
||||||
String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
|
String aName = CommunicationService.getDeviceName(); // TODO: get the
|
||||||
sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin + "\n\n");
|
// proper name
|
||||||
|
sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + mPin + "\n\n");
|
||||||
// Wait until we get the appropriate string back...
|
|
||||||
String aTemp = mReader.readLine();
|
|
||||||
|
|
||||||
if (aTemp == null) {
|
|
||||||
throw new IOException(
|
|
||||||
"End of stream reached before any data received.");
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
|
|
||||||
if (aTemp.equals("LO_SERVER_VALIDATING_PIN")) {
|
|
||||||
// Broadcast that we need a pin screen.
|
|
||||||
aIntent = new Intent(
|
|
||||||
CommunicationService.STATUS_PAIRING_PINVALIDATION);
|
|
||||||
aIntent.putExtra("PIN", aPin);
|
|
||||||
aIntent.putExtra("SERVERNAME", aServer.getName());
|
|
||||||
mPin = aPin;
|
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService)
|
|
||||||
.sendBroadcast(aIntent);
|
|
||||||
while (mReader.readLine().length() != 0) {
|
|
||||||
// Read off empty lines
|
|
||||||
}
|
|
||||||
aTemp = mReader.readLine();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
aIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
|
||||||
aIntent);
|
|
||||||
|
|
||||||
while (mReader.readLine().length() != 0) {
|
|
||||||
// Get rid of extra lines
|
|
||||||
Log.i(Globals.TAG, "NetworkClient: extra line");
|
|
||||||
}
|
|
||||||
Log.i(Globals.TAG, "NetworkClient: calling startListening");
|
|
||||||
startListening();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String setupPin(Server aServer) {
|
private String setupPin(Server aServer) {
|
||||||
// Get settings
|
// Get settings
|
||||||
SharedPreferences aPreferences = mCommunicationService
|
SharedPreferences aPreferences = mCommunicationService
|
||||||
.getSharedPreferences("sdremote_authorisedremotes",
|
.getSharedPreferences("sdremote_authorisedremotes",
|
||||||
android.content.Context.MODE_PRIVATE);
|
android.content.Context.MODE_PRIVATE);
|
||||||
if (aPreferences.contains(aServer.getName())) {
|
if (aPreferences.contains(aServer.getName())) {
|
||||||
return aPreferences.getString(aServer.getName(), "");
|
return aPreferences.getString(aServer.getName(), "");
|
||||||
} else {
|
} else {
|
||||||
@@ -132,6 +97,46 @@ public class NetworkClient extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validating() throws IOException {
|
||||||
|
|
||||||
|
// Wait until we get the appropriate string back...
|
||||||
|
String aTemp = mReader.readLine();
|
||||||
|
|
||||||
|
if (aTemp == null) {
|
||||||
|
throw new IOException(
|
||||||
|
"End of stream reached before any data received.");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
|
||||||
|
if (aTemp.equals("LO_SERVER_VALIDATING_PIN")) {
|
||||||
|
// Broadcast that we need a pin screen.
|
||||||
|
mIntent = new Intent(
|
||||||
|
CommunicationService.STATUS_PAIRING_PINVALIDATION);
|
||||||
|
mIntent.putExtra("PIN", mPin);
|
||||||
|
mIntent.putExtra("SERVERNAME", mServer.getName());
|
||||||
|
LocalBroadcastManager.getInstance(mCommunicationService)
|
||||||
|
.sendBroadcast(mIntent);
|
||||||
|
while (mReader.readLine().length() != 0) {
|
||||||
|
// Read off empty lines
|
||||||
|
}
|
||||||
|
aTemp = mReader.readLine();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
||||||
|
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
||||||
|
mIntent);
|
||||||
|
|
||||||
|
while (mReader.readLine().length() != 0) {
|
||||||
|
// Get rid of extra lines
|
||||||
|
Log.i(Globals.TAG, "NetworkClient: extra line");
|
||||||
|
}
|
||||||
|
Log.i(Globals.TAG, "NetworkClient: calling startListening");
|
||||||
|
startListening();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -8,18 +8,99 @@
|
|||||||
*/
|
*/
|
||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
|
import org.libreoffice.impressremote.ActivityChangeBroadcastProcessor;
|
||||||
import org.libreoffice.impressremote.R;
|
import org.libreoffice.impressremote.R;
|
||||||
|
import org.libreoffice.impressremote.SelectorActivity;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class ReconnectionActivity extends SherlockActivity {
|
public class ReconnectionActivity extends SherlockActivity {
|
||||||
|
|
||||||
|
private ActivityChangeBroadcastProcessor mBroadcastProcessor;
|
||||||
|
private CommunicationService mCommunicationService;
|
||||||
|
|
||||||
|
// private TextView mCountDownTextView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_reconnect);
|
setContentView(R.layout.activity_reconnect);
|
||||||
|
// mCountDownTextView = (TextView) findViewById(R.id.countDownTV);
|
||||||
|
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
bindService(new Intent(this, CommunicationService.class), mConnection,
|
||||||
|
Context.BIND_IMPORTANT);
|
||||||
|
|
||||||
|
final Server desiredServer = getIntent().getParcelableExtra("server");
|
||||||
|
|
||||||
|
IntentFilter aFilter = new IntentFilter();
|
||||||
|
|
||||||
|
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
||||||
|
mBroadcastProcessor.addToFilter(aFilter);
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(mListener,
|
||||||
|
aFilter);
|
||||||
|
|
||||||
|
getSupportActionBar().setTitle(desiredServer.getName());
|
||||||
|
|
||||||
|
// TODO Connection to desired server
|
||||||
|
// Create a countdown clock for 10 seconds, then double the delay
|
||||||
|
// with every failure. Until it reaches 1min. Like Gmail retry
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private BroadcastReceiver mListener = new BroadcastReceiver() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context aContext, Intent aIntent) {
|
||||||
|
mBroadcastProcessor.onReceive(aContext, aIntent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName aClassName,
|
||||||
|
IBinder aService) {
|
||||||
|
mCommunicationService = ((CommunicationService.CBinder) aService)
|
||||||
|
.getService();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName aClassName) {
|
||||||
|
mCommunicationService = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
Intent aIntent = new Intent(this, SelectorActivity.class);
|
||||||
|
aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(aIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
public class Server {
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class Server implements Parcelable {
|
||||||
|
|
||||||
public enum Protocol {
|
public enum Protocol {
|
||||||
NETWORK, BLUETOOTH
|
NETWORK, BLUETOOTH
|
||||||
@@ -56,6 +59,36 @@ public class Server {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getName() + '@' + Integer.toHexString(hashCode()) + ":{" + mAddress + "," + mName + "}";
|
return getClass().getName() + '@' + Integer.toHexString(hashCode()) + ":{" + mAddress + "," + mName + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
|
out.writeString(mAddress);
|
||||||
|
out.writeString(mName);
|
||||||
|
out.writeString(mProtocol.name());
|
||||||
|
out.writeLong(mTimeDiscovered);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<Server> CREATOR = new Parcelable.Creator<Server>() {
|
||||||
|
public Server createFromParcel(Parcel in) {
|
||||||
|
return new Server(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server[] newArray(int size) {
|
||||||
|
return new Server[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private Server(Parcel in) {
|
||||||
|
mAddress = in.readString();
|
||||||
|
mName = in.readString();
|
||||||
|
mProtocol = Protocol.valueOf(in.readString());
|
||||||
|
mTimeDiscovered = in.readLong();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user