@@ -68,7 +68,7 @@ public class SdlDeviceListener {
6868 private boolean isRunning = false ;
6969
7070
71- public SdlDeviceListener (Context context , BluetoothDevice device , Callback callback ){
71+ public SdlDeviceListener (Context context , BluetoothDevice device , Callback callback ) {
7272 this .contextWeakReference = new WeakReference <>(context );
7373 this .connectedDevice = device ;
7474 this .callback = callback ;
@@ -83,8 +83,8 @@ public SdlDeviceListener(Context context, BluetoothDevice device, Callback callb
8383 * listens for a finite amount of time. If this is the first time the device has been seen, this
8484 * will listen for 30 seconds, if it is not, this will listen for 15 seconds instead.
8585 */
86- public void start (){
87- if (hasSDLConnected (contextWeakReference .get (), connectedDevice .getAddress ())){
86+ public void start () {
87+ if (hasSDLConnected (contextWeakReference .get (), connectedDevice .getAddress ())) {
8888 DebugTool .logInfo (TAG + ": Confirmed SDL device, should start router service" );
8989 //This device has connected to SDL previously, it is ok to start the RS right now
9090 callback .onTransportConnected (contextWeakReference .get (), connectedDevice );
@@ -118,10 +118,11 @@ public void run() {
118118
119119 /**
120120 * Check to see if this instance is in the middle of running or not
121+ *
121122 * @return if this is already in the process of running
122123 */
123- public boolean isRunning (){
124- synchronized (RUNNING_LOCK ){
124+ public boolean isRunning () {
125+ synchronized (RUNNING_LOCK ) {
125126 return isRunning ;
126127 }
127128 }
@@ -130,13 +131,13 @@ private static class TransportHandler extends Handler {
130131
131132 final WeakReference <SdlDeviceListener > provider ;
132133
133- TransportHandler (SdlDeviceListener provider ){
134+ TransportHandler (SdlDeviceListener provider ) {
134135 this .provider = new WeakReference <>(provider );
135136 }
136137
137138 @ Override
138139 public void handleMessage (@ NonNull Message msg ) {
139- if (this .provider .get () == null ){
140+ if (this .provider .get () == null ) {
140141 return ;
141142 }
142143 SdlDeviceListener sdlListener = this .provider .get ();
@@ -145,9 +146,9 @@ public void handleMessage(@NonNull Message msg) {
145146 case SdlRouterService .MESSAGE_STATE_CHANGE :
146147 switch (msg .arg1 ) {
147148 case MultiplexBaseTransport .STATE_CONNECTED :
148- sdlListener .setSDLConnectedStatus (sdlListener .contextWeakReference .get (), sdlListener .connectedDevice .getAddress (),true );
149+ sdlListener .setSDLConnectedStatus (sdlListener .contextWeakReference .get (), sdlListener .connectedDevice .getAddress (), true );
149150 boolean keepConnectionOpen = sdlListener .callback .onTransportConnected (sdlListener .contextWeakReference .get (), sdlListener .connectedDevice );
150- if ( !keepConnectionOpen ) {
151+ if ( !keepConnectionOpen ) {
151152 sdlListener .bluetoothTransport .stop ();
152153 sdlListener .bluetoothTransport = null ;
153154 sdlListener .timeoutHandler .removeCallbacks (sdlListener .timeoutRunner );
@@ -172,15 +173,16 @@ public void handleMessage(@NonNull Message msg) {
172173
173174 /**
174175 * Set the connection establishment status of the particular device
175- * @param address address of the device in quesiton
176+ *
177+ * @param address address of the device in quesiton
176178 * @param hasSDLConnected true if a connection has been established, false if not
177179 */
178- public static void setSDLConnectedStatus (Context context , String address , boolean hasSDLConnected ){
180+ public static void setSDLConnectedStatus (Context context , String address , boolean hasSDLConnected ) {
179181 synchronized (LOCK ) {
180182 if (context != null ) {
181- DebugTool .logInfo ( TAG + ": Saving connected status - " + address + " : " + hasSDLConnected );
183+ DebugTool .logInfo (TAG + ": Saving connected status - " + address + " : " + hasSDLConnected );
182184 SharedPreferences preferences = context .getSharedPreferences (SDL_DEVICE_STATUS_SHARED_PREFS , Context .MODE_PRIVATE );
183- if (preferences .contains (address ) && hasSDLConnected == preferences .getBoolean (address , false )) {
185+ if (preferences .contains (address ) && hasSDLConnected == preferences .getBoolean (address , false )) {
184186 //The same key/value exists in our shared preferences. No reason to write again.
185187 return ;
186188 }
@@ -193,10 +195,11 @@ public static void setSDLConnectedStatus(Context context, String address, boolea
193195
194196 /**
195197 * Checks to see if a device address has connected to SDL before.
198+ *
196199 * @param address the mac address of the device in quesiton
197200 * @return if this is the first status check of this device
198201 */
199- private boolean isFirstStatusCheck (String address ){
202+ private boolean isFirstStatusCheck (String address ) {
200203 synchronized (LOCK ) {
201204 Context context = contextWeakReference .get ();
202205 if (context != null ) {
@@ -206,12 +209,14 @@ private boolean isFirstStatusCheck(String address){
206209 return false ;
207210 }
208211 }
212+
209213 /**
210214 * Checks to see if a device address has connected to SDL before.
215+ *
211216 * @param address the mac address of the device in quesiton
212217 * @return if an SDL connection has ever been established with this device
213218 */
214- public static boolean hasSDLConnected (Context context , String address ){
219+ public static boolean hasSDLConnected (Context context , String address ) {
215220 synchronized (LOCK ) {
216221 if (context != null ) {
217222 SharedPreferences preferences = context .getSharedPreferences (SDL_DEVICE_STATUS_SHARED_PREFS , Context .MODE_PRIVATE );
@@ -226,18 +231,19 @@ public static boolean hasSDLConnected(Context context, String address){
226231 * feature can be supported. Due to older libraries sending their intents to start the router
227232 * service right at the bluetooth A2DP/HFS connections, this feature can't be used until all
228233 * applications are updated to the point they include the feature.
234+ *
229235 * @param sdlAppInfoList current list of SDL enabled applications on the device
230236 * @return if this feature is supported or not. If it is not, the caller should follow the
231- * previously used flow, ie start the router service.
237+ * previously used flow, ie start the router service.
232238 */
233- public static boolean isFeatureSupported (List <SdlAppInfo > sdlAppInfoList ){
239+ public static boolean isFeatureSupported (List <SdlAppInfo > sdlAppInfoList ) {
234240
235241 SdlAppInfo appInfo ;
236- for (int i = sdlAppInfoList .size () - 1 ; i >=0 ; i --){
242+ for (int i = sdlAppInfoList .size () - 1 ; i >= 0 ; i --) {
237243 appInfo = sdlAppInfoList .get (i );
238- if (appInfo != null
244+ if (appInfo != null
239245 && !appInfo .isCustomRouterService ()
240- && appInfo .getRouterServiceVersion () < MIN_VERSION_REQUIRED ) {
246+ && appInfo .getRouterServiceVersion () < MIN_VERSION_REQUIRED ) {
241247 return false ;
242248 }
243249 }
@@ -250,14 +256,15 @@ public static boolean isFeatureSupported(List<SdlAppInfo> sdlAppInfoList){
250256 * connection on the SDL UUID RFCOMM chanel or not. Most of the time the only callback that
251257 * matters will be the onTransportConnected.
252258 */
253- public interface Callback {
259+ public interface Callback {
254260 /**
255- *
256261 * @param bluetoothDevice the BT device that successfully connected to SDL's UUID
257262 * @return if the RFCOMM connection should stay open. In most cases this should be false
258263 */
259264 boolean onTransportConnected (Context context , BluetoothDevice bluetoothDevice );
265+
260266 void onTransportDisconnected (BluetoothDevice bluetoothDevice );
267+
261268 void onTransportError (BluetoothDevice bluetoothDevice );
262269 }
263270}
0 commit comments