Skip to content

Commit 250dffb

Browse files
HeniganHenigan
authored andcommitted
RS Notificaiton only if has connected before
1 parent 4cb096b commit 250dffb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public class SdlRouterService extends Service {
202202
private boolean wrongProcess = false;
203203
private boolean initPassed = false;
204204
private boolean hasCalledStartForeground = false;
205+
private boolean hasConnectedBefore = false;
205206
boolean firstStart = true;
206207

207208
public static HashMap<String, RegisteredApp> registeredApps;
@@ -1284,6 +1285,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
12841285
}
12851286
if (intent != null) {
12861287
if (intent.getBooleanExtra(FOREGROUND_EXTRA, false)) {
1288+
hasConnectedBefore = false;
12871289
hasCalledStartForeground = false;
12881290

12891291
if (!this.isPrimaryTransportConnected()) { //If there is no transport connected we need to ensure the service is moved to the foreground
@@ -1296,6 +1298,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
12961298
}
12971299
boolean confirmedDevice = intent.getBooleanExtra(TransportConstants.CONFIRMED_SDL_DEVICE, false);
12981300
int timeout = getNotificationTimeout(address, confirmedDevice);
1301+
hasConnectedBefore = hasSDLConnected(address);
12991302

13001303
enterForeground("Waiting for connection...", timeout, false);
13011304
resetForegroundTimeOut(timeout);
@@ -1499,7 +1502,7 @@ private void enterForeground(String content, long chronometerLength, boolean ong
14991502
builder = new Notification.Builder(this, SDL_NOTIFICATION_CHANNEL_ID);
15001503
}
15011504

1502-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
1505+
if (hasConnectedBefore && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
15031506
builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE);
15041507
}
15051508

@@ -1573,7 +1576,7 @@ private void enterForeground(String content, long chronometerLength, boolean ong
15731576
private void safeStartForeground(int id, Notification notification) {
15741577
try {
15751578
if (notification == null) {
1576-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
1579+
if (hasConnectedBefore && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
15771580
Notification.Builder builder =
15781581
new Notification.Builder(this, SDL_NOTIFICATION_CHANNEL_ID)
15791582
.setContentTitle("SmartDeviceLink")
@@ -3820,7 +3823,7 @@ private void notifySppError() {
38203823
builder = new Notification.Builder(getApplicationContext(), TransportConstants.SDL_ERROR_NOTIFICATION_CHANNEL_ID);
38213824
}
38223825

3823-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
3826+
if (hasConnectedBefore && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
38243827
builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE);
38253828
}
38263829
ComponentName name = new ComponentName(this, this.getClass());

0 commit comments

Comments
 (0)