1515import com .smartdevicelink .util .AndroidTools ;
1616import com .smartdevicelink .util .DebugTool ;
1717
18- import java .lang .ref .WeakReference ;
1918
2019public class SdlReceiver extends SdlBroadcastReceiver {
2120 private static final String TAG = "SdlBroadcastReceiver" ;
2221
2322 private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION" ;
24- private PendingIntent pendingIntent ;
25- private Intent cachedIntent ;
23+ private PendingIntent pendingIntentToStartService ;
24+ private Intent startSdlServiceIntent ;
2625
2726 @ Override
2827 public void onSdlEnabled (Context context , Intent intent ) {
@@ -38,8 +37,8 @@ public void onSdlEnabled(Context context, Intent intent) {
3837 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
3938 if (!AndroidTools .hasForegroundServiceTypePermission (context )) {
4039 requestUsbAccessory (context );
41- cachedIntent = intent ;
42- this .pendingIntent = pendingIntent ;
40+ startSdlServiceIntent = intent ;
41+ this .pendingIntentToStartService = pendingIntent ;
4342 DebugTool .logInfo (TAG , "Permission missing for ForegroundServiceType connected device." + context );
4443 return ;
4544 }
@@ -81,10 +80,10 @@ public String getSdlServiceName() {
8180
8281 public void onReceive (Context context , Intent intent ) {
8382 String action = intent .getAction ();
84- if (ACTION_USB_PERMISSION .equals (action ) && context != null && cachedIntent != null && pendingIntent != null ) {
83+ if (ACTION_USB_PERMISSION .equals (action ) && context != null && startSdlServiceIntent != null && pendingIntentToStartService != null ) {
8584 if (AndroidTools .hasForegroundServiceTypePermission (context )) {
8685 try {
87- pendingIntent .send (context , 0 , cachedIntent );
86+ pendingIntentToStartService .send (context , 0 , startSdlServiceIntent );
8887 } catch (PendingIntent .CanceledException e ) {
8988 e .printStackTrace ();
9089 }
0 commit comments