Skip to content

Commit aa5b71b

Browse files
authored
Merge pull request #794 from smartdevicelink/feature/even_less_intrusive_notification
Even less intrusive notification
2 parents a8d42df + 71b9c50 commit aa5b71b

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public void run() {
788788
while (true) {
789789
try {
790790
bytesRead = mmInStream.read(buffer);
791-
Log.i(getClass().getName(), "Received " + bytesRead + " bytes from Bluetooth");
791+
//Log.i(getClass().getName(), "Received " + bytesRead + " bytes from Bluetooth");
792792
for (int i = 0; i < bytesRead; i++) {
793793
input = buffer[i];
794794

sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver{
3232

3333
private static final String TAG = "Sdl Broadcast Receiver";
3434

35-
private static final String BOOT_COMPLETE = "android.intent.action.BOOT_COMPLETED";
36-
private static final String ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED";
37-
private static final String STATE_CHANGED = "android.bluetooth.adapter.action.STATE_CHANGED" ;
38-
3935
protected static final String SDL_ROUTER_SERVICE_CLASS_NAME = "sdlrouterservice";
4036

4137
public static final String LOCAL_ROUTER_SERVICE_EXTRA = "router_service";
@@ -69,9 +65,7 @@ public void onReceive(Context context, Intent intent) {
6965
return;
7066
}
7167

72-
if(!(action.equalsIgnoreCase(BOOT_COMPLETE)
73-
|| action.equalsIgnoreCase(ACL_CONNECTED)
74-
|| action.equalsIgnoreCase(STATE_CHANGED)
68+
if(!(action.equalsIgnoreCase(BluetoothDevice.ACTION_ACL_CONNECTED)
7569
|| action.equalsIgnoreCase(USBTransport.ACTION_USB_ACCESSORY_ATTACHED)
7670
|| action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION))){
7771
//We don't want anything else here if the child class called super and has different intent filters
@@ -155,20 +149,8 @@ public void onListObtained(boolean successful) {
155149
didStart = wakeUpRouterService(context, false,altServiceWake,device );
156150

157151
}
158-
159152
}
160-
161-
if (action.contains("android.bluetooth.adapter.action.STATE_CHANGED")){
162-
int state = intent.getIntExtra("android.bluetooth.adapter.extra.STATE",-1);
163-
if (state == BluetoothAdapter.STATE_OFF ||
164-
state == BluetoothAdapter.STATE_TURNING_OFF){
165-
//onProtocolDisabled(context);
166-
//Let's let the service that is running manage what to do for this
167-
//If we were to do it here, for every instance of this BR it would send
168-
//an intent to stop service, where it's only one that is needed.
169-
return;
170-
}
171-
}
153+
172154

173155
Log.d(TAG, "Check for local router");
174156
if(localRouterClass!=null){ //If there is a supplied router service lets run some logic regarding starting one

sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)