summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej.hunt@collabora.com>2013-12-10 19:52:33 +0000
committerAndrzej Hunt <andrzej.hunt@collabora.com>2013-12-10 20:03:12 +0000
commit3cc31f89787e435c893b38a0adc0a23f566ab60f (patch)
tree3ae096ae825c9d02bc86b463fdbc49cbb91cf11a /android
parenta5ad6e750b58d07d9edbcc3ee31735bdcb05e4b5 (diff)
fdo#60486 Fix auto-enabling bluetooth and improve bluetooth handling.
We should only enable bluetooth with explicit approval of the user, see: http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#enable%28%29 We now also display an appropriate message if bluetooth is disabled. Change-Id: Ic3a07c9ad0806a60ac7c7e609a30add7af18916f
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/res/values/strings.xml1
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java14
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java12
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java22
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java10
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/util/Intents.java5
6 files changed, 50 insertions, 14 deletions
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 4ec816af049b..7dc068a5c968 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -90,5 +90,6 @@
<string name="requirements_network_connection">The Android device and a computer connected to the same network.</string>
<string name="requirements_network_ports">If you have a firewall make sure ports 1598 and 1599 are opened.</string>
<string name="requirements_bluetooth_connection">A computer with enabled Bluetooth.</string>
+ <string name="message_bluetooth_disabled">Please enable bluetooth to connect to a bluetooth enabled computer.</string>
</resources>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 043965aa5e32..7d1336ca2b9d 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -31,6 +31,8 @@ import org.libreoffice.impressremote.util.SavedStates;
public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
private boolean mBluetoothWasEnabled;
+ private final static int REQUEST_ENABLE_BT = 1;
+
@Override
protected void onCreate(Bundle aSavedInstanceState) {
super.onCreate(aSavedInstanceState);
@@ -42,6 +44,16 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
setUpContent();
}
+ @Override
+ protected void onActivityResult(int arg0, int arg1, Intent arg2) {
+ super.onActivityResult(arg0, arg1, arg2);
+
+ if (arg0 == REQUEST_ENABLE_BT) {
+ // Ideally we should do all detection based on listening to the bluetooth state
+ // as the user can still enable BT separately (see BluetoothServersFinder.java:onReceive)
+ }
+ }
+
private void saveBluetoothState(Bundle aSavedInstanceState) {
// In more ideal world this work should be done at the service.
// Unfortunately service cannot save or restore its state.
@@ -64,7 +76,7 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
}
private void enableBluetooth() {
- BluetoothOperator.enable();
+ BluetoothOperator.enable(this, REQUEST_ENABLE_BT);
}
private void setUpTitle() {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
index 29e9b9c1a051..e696a1ba14ef 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
@@ -72,9 +72,19 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
public void onReceive(Context aContext, Intent aIntent) {
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(aIntent.getAction())) {
switch (aIntent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) {
- case BluetoothAdapter.STATE_ON:
+ case BluetoothAdapter.STATE_ON: {
BluetoothOperator.getAdapter().startDiscovery();
+ Intent aNewIntent = Intents.buildBluetoothStateChangedIntent();
+ LocalBroadcastManager.getInstance(mContext).sendBroadcast(aNewIntent);
return;
+ }
+
+ case BluetoothAdapter.STATE_OFF: {
+ mServers.clear();
+ Intent aNewIntent = Intents.buildBluetoothStateChangedIntent();
+ LocalBroadcastManager.getInstance(mContext).sendBroadcast(aNewIntent);
+ return;
+ }
default:
return;
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index ea8c702f8028..3e5908dac92e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -55,6 +56,8 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
WIFI, BLUETOOTH
}
+ boolean mBluetoothDisabled = false;
+
private CommunicationService mCommunicationService;
private BroadcastReceiver mIntentsReceiver;
@@ -148,7 +151,10 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
return getString(R.string.message_search_wifi);
case BLUETOOTH:
- return getString(R.string.message_search_bluetooth);
+ if (mBluetoothDisabled != true)
+ return getString(R.string.message_search_bluetooth);
+ else
+ return getString(R.string.message_bluetooth_disabled);
default:
return "";
@@ -210,6 +216,8 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
}
}
+ mBluetoothDisabled = !BluetoothAdapter.getDefaultAdapter().isEnabled();
+
return aComputers;
}
@@ -251,18 +259,10 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
return;
}
- if (!isShowingProgressMessageRequired()) {
- return;
- }
-
showProgressMessage();
showLearnMoreMessage();
}
- private boolean isShowingProgressMessageRequired() {
- return getProgressMessageView().getVisibility() == View.INVISIBLE;
- }
-
private void tearDownComputersAdapter() {
setListAdapter(null);
}
@@ -330,6 +330,8 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
public void onReceive(Context aContext, Intent aIntent) {
if (Intents.Actions.SERVERS_LIST_CHANGED.equals(aIntent.getAction())) {
mComputersFragment.loadComputers();
+ } else if (Intents.Actions.BLUETOOTH_STATE_CHANGED.equals(aIntent.getAction())) {
+ mComputersFragment.loadComputers();
}
}
}
@@ -337,7 +339,7 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
private IntentFilter buildIntentsReceiverFilter() {
IntentFilter aIntentFilter = new IntentFilter();
aIntentFilter.addAction(Intents.Actions.SERVERS_LIST_CHANGED);
-
+ aIntentFilter.addAction(Intents.Actions.BLUETOOTH_STATE_CHANGED);
return aIntentFilter;
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
index 95228388d501..c451518160ac 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
@@ -8,7 +8,9 @@
*/
package org.libreoffice.impressremote.util;
+import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
+import android.content.Intent;
public final class BluetoothOperator {
private BluetoothOperator() {
@@ -26,12 +28,16 @@ public final class BluetoothOperator {
return BluetoothAdapter.getDefaultAdapter();
}
- public static void enable() {
+ public static void enable(Activity aActivity, int nRequestCode) {
if (!isAvailable()) {
return;
}
- getAdapter().enable();
+ if (getAdapter() != null) {
+ Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ aActivity.startActivityForResult(enableBtIntent, nRequestCode);
+ }
+
}
public static void disable() {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index beab7ae03460..e27f2f1ee75b 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -29,6 +29,7 @@ public final class Intents {
}
public static final String SERVERS_LIST_CHANGED = "SERVERS_LIST_CHANGED";
+ public static final String BLUETOOTH_STATE_CHANGED = "BLUETOOTH_STATE_CHANGED";
public static final String PAIRING_SUCCESSFUL = "PAIRING_SUCCESSFUL";
public static final String PAIRING_VALIDATION = "PAIRING_VALIDATION";
@@ -74,6 +75,10 @@ public final class Intents {
return new Intent(Actions.SERVERS_LIST_CHANGED);
}
+ public static Intent buildBluetoothStateChangedIntent() {
+ return new Intent(Actions.BLUETOOTH_STATE_CHANGED);
+ }
+
public static Intent buildPairingSuccessfulIntent() {
return new Intent(Actions.PAIRING_SUCCESSFUL);
}