1 package org.robolectric.shadows; 2 3 import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; 4 5 import android.annotation.SuppressLint; 6 import android.bluetooth.BluetoothServerSocket; 7 import android.bluetooth.BluetoothSocket; 8 import android.os.Build; 9 import android.os.ParcelUuid; 10 import org.robolectric.annotation.Implements; 11 import org.robolectric.shadow.api.Shadow; 12 13 @Implements(value = BluetoothServerSocket.class) 14 public class ShadowBluetoothServerSocket { 15 16 @SuppressLint("PrivateApi") 17 @SuppressWarnings("unchecked") newInstance( int type, boolean auth, boolean encrypt, ParcelUuid uuid)18 public static BluetoothServerSocket newInstance( 19 int type, boolean auth, boolean encrypt, ParcelUuid uuid) { 20 if (Build.VERSION.SDK_INT >= JELLY_BEAN_MR1) { 21 return Shadow.newInstance( 22 BluetoothServerSocket.class, 23 new Class<?>[] {Integer.TYPE, Boolean.TYPE, Boolean.TYPE, ParcelUuid.class}, 24 new Object[] {type, auth, encrypt, uuid}); 25 } else { 26 return Shadow.newInstance( 27 BluetoothServerSocket.class, 28 new Class<?>[] {Integer.TYPE, Boolean.TYPE, Boolean.TYPE, Integer.TYPE}, 29 new Object[] {type, auth, encrypt, getPort(uuid)}); 30 } 31 } 32 33 // Port ranges are valid from 1 to MAX_RFCOMM_CHANNEL. getPort(ParcelUuid uuid)34 private static int getPort(ParcelUuid uuid) { 35 return Math.abs(uuid.hashCode() % BluetoothSocket.MAX_RFCOMM_CHANNEL) + 1; 36 } 37 } 38