Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
Android Documentation
SdlRouterService

Class SdlRouterService

Hierarchy

java.lang.Object
     android.content.Context
         android.content.ContextWrapper
             android.app.Service

Package
com.smartdevicelink.transport

Overview

This class should not be modified by anyone outside of the approved contributors of the SmartDeviceLink project. This service is a central point of communication between hardware and the registered clients. It will multiplex a single transport to provide a connection for a theoretical infinite amount of SDL sessions.

Fields

ROUTER_SERVICE_VERSION_NUMBER

protected static final int ROUTER_SERVICE_VERSION_NUMBER
Constant Value
16

REGISTER_NEWER_SERVER_INSTANCE_ACTION

public static final java.lang.String REGISTER_NEWER_SERVER_INSTANCE_ACTION
Constant Value
"com.sdl.android.newservice"

SDL_NOTIFICATION_FAQS_PAGE

public static final java.lang.String SDL_NOTIFICATION_FAQS_PAGE
Constant Value
"https://smartdevicelink.com/en/guides/android/frequently-asked-questions/sdl-notifications/"

REGISTER_WITH_ROUTER_ACTION

public static final java.lang.String REGISTER_WITH_ROUTER_ACTION
Constant Value
"com.sdl.android.register"

MESSAGE_STATE_CHANGE

public static final int MESSAGE_STATE_CHANGE
Constant Value
1

MESSAGE_READ

public static final int MESSAGE_READ
Constant Value
2

MESSAGE_WRITE

public static final int MESSAGE_WRITE
Constant Value
3

MESSAGE_DEVICE_NAME

public static final int MESSAGE_DEVICE_NAME
Constant Value
4

MESSAGE_LOG

public static final int MESSAGE_LOG
Constant Value
5

SDL_DEVICE_STATUS_SHARED_PREFS

protected static final java.lang.String SDL_DEVICE_STATUS_SHARED_PREFS
Constant Value
"sdl.device.status"

SDL_ROUTER_SERVICE_PREFS

protected static final java.lang.String SDL_ROUTER_SERVICE_PREFS
Constant Value
"sdl.router.service.prefs"

KEY_AVOID_NOTIFICATION_CHANNEL_DELETE

protected static final java.lang.String KEY_AVOID_NOTIFICATION_CHANNEL_DELETE
Constant Value
"avoidNotificationChannelDelete"

registeredApps

public static java.util.HashMap registeredApps

Inherited Fields

From Class Fields
android.app.Service START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY
android.content.Context ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APPWIDGET_SERVICE, APP_OPS_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, FINGERPRINT_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE

Constructors

SdlRouterService()

public SdlRouterService()

Methods

onBind( Intent intent )

public android.os.IBinder onBind(Intent intent)

Method Parameters

intent

onUnbind( Intent intent )

public boolean onUnbind(Intent intent)

Method Parameters

intent

formatMessage( SdlRouterService.RegisteredApp app, Message message )

Formats the message for the app that is to receive it

protected boolean formatMessage(SdlRouterService.RegisteredApp app,Message message)

Method Parameters

app
message

onCreate()

public void onCreate()

deployNextRouterService()

The method will attempt to start up the next router service in line based on the sorting criteria of best router service.

protected void deployNextRouterService()

startUpSequence()

public void startUpSequence()

setRouterServiceExceptionHandler()

This method will set a new UncaughtExceptionHandler for the current thread. The only purpose of the custom UncaughtExceptionHandler is to catch the rare occurrence that the a specific mobile device/OS can't properly handle the deletion and creation of the foreground notification channel that is necessary for foreground services after Android Oreo. The new UncaughtExceptionHandler will catch that specific exception and tell the main looper to continue forward. This still leaves the SdlRouterService killed, but prevents an ANR to the app that makes the startForegroundService call. It will set a flag that will prevent the channel from being deleted in the future and therefore avoiding this exception.

protected void setRouterServiceExceptionHandler()

onStartCommand( Intent intent, int flags, int startId )

public int onStartCommand(Intent intent,int flags,int startId)

Method Parameters

intent
flags
startId

onDestroy()

public void onDestroy()

resetForegroundTimeOut( long delay )

public void resetForegroundTimeOut(long delay)

Method Parameters

delay

cancelForegroundTimeOut()

public void cancelForegroundTimeOut()

shouldServiceRemainOpen( Intent intent )

1. If the app has SDL shut off, shut down 2. if The app has an Alt Transport address or was started by one, stay open 3. If Bluetooth is off/NA shut down 4. Anything else

public boolean shouldServiceRemainOpen(Intent intent)

Method Parameters

intent

closeSelf()

This method is needed so that apps that choose not to implement this as a service as defined by Android, but rather just a simple class we have to know how to shut down.

public void closeSelf()

onTransportConnected( TransportRecord record )

public void onTransportConnected(TransportRecord record)

Method Parameters

record

onTransportDisconnected( TransportRecord record )

public void onTransportDisconnected(TransportRecord record)

Method Parameters

record

onTransportError( TransportRecord transport, Bundle errorBundle )

public void onTransportError(TransportRecord transport,Bundle errorBundle)

Method Parameters

transport
errorBundle

onPacketRead( SdlPacket packet )

public void onPacketRead(SdlPacket packet)

Method Parameters

packet

writeBytesToTransport( Bundle bundle )

public boolean writeBytesToTransport(Bundle bundle)

Method Parameters

bundle

sendPacketToRegisteredApp( SdlPacket packet )

This will send the received packet to the registered service. It will default to the single registered "foreground" app. This can be overridden to provide more specific functionality.

public boolean sendPacketToRegisteredApp(SdlPacket packet)

Method Parameters

packet
the packet that is received

bluetoothQuerryAndConnect()

This function looks through the phones currently paired bluetooth devices If one of the devices' names contain "sync", or livio it will attempt to connect the RFCOMM And start SDL

public synchronized boolean bluetoothQuerryAndConnect()

setSDLConnectedStatus( String address, boolean hasSDLConnected )

Set the connection establishment status of the particular device

protected void setSDLConnectedStatus(String address,boolean hasSDLConnected)

Method Parameters

address
address of the device in question
hasSDLConnected
true if a connection has been established, false if not

isFirstStatusCheck( String address )

Checks to see if a device address has connected to SDL before.

protected boolean isFirstStatusCheck(String address)

Method Parameters

address
the mac address of the device in question

hasSDLConnected( String address )

Checks to see if a device address has connected to SDL before.

protected boolean hasSDLConnected(String address)

Method Parameters

address
the mac address of the device in question

setSdlRouterServicePrefs( String key, boolean value )

Set specific settings through key/value to the SDL_ROUTER_SERVICE_PREFS

protected void setSdlRouterServicePrefs(String key,boolean value)

Method Parameters

key
the key of the pair to set in the preferences
value
boolean to attach to key in the preferences

getBooleanPref( String key, boolean defaultValue )

Retrieves a boolean value for the given key in the SDL_ROUTER_SERVICE_PREFS

protected boolean getBooleanPref(String key,boolean defaultValue)

Method Parameters

key
the string key that will be used to retrieve the boolean value
defaultValue
if they key does not exist or there is no value to be found, this is the value that will be returned

getLocalRouterService( Intent launchIntent, ComponentName name )

Deprecated

protected static com.smartdevicelink.transport.SdlRouterService.LocalRouterService getLocalRouterService(Intent launchIntent,ComponentName name)

Method Parameters

launchIntent
name

getNextTask( TransportType transportType )

Method for finding the next, highest priority write task from all connected apps.

protected com.smartdevicelink.transport.SdlRouterService.PacketWriteTask getNextTask(TransportType transportType)

Method Parameters

transportType

Inherited Methods

From Class Methods
android.app.Service getApplication, onCreate, onStart, onStartCommand, onDestroy, onConfigurationChanged, onLowMemory, onTrimMemory, onBind, onUnbind, onRebind, onTaskRemoved, stopSelf, stopSelf, stopSelfResult, startForeground, stopForeground, dump
android.content.ContextWrapper attachBaseContext, getBaseContext, getAssets, getResources, getPackageManager, getContentResolver, getMainLooper, getApplicationContext, setTheme, getTheme, getClassLoader, getPackageName, getApplicationInfo, getPackageResourcePath, getPackageCodePath, getSharedPreferences, openFileInput, openFileOutput, deleteFile, getFileStreamPath, fileList, getFilesDir, getNoBackupFilesDir, getExternalFilesDir, getExternalFilesDirs, getObbDir, getObbDirs, getCacheDir, getCodeCacheDir, getExternalCacheDir, getExternalCacheDirs, getExternalMediaDirs, getDir, openOrCreateDatabase, openOrCreateDatabase, deleteDatabase, getDatabasePath, databaseList, getWallpaper, peekWallpaper, getWallpaperDesiredMinimumWidth, getWallpaperDesiredMinimumHeight, setWallpaper, setWallpaper, clearWallpaper, startActivity, startActivity, startActivities, startActivities, startIntentSender, startIntentSender, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyOrderedBroadcast, removeStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcastAsUser, removeStickyBroadcastAsUser, registerReceiver, registerReceiver, unregisterReceiver, startService, stopService, bindService, unbindService, startInstrumentation, getSystemService, getSystemServiceName, checkPermission, checkCallingPermission, checkCallingOrSelfPermission, checkSelfPermission, enforcePermission, enforceCallingPermission, enforceCallingOrSelfPermission, grantUriPermission, revokeUriPermission, checkUriPermission, checkCallingUriPermission, checkCallingOrSelfUriPermission, checkUriPermission, enforceUriPermission, enforceCallingUriPermission, enforceCallingOrSelfUriPermission, enforceUriPermission, createPackageContext, createConfigurationContext, createDisplayContext, isRestricted
android.content.Context getAssets, getResources, getPackageManager, getContentResolver, getMainLooper, getApplicationContext, registerComponentCallbacks, unregisterComponentCallbacks, getText, getString, getString, getColor, getDrawable, getColorStateList, setTheme, getTheme, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, getClassLoader, getPackageName, getApplicationInfo, getPackageResourcePath, getPackageCodePath, getSharedPreferences, openFileInput, openFileOutput, deleteFile, getFileStreamPath, getFilesDir, getNoBackupFilesDir, getExternalFilesDir, getExternalFilesDirs, getObbDir, getObbDirs, getCacheDir, getCodeCacheDir, getExternalCacheDir, getExternalCacheDirs, getExternalMediaDirs, fileList, getDir, openOrCreateDatabase, openOrCreateDatabase, deleteDatabase, getDatabasePath, databaseList, getWallpaper, peekWallpaper, getWallpaperDesiredMinimumWidth, getWallpaperDesiredMinimumHeight, setWallpaper, setWallpaper, clearWallpaper, startActivity, startActivity, startActivities, startActivities, startIntentSender, startIntentSender, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyOrderedBroadcast, removeStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcastAsUser, removeStickyBroadcastAsUser, registerReceiver, registerReceiver, unregisterReceiver, startService, stopService, bindService, unbindService, startInstrumentation, getSystemService, getSystemService, getSystemServiceName, checkPermission, checkCallingPermission, checkCallingOrSelfPermission, checkSelfPermission, enforcePermission, enforceCallingPermission, enforceCallingOrSelfPermission, grantUriPermission, revokeUriPermission, checkUriPermission, checkCallingUriPermission, checkCallingOrSelfUriPermission, checkUriPermission, enforceUriPermission, enforceCallingUriPermission, enforceCallingOrSelfUriPermission, enforceUriPermission, createPackageContext, createConfigurationContext, createDisplayContext, isRestricted
java.lang.Object getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize
View on GitHub.com
Previous Section Next Section