summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2018-03-09 15:24:11 -0500
committerJoey Grover <joeygrover@gmail.com>2018-03-09 15:24:11 -0500
commitced9919a1a331daabbb9a0dec9fcb0b6928aee32 (patch)
treebd404b0a35be46aeafde056f21d4fd50648781d2
parentd4f3ff3800ba55cb1012c5b466651beca9780480 (diff)
downloadsdl_android-ced9919a1a331daabbb9a0dec9fcb0b6928aee32.tar.gz
Move explicit broadcast method to AndroidTools for less redundant code
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java34
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java16
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java34
3 files changed, 42 insertions, 42 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
index 17f658ecf..eb83a3675 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
@@ -638,7 +638,7 @@ public class SdlRouterService extends Service{
if(service.pingIntent == null){
service.initPingIntent();
}
- service.sendExplicitBroadcast(service.pingIntent, null);
+ AndroidTools.sendExplicitBroadcast(service.getApplicationContext(),service.pingIntent, null);
}
break;
default:
@@ -1223,7 +1223,7 @@ public class SdlRouterService extends Service{
startService.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
- sendExplicitBroadcast(startService, null);
+ AndroidTools.sendExplicitBroadcast(getApplicationContext(),startService, null);
//HARDWARE_CONNECTED
if(!(registeredApps== null || registeredApps.isEmpty())){
@@ -2012,7 +2012,7 @@ public class SdlRouterService extends Service{
sdlApps = getPackageManager().queryBroadcastReceivers(pingIntent, 0);
}
- sendExplicitBroadcast(pingIntent, sdlApps);
+ AndroidTools.sendExplicitBroadcast(getApplicationContext(), pingIntent, sdlApps);
synchronized(PING_COUNT_LOCK){
pingCount++;
}
@@ -2037,34 +2037,6 @@ public class SdlRouterService extends Service{
pingIntent = null;
}
- /**
- * Sends the provided intent to the specified destinations making it an explicit intent, rather
- * than an implicit intent. A direct replacement of sendBroadcast(Intent). As of Android 8.0
- * (API 26+) implicit broadcasts are no longer sent to broadcast receivers that are declared via
- * the AndroidManifest.
- *
- * @param intent - the intent to send explicitly
- * @param apps - the list of apps that this broadcast will be sent to. If null is passed in
- * the intent will be sent to all SDL enabled apps via a query the package manager
- */
- private void sendExplicitBroadcast(Intent intent, List<ResolveInfo> apps) {
-
- if (apps == null) {
- apps = getPackageManager().queryBroadcastReceivers(intent, 0);
- }
-
- if (apps != null && apps.size()>0) {
- for(ResolveInfo app: apps){
- try {
- intent.setClassName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
- sendBroadcast(intent);
- }catch(Exception e){
- //In case there is missing info in the app reference we want to keep moving
- }
- }
- }
- }
-
/* ****************************************************************************************************************************************
// ********************************************************** TINY CLASSES ************************************************************
//*****************************************************************************************************************************************/
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java b/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
index feccb698f..e0e1c93f2 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/USBAccessoryAttachmentActivity.java
@@ -7,6 +7,8 @@ import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;
+import com.smartdevicelink.util.AndroidTools;
+
import java.util.List;
/**
@@ -71,17 +73,9 @@ public class USBAccessoryAttachmentActivity extends Activity {
intent.getParcelableExtra(
UsbManager.EXTRA_PERMISSION_GRANTED));
- List<ResolveInfo> apps = getPackageManager().queryBroadcastReceivers(usbAccessoryAttachedIntent, 0);
- if (apps != null && apps.size()>0) {
- for(ResolveInfo app: apps){
- try {
- usbAccessoryAttachedIntent.setClassName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
- sendBroadcast(usbAccessoryAttachedIntent);
- }catch(Exception e){
- //In case there is missing info in the app reference we want to keep moving
- }
- }
- }
+
+ AndroidTools.sendExplicitBroadcast(getApplicationContext(),usbAccessoryAttachedIntent,null);
+
}
finish();
diff --git a/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java
index 7a6063c9a..6a9fa4112 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java
@@ -121,4 +121,38 @@ public class AndroidTools {
return sdlAppInfoList;
}
+
+ /**
+ * Sends the provided intent to the specified destinations making it an explicit intent, rather
+ * than an implicit intent. A direct replacement of sendBroadcast(Intent). As of Android 8.0
+ * (API 26+) implicit broadcasts are no longer sent to broadcast receivers that are declared via
+ * the AndroidManifest.
+ *
+ * @param intent - the intent to send explicitly
+ * @param apps - the list of apps that this broadcast will be sent to. If null is passed in
+ * the intent will be sent to all apps that match the provided intent via a query
+ * to the package manager
+ */
+ public static void sendExplicitBroadcast(Context context, Intent intent, List<ResolveInfo> apps) {
+
+ if(context == null || intent == null){
+ return;
+ }
+
+ if (apps == null) {
+ apps = context.getPackageManager().queryBroadcastReceivers(intent, 0);
+ }
+
+ if (apps != null && apps.size()>0) {
+ for(ResolveInfo app: apps){
+ try {
+ intent.setClassName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
+ context.sendBroadcast(intent);
+ }catch(Exception e){
+ //In case there is missing info in the app reference we want to keep moving
+ }
+ }
+ }
+ }
+
}