diff --git a/briar-android/AndroidManifest.xml b/briar-android/AndroidManifest.xml
index 4393823e9..0ce2865ec 100644
--- a/briar-android/AndroidManifest.xml
+++ b/briar-android/AndroidManifest.xml
@@ -7,8 +7,7 @@
android:versionName="0.12">
diff --git a/briar-android/build.gradle b/briar-android/build.gradle
index 940f8cea5..e56648b98 100644
--- a/briar-android/build.gradle
+++ b/briar-android/build.gradle
@@ -19,13 +19,9 @@ dependencies {
compile("com.android.support:appcompat-v7:$supportVersion") {
exclude module: 'support-v4'
}
- compile("com.android.support:preference-v7:$supportVersion") {
- exclude module: 'support-v4'
- }
+
compile("com.android.support:preference-v14:$supportVersion") {
exclude module: 'support-v4'
- exclude module: 'preference-v7'
- exclude module: 'recyclerview-v7'
}
compile("com.android.support:design:$supportVersion") {
exclude module: 'support-v4'
@@ -64,7 +60,6 @@ dependencyVerification {
'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259',
'com.android.support:support-v4:81ce890f26d35c75ad17d0f998a7e3230330c3b41e0b629566bc744bee89e448',
'com.android.support:appcompat-v7:00f9d93acacd6731f309724054bf51492814b4b2869f16d7d5c0038dcb8c9a0d',
- 'com.android.support:preference-v7:775101bd07bd052e455761c5c5d9523d7ad59f2f320e3e8cbde241fd6b1d6025',
'com.android.support:preference-v14:44881bb46094e86d0bc2426f205419674a5b4eb514b44b5a4659b5de29f71eb7',
'com.android.support:design:003e0c0bea0a6891f8b2bc43f20ae7af2a49a17363e5bb10df5ee0bae12fa686',
'com.android.support:support-annotations:786ab0d060774fb95cfdaf4878771e14b85733b1af9d72a4aae762dc7c1dff9f',
diff --git a/briar-android/res/values-v14/styles.xml b/briar-android/res/values-v14/styles.xml
deleted file mode 100644
index cd46b12fb..000000000
--- a/briar-android/res/values-v14/styles.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/briar-android/res/values/styles.xml b/briar-android/res/values/styles.xml
index 729554b99..98751d04c 100644
--- a/briar-android/res/values/styles.xml
+++ b/briar-android/res/values/styles.xml
@@ -22,6 +22,10 @@
- 1dp
+
+
-
-
diff --git a/briar-android/src/im/delight/android/identicons/IdenticonView.java b/briar-android/src/im/delight/android/identicons/IdenticonView.java
index f5e44bdc4..41f14c555 100644
--- a/briar-android/src/im/delight/android/identicons/IdenticonView.java
+++ b/briar-android/src/im/delight/android/identicons/IdenticonView.java
@@ -16,10 +16,8 @@ package im.delight.android.identicons;
* limitations under the License.
*/
-import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
-import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@@ -41,12 +39,9 @@ abstract public class IdenticonView extends View {
init();
}
- @SuppressLint("NewApi")
protected void init() {
setWillNotDraw(false);
- if (Build.VERSION.SDK_INT >= 11) {
- setLayerType(View.LAYER_TYPE_SOFTWARE, null);
- }
+ setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
public void show(byte[] input) {
diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java
index 24cc0dd97..cffc9727e 100644
--- a/briar-android/src/org/briarproject/android/BriarActivity.java
+++ b/briar-android/src/org/briarproject/android/BriarActivity.java
@@ -76,9 +76,8 @@ public abstract class BriarActivity extends BaseActivity {
Intent i = new Intent(this, ExitActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK
| FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | FLAG_ACTIVITY_NO_ANIMATION);
- if (Build.VERSION.SDK_INT >= 11)
- i.addFlags(FLAG_ACTIVITY_CLEAR_TASK);
+ | FLAG_ACTIVITY_NO_ANIMATION
+ | FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
diff --git a/briar-android/src/org/briarproject/android/forum/ForumActivity.java b/briar-android/src/org/briarproject/android/forum/ForumActivity.java
index a87764b1d..5f141948f 100644
--- a/briar-android/src/org/briarproject/android/forum/ForumActivity.java
+++ b/briar-android/src/org/briarproject/android/forum/ForumActivity.java
@@ -3,11 +3,9 @@ package org.briarproject.android.forum;
import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
-import android.annotation.TargetApi;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
-import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
@@ -519,14 +517,12 @@ public class ForumActivity extends BriarActivity implements
List indexList =
getSubTreeIndexes(visiblePos, forumEntry.getLevel());
if (!indexList.isEmpty()) {
- if (Build.VERSION.SDK_INT >= 11) {
- // stop animating children
- for (int index : indexList) {
- ValueAnimator anim =
- animatingEntries.get(forumEntries.get(index));
- if (anim != null && anim.isRunning()) {
- anim.cancel();
- }
+ // stop animating children
+ for (int index : indexList) {
+ ValueAnimator anim =
+ animatingEntries.get(forumEntries.get(index));
+ if (anim != null && anim.isRunning()) {
+ anim.cancel();
}
}
if (indexList.size() == 1) {
@@ -560,7 +556,6 @@ public class ForumActivity extends BriarActivity implements
return null;
}
- @TargetApi(11)
private void animateFadeOut(final ForumViewHolder ui,
final ForumEntry addedEntry) {
ui.setIsRecyclable(false);
@@ -686,9 +681,7 @@ public class ForumActivity extends BriarActivity implements
ui.cell.setBackgroundColor(ContextCompat
.getColor(ForumActivity.this,
R.color.forum_cell_highlight));
- if (Build.VERSION.SDK_INT >= 11) {
- animateFadeOut(ui, addedEntry);
- }
+ animateFadeOut(ui, addedEntry);
addedEntry = null;
} else {
ui.cell.setBackgroundColor(ContextCompat
diff --git a/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java b/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java
index cdb20408b..a0629d5d2 100644
--- a/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java
+++ b/briar-android/src/org/briarproject/android/introduction/ContactChooserAdapter.java
@@ -1,11 +1,6 @@
package org.briarproject.android.introduction;
import android.content.Context;
-import android.graphics.Color;
-import android.graphics.ColorFilter;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.os.Build;
import android.view.View;
import org.briarproject.android.contact.ContactListAdapter;
@@ -47,6 +42,7 @@ public class ContactChooserAdapter extends ContactListAdapter {
* Set the identity from whose perspective the contact shall be chosen.
* Contacts that belong to a different author will be shown grayed out,
* but are still clickable.
+ *
* @param authorId The ID of the local Author
*/
public void setLocalAuthor(AuthorId authorId) {
@@ -55,21 +51,12 @@ public class ContactChooserAdapter extends ContactListAdapter {
}
private void grayOutItem(final ContactHolder ui) {
- if (Build.VERSION.SDK_INT >= 11) {
- float alpha = 0.25f;
- ui.bulb.setAlpha(alpha);
- ui.avatar.setAlpha(alpha);
- ui.name.setAlpha(alpha);
- ui.date.setAlpha(alpha);
- ui.identity.setAlpha(alpha);
- } else {
- ColorFilter colorFilter = new PorterDuffColorFilter(Color.GRAY,
- PorterDuff.Mode.MULTIPLY);
- ui.bulb.setColorFilter(colorFilter);
- ui.avatar.setColorFilter(colorFilter);
- ui.name.setEnabled(false);
- ui.date.setEnabled(false);
- }
+ float alpha = 0.25f;
+ ui.bulb.setAlpha(alpha);
+ ui.avatar.setAlpha(alpha);
+ ui.name.setAlpha(alpha);
+ ui.date.setAlpha(alpha);
+ ui.identity.setAlpha(alpha);
}
}
diff --git a/briar-android/src/org/briarproject/android/report/DevReportActivity.java b/briar-android/src/org/briarproject/android/report/DevReportActivity.java
index e7077e514..c029ffa66 100644
--- a/briar-android/src/org/briarproject/android/report/DevReportActivity.java
+++ b/briar-android/src/org/briarproject/android/report/DevReportActivity.java
@@ -4,7 +4,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.AsyncTask;
-import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
@@ -101,11 +100,9 @@ public class DevReportActivity extends BaseCrashReportDialog
SharedPreferences prefs = sharedPreferencesFactory.create();
excludedFields = new HashSet<>();
- if (Build.VERSION.SDK_INT >= 11) {
- for (String name : prefs.getStringSet(PREF_EXCLUDED_FIELDS,
- new HashSet())) {
- excludedFields.add(ReportField.valueOf(name));
- }
+ for (String name : prefs.getStringSet(PREF_EXCLUDED_FIELDS,
+ new HashSet())) {
+ excludedFields.add(ReportField.valueOf(name));
}
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
@@ -367,16 +364,14 @@ public class DevReportActivity extends BaseCrashReportDialog
protected void onPostExecute(Boolean success) {
final SharedPreferences prefs =
sharedPreferencesFactory.create();
- if (Build.VERSION.SDK_INT >= 11) {
- final SharedPreferences.Editor prefEditor =
- prefs.edit();
- Set fields = new HashSet<>();
- for (ReportField field : excludedFields) {
- fields.add(field.name());
- }
- prefEditor.putStringSet(PREF_EXCLUDED_FIELDS, fields);
- prefEditor.apply();
+ final SharedPreferences.Editor prefEditor =
+ prefs.edit();
+ Set fields = new HashSet<>();
+ for (ReportField field : excludedFields) {
+ fields.add(field.name());
}
+ prefEditor.putStringSet(PREF_EXCLUDED_FIELDS, fields);
+ prefEditor.apply();
if (success) {
// Retrieve user's comment and email address, if any
diff --git a/briar-android/src/org/briarproject/android/sharing/ContactSelectorAdapter.java b/briar-android/src/org/briarproject/android/sharing/ContactSelectorAdapter.java
index d940c48dc..422022baa 100644
--- a/briar-android/src/org/briarproject/android/sharing/ContactSelectorAdapter.java
+++ b/briar-android/src/org/briarproject/android/sharing/ContactSelectorAdapter.java
@@ -1,12 +1,6 @@
package org.briarproject.android.sharing;
import android.content.Context;
-import android.graphics.Color;
-import android.graphics.ColorFilter;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.os.Build;
-import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -27,25 +21,10 @@ import static android.view.View.VISIBLE;
class ContactSelectorAdapter
extends BaseContactListAdapter {
- private final ColorFilter grayColorFilter;
-
ContactSelectorAdapter(Context context,
OnItemClickListener listener) {
super(context, listener);
- if (Build.VERSION.SDK_INT >= 11) {
- grayColorFilter = null;
- } else {
- // Overlay the background colour at 75% opacity
- int bg = ContextCompat.getColor(context, R.color.window_background);
- int alpha = (int) (255 * 0.75f);
- int red = Color.red(bg);
- int green = Color.green(bg);
- int blue = Color.blue(bg);
- bg = Color.argb(alpha, red, green, blue);
- grayColorFilter = new PorterDuffColorFilter(bg,
- PorterDuff.Mode.SRC_OVER);
- }
}
@Override
@@ -114,14 +93,9 @@ class ContactSelectorAdapter
}
private void grayOutItem(SelectableContactHolder ui, boolean gray) {
- if (Build.VERSION.SDK_INT >= 11) {
- float alpha = gray ? 0.25f : 1f;
- ui.avatar.setAlpha(alpha);
- ui.name.setAlpha(alpha);
- ui.checkBox.setAlpha(alpha);
- } else {
- if (gray) ui.avatar.setColorFilter(grayColorFilter);
- else ui.avatar.clearColorFilter();
- }
+ float alpha = gray ? 0.25f : 1f;
+ ui.avatar.setAlpha(alpha);
+ ui.name.setAlpha(alpha);
+ ui.checkBox.setAlpha(alpha);
}
}
diff --git a/briar-android/src/org/briarproject/android/util/BriarRecyclerView.java b/briar-android/src/org/briarproject/android/util/BriarRecyclerView.java
index 70ba252cc..affbe9e13 100644
--- a/briar-android/src/org/briarproject/android/util/BriarRecyclerView.java
+++ b/briar-android/src/org/briarproject/android/util/BriarRecyclerView.java
@@ -1,9 +1,7 @@
package org.briarproject.android.util;
-import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
-import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.util.AttributeSet;
@@ -71,7 +69,7 @@ public class BriarRecyclerView extends FrameLayout {
showProgressBar();
// scroll down when opening keyboard
- if (isScrollingToEnd && Build.VERSION.SDK_INT >= 11) {
+ if (isScrollingToEnd) {
addLayoutChangeListener();
}
@@ -90,7 +88,6 @@ public class BriarRecyclerView extends FrameLayout {
};
}
- @TargetApi(11)
private void addLayoutChangeListener() {
recyclerView.addOnLayoutChangeListener(
new OnLayoutChangeListener() {
diff --git a/briar-android/src/org/briarproject/android/util/CameraView.java b/briar-android/src/org/briarproject/android/util/CameraView.java
index 9d5295b23..79ea7eadd 100644
--- a/briar-android/src/org/briarproject/android/util/CameraView.java
+++ b/briar-android/src/org/briarproject/android/util/CameraView.java
@@ -25,7 +25,6 @@ import static android.hardware.Camera.Parameters.FOCUS_MODE_EDOF;
import static android.hardware.Camera.Parameters.FOCUS_MODE_FIXED;
import static android.hardware.Camera.Parameters.FOCUS_MODE_MACRO;
import static android.hardware.Camera.Parameters.SCENE_MODE_BARCODE;
-import static android.view.SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -59,8 +58,6 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
super.onAttachedToWindow();
setKeepScreenOn(true);
SurfaceHolder holder = getHolder();
- if (Build.VERSION.SDK_INT < 11)
- holder.setType(SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(this);
}
@@ -164,8 +161,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
LOG.info("Setting scene mode to barcode");
params.setSceneMode(SCENE_MODE_BARCODE);
}
- if (Build.VERSION.SDK_INT >= 14 &&
- focusModes.contains(FOCUS_MODE_CONTINUOUS_PICTURE)) {
+ if (focusModes.contains(FOCUS_MODE_CONTINUOUS_PICTURE)) {
LOG.info("Setting focus mode to continuous picture");
params.setFocusMode(FOCUS_MODE_CONTINUOUS_PICTURE);
} else if (focusModes.contains(FOCUS_MODE_CONTINUOUS_VIDEO)) {
@@ -212,12 +208,6 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
+ ", stretch " + stretch + ", pixels " + pixels
+ ", score " + score);
}
- // Large preview sizes can crash older devices
- int maxDimension = Math.max(width, height);
- if (Build.VERSION.SDK_INT < 14 && maxDimension > screenMax) {
- LOG.info("Too large for screen");
- continue;
- }
if (bestSize == null || score > bestScore) {
bestSize = size;
bestScore = score;
diff --git a/briar-android/src/org/briarproject/android/util/CustomAnimations.java b/briar-android/src/org/briarproject/android/util/CustomAnimations.java
index 07dec1324..50615f213 100644
--- a/briar-android/src/org/briarproject/android/util/CustomAnimations.java
+++ b/briar-android/src/org/briarproject/android/util/CustomAnimations.java
@@ -2,8 +2,6 @@ package org.briarproject.android.util;
import android.animation.Animator;
import android.animation.ValueAnimator;
-import android.annotation.SuppressLint;
-import android.os.Build;
import android.view.ViewGroup;
import static android.view.View.GONE;
@@ -12,25 +10,7 @@ import static android.view.View.VISIBLE;
public class CustomAnimations {
- public static void animateHeight(ViewGroup viewGroup, boolean isExtending,
- int duration) {
- if (Build.VERSION.SDK_INT >= 11) {
- animateHeightPostGingerbread(viewGroup, isExtending, duration);
- } else {
- animateHeightGingerbread(viewGroup, isExtending);
- }
- }
-
- private static void animateHeightGingerbread(ViewGroup viewGroup,
- boolean isExtending) {
- // No animations for Gingerbread
- if (isExtending) viewGroup.setVisibility(VISIBLE);
- else viewGroup.setVisibility(GONE);
- }
-
-
- @SuppressLint("NewApi")
- private static void animateHeightPostGingerbread(final ViewGroup viewGroup,
+ public static void animateHeight(final ViewGroup viewGroup,
final boolean isExtending, int duration) {
ValueAnimator anim;
if (isExtending) {
@@ -74,4 +54,5 @@ public class CustomAnimations {
anim.setDuration(duration);
anim.start();
}
+
}
diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
index 8c26d4518..33f35f49d 100644
--- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
+++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
@@ -182,7 +182,8 @@ class DroidtoothPlugin implements DuplexPlugin {
// Bind a server socket to accept connections from contacts
BluetoothServerSocket ss;
try {
- ss = InsecureBluetooth.listen(adapter, "RFCOMM", getUuid());
+ ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
+ "RFCOMM", getUuid());
} catch (IOException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
@@ -321,7 +322,7 @@ class DroidtoothPlugin implements DuplexPlugin {
BluetoothDevice d = adapter.getRemoteDevice(address);
BluetoothSocket s = null;
try {
- s = InsecureBluetooth.createSocket(d, u);
+ s = d.createInsecureRfcommSocketToServiceRecord(u);
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
s.connect();
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
@@ -372,7 +373,8 @@ class DroidtoothPlugin implements DuplexPlugin {
// Bind a server socket for receiving invitation connections
BluetoothServerSocket ss;
try {
- ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid);
+ ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
+ "RFCOMM", getUuid());
} catch (IOException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return null;
@@ -453,7 +455,8 @@ class DroidtoothPlugin implements DuplexPlugin {
// Bind a server socket for receiving invitation connections
BluetoothServerSocket ss;
try {
- ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid);
+ ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
+ "RFCOMM", getUuid());
} catch (IOException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return null;
diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java b/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java
deleted file mode 100644
index 4d6e1117d..000000000
--- a/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package org.briarproject.plugins.droidtooth;
-
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.UUID;
-import java.util.logging.Logger;
-
-import android.annotation.SuppressLint;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothServerSocket;
-import android.bluetooth.BluetoothSocket;
-import android.os.Binder;
-import android.os.Build;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.ParcelUuid;
-
-// Based on http://stanford.edu/~tpurtell/InsecureBluetooth.java by T.J. Purtell
-class InsecureBluetooth {
-
- private static final Logger LOG =
- Logger.getLogger(InsecureBluetooth.class.getName());
-
- private static final int TYPE_RFCOMM = 1;
-
- @SuppressLint("NewApi")
- static BluetoothServerSocket listen(BluetoothAdapter adapter, String name,
- UUID uuid) throws IOException {
- if (Build.VERSION.SDK_INT >= 10) {
- LOG.info("Listening with new API");
- return adapter.listenUsingInsecureRfcommWithServiceRecord(name,
- uuid);
- }
- try {
- LOG.info("Listening via reflection");
- // Find an available channel
- String className = BluetoothAdapter.class.getCanonicalName()
- + ".RfcommChannelPicker";
- Class> channelPickerClass = null;
- Class>[] children = BluetoothAdapter.class.getDeclaredClasses();
- for (Class> c : children) {
- if (c.getCanonicalName().equals(className)) {
- channelPickerClass = c;
- break;
- }
- }
- if (channelPickerClass == null)
- throw new IOException("Can't find channel picker class");
- Constructor> constructor =
- channelPickerClass.getDeclaredConstructor(UUID.class);
- constructor.setAccessible(true);
- Object channelPicker = constructor.newInstance(uuid);
- Method nextChannel =
- channelPickerClass.getDeclaredMethod("nextChannel");
- nextChannel.setAccessible(true);
- int channel = (Integer) nextChannel.invoke(channelPicker);
- if (channel == -1) throw new IOException("No available channels");
- // Listen on the channel
- BluetoothServerSocket socket = listen(channel);
- // Add a service record
- Field f = BluetoothAdapter.class.getDeclaredField("mService");
- f.setAccessible(true);
- Object mService = f.get(adapter);
- Method addRfcommServiceRecord =
- mService.getClass().getDeclaredMethod(
- "addRfcommServiceRecord", String.class,
- ParcelUuid.class, int.class, IBinder.class);
- addRfcommServiceRecord.setAccessible(true);
- int handle = (Integer) addRfcommServiceRecord.invoke(mService, name,
- new ParcelUuid(uuid), channel, new Binder());
- if (handle == -1) {
- socket.close();
- throw new IOException("Can't register SDP record for " + name);
- }
- Field f1 = BluetoothAdapter.class.getDeclaredField("mHandler");
- f1.setAccessible(true);
- Object mHandler = f1.get(adapter);
- Method setCloseHandler = socket.getClass().getDeclaredMethod(
- "setCloseHandler", Handler.class, int.class);
- setCloseHandler.setAccessible(true);
- setCloseHandler.invoke(socket, mHandler, handle);
- return socket;
- } catch (NoSuchMethodException e) {
- throw new IOException(e);
- } catch (NoSuchFieldException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- } catch (InstantiationException e) {
- throw new IOException(e);
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof IOException) {
- throw (IOException) e.getCause();
- } else {
- throw new IOException(e);
- }
- }
- }
-
- private static BluetoothServerSocket listen(int port) throws IOException {
- try {
- Constructor constructor =
- BluetoothServerSocket.class.getDeclaredConstructor(
- int.class, boolean.class, boolean.class, int.class);
- constructor.setAccessible(true);
- BluetoothServerSocket socket = constructor.newInstance(TYPE_RFCOMM,
- false, false, port);
- Field f = BluetoothServerSocket.class.getDeclaredField("mSocket");
- f.setAccessible(true);
- Object mSocket = f.get(socket);
- Method bindListen =
- mSocket.getClass().getDeclaredMethod("bindListen");
- bindListen.setAccessible(true);
- int errno = (Integer) bindListen.invoke(mSocket);
- if (errno != 0) {
- socket.close();
- throw new IOException("Can't bind: errno " + errno);
- }
- return socket;
- } catch (NoSuchMethodException e) {
- throw new IOException(e);
- } catch (NoSuchFieldException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- } catch (InstantiationException e) {
- throw new IOException(e);
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof IOException) {
- throw (IOException) e.getCause();
- } else {
- throw new IOException(e);
- }
- }
- }
-
- @SuppressLint("NewApi")
- static BluetoothSocket createSocket(BluetoothDevice device, UUID uuid)
- throws IOException {
- if (Build.VERSION.SDK_INT >= 10) {
- LOG.info("Creating socket with new API");
- return device.createInsecureRfcommSocketToServiceRecord(uuid);
- }
- try {
- LOG.info("Creating socket via reflection");
- Constructor constructor =
- BluetoothSocket.class.getDeclaredConstructor(int.class,
- int.class, boolean.class, boolean.class,
- BluetoothDevice.class, int.class, ParcelUuid.class);
- constructor.setAccessible(true);
- return constructor.newInstance(TYPE_RFCOMM, -1, false, true, device,
- -1, new ParcelUuid(uuid));
- } catch (NoSuchMethodException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- } catch (InstantiationException e) {
- throw new IOException(e);
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof IOException) {
- throw (IOException) e.getCause();
- } else {
- throw new IOException(e);
- }
- }
- }
-}