@@ -418,7 +418,6 @@ public void handleMessage(Message msg) {
418418
419419 break ;
420420 case TransportConstants .ROUTER_SEND_PACKET :
421- Log .d (TAG , "Received packet to send" );
422421 if (receivedBundle !=null ){
423422 Runnable packetRun = new Runnable (){
424423 @ Override
@@ -908,7 +907,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
908907 }
909908 }
910909 int timeout = getNotificationTimeout (address );
911- enterForeground ("Waiting for connection..." , timeout );
910+ enterForeground ("Waiting for connection..." , timeout , false );
912911 resetForegroundTimeOut (timeout );
913912 }
914913 if (intent .hasExtra (TransportConstants .PING_ROUTER_SERVICE_EXTRA )){
@@ -1012,18 +1011,15 @@ private int getNotificationTimeout(String address){
10121011 if (address != null ){
10131012 if (hasSDLConnected (address )){
10141013 return FOREGROUND_TIMEOUT * 2 ;
1015- }else if (this .isFirstStatusCheck (address )){
1014+ }else if (this .isFirstStatusCheck (address )) {
10161015 // If this is the first time the service has ever connected to this device we want
1017- // to give it a few extra seconds.
1018- setSDLConnectedStatus (address ,false );
1019- return FOREGROUND_TIMEOUT ;
1020- }else {
1021- // If the service has seen this device before but hasn't ever connected, the
1022- // notification can be removed ASAP.
1023- return FOREGROUND_TIMEOUT /100 ;
1016+ // to ensure we have a record of it
1017+ setSDLConnectedStatus (address , false );
10241018 }
10251019 }
1026- return FOREGROUND_TIMEOUT /100 ;
1020+ // If this is a new device or hasn't connected through SDL we want to limit the exposure
1021+ // of the SDL service in the foreground
1022+ return FOREGROUND_TIMEOUT /1000 ;
10271023 }
10281024
10291025 public void resetForegroundTimeOut (long delay ){
@@ -1056,7 +1052,7 @@ public void cancelForegroundTimeOut(){
10561052
10571053 @ SuppressLint ("NewApi" )
10581054 @ SuppressWarnings ("deprecation" )
1059- private void enterForeground (String content , long chronometerLength ) {
1055+ private void enterForeground (String content , long chronometerLength , boolean ongoing ) {
10601056 if (android .os .Build .VERSION .SDK_INT < android .os .Build .VERSION_CODES .HONEYCOMB ){
10611057 Log .w (TAG , "Unable to start service as foreground due to OS SDK version being lower than 11" );
10621058 isForeground = false ;
@@ -1094,7 +1090,7 @@ private void enterForeground(String content, long chronometerLength) {
10941090 builder .setSmallIcon (android .R .drawable .stat_sys_data_bluetooth );
10951091 }
10961092 builder .setLargeIcon (icon );
1097- builder .setOngoing (true );
1093+ builder .setOngoing (ongoing );
10981094
10991095 // Create an intent that will be fired when the user clicks the notification.
11001096 Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (SDL_NOTIFICATION_FAQS_PAGE ));
@@ -1240,7 +1236,7 @@ private synchronized void initBluetoothSerialService(){
12401236 public void onTransportConnected (final TransportType type ){
12411237 isTransportConnected = true ;
12421238 cancelForegroundTimeOut ();
1243- enterForeground ("Connected to " + this .getConnectedDeviceName (),0 );
1239+ enterForeground ("Connected to " + this .getConnectedDeviceName (),0 , true );
12441240 if (packetWriteTaskMaster !=null ){
12451241 packetWriteTaskMaster .close ();
12461242 packetWriteTaskMaster = null ;
@@ -2517,7 +2513,7 @@ public PacketWriteTask(Bundle bundle){
25172513 bytesToWrite = bundle .getByteArray (TransportConstants .BYTES_TO_SEND_EXTRA_NAME );
25182514 offset = bundle .getInt (TransportConstants .BYTES_TO_SEND_EXTRA_OFFSET , 0 ); //If nothing, start at the beginning of the array
25192515 size = bundle .getInt (TransportConstants .BYTES_TO_SEND_EXTRA_COUNT , bytesToWrite .length ); //In case there isn't anything just send the whole packet.
2520- this .priorityCoefficient = bundle .getInt (TransportConstants .PACKET_PRIORITY_COEFFICIENT ,0 ); Log . d ( TAG , "packet priority coef: " + this . priorityCoefficient );
2516+ this .priorityCoefficient = bundle .getInt (TransportConstants .PACKET_PRIORITY_COEFFICIENT ,0 );
25212517 }
25222518
25232519 @ Override
0 commit comments