Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class SdlRouterService extends Service {
/**
* <b> NOTE: DO NOT MODIFY THIS UNLESS YOU KNOW WHAT YOU'RE DOING.</b>
*/
protected static final int ROUTER_SERVICE_VERSION_NUMBER = 16;
protected static final int ROUTER_SERVICE_VERSION_NUMBER = 17;

private static final String ROUTER_SERVICE_PROCESS = "com.smartdevicelink.router";

Expand Down Expand Up @@ -239,7 +239,6 @@ public class SdlRouterService extends Service {
* Executor for making sure clients are still running during trying times
*/
private ScheduledExecutorService clientPingExecutor = null;
Intent pingIntent = null;
private boolean isPingingClients = false;
int pingCount = 0;

Expand Down Expand Up @@ -818,10 +817,8 @@ public void handleMessage(Message msg) {
}
}
if (service.isPrimaryTransportConnected() && ((TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING & flags) == TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING)) {
if (service.pingIntent == null) {
service.initPingIntent();
}
AndroidTools.sendExplicitBroadcast(service.getApplicationContext(), service.pingIntent, null);
AndroidTools.sendExplicitBroadcast(service.getApplicationContext(),
service.createPingIntent(), null);
}
break;
default:
Expand Down Expand Up @@ -2967,16 +2964,29 @@ protected PacketWriteTask getNextTask(TransportType transportType) {
return null;
}

private void initPingIntent() {
pingIntent = new Intent();
private Intent createPingIntent() {
Intent pingIntent = new Intent();
pingIntent.setAction(TransportConstants.START_ROUTER_SERVICE_ACTION);
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_EXTRA, true);
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE, getBaseContext().getPackageName());
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(SdlRouterService.this, SdlRouterService.this.getClass()));
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_PING, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
//Starting in Android 12 we need to start services from a foreground context
//To enable developers to be able to start their SdlService from the "background"
//we will attach a pendingIntent as an extra to the intent
//the developer can use this pendingIntent to start their SdlService from the context of
//the active RouterService
Intent pending = new Intent();
PendingIntent pendingIntent = PendingIntent.getForegroundService(this, (int) System.currentTimeMillis(), pending, PendingIntent.FLAG_MUTABLE | Intent.FILL_IN_COMPONENT);
pingIntent.putExtra(TransportConstants.PENDING_INTENT_EXTRA, pendingIntent);
}

if (receivedVehicleType != null) {
pingIntent.putExtra(TransportConstants.VEHICLE_INFO_EXTRA, receivedVehicleType.getStore());
}

return pingIntent;
}

private void startClientPings() {
Expand All @@ -3001,6 +3011,7 @@ private void startClientPings() {

clientPingExecutor.scheduleAtFixedRate(new Runnable() {
List<ResolveInfo> sdlApps;
Intent pingIntent;

@Override
public void run() {
Expand All @@ -3010,7 +3021,7 @@ public void run() {
return;
}
if (pingIntent == null) {
initPingIntent();
pingIntent = createPingIntent();
}

if (sdlApps == null) {
Expand Down Expand Up @@ -3039,7 +3050,6 @@ private void stopClientPings() {
clientPingExecutor = null;
isPingingClients = false;
}
pingIntent = null;
}

/* ****************************************************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion android/sdl_android/src/main/res/values/sdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="sdl_router_service_version_name" translatable="false">sdl_router_version</string>

<integer name="sdl_router_service_version_value">16</integer>
<integer name="sdl_router_service_version_value">17</integer>

<string name="sdl_router_service_is_custom_name" translatable="false">sdl_custom_router</string>
<string name="sdl_oem_vehicle_type_filter_name" translatable="false">sdl_oem_vehicle_type</string>
Expand Down