Skip to content

Commit 762ffc9

Browse files
committed
Merge branch 'develop' into bugfix/issue_1859_foreground_service_type
# Conflicts: # android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java
2 parents 5bad185 + d0845a9 commit 762ffc9

9 files changed

Lines changed: 56 additions & 14 deletions

File tree

android/hello_sdl_android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 33
4+
compileSdkVersion 34
55
defaultConfig {
66
applicationId "com.sdl.hellosdlandroid"
77
minSdkVersion 16
8-
targetSdkVersion 33
8+
targetSdkVersion 34
99
versionCode 1
1010
versionName "1.0"
1111
resValue "string", "app_name", "Hello Sdl Android"

android/sdl_android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 33
4+
compileSdkVersion 34
55
defaultConfig {
66
minSdkVersion 16
7-
targetSdkVersion 33
7+
targetSdkVersion 34
88
versionCode 25
99
versionName new File(projectDir.path, ('/../../VERSION')).text.trim()
1010
buildConfigField "String", "VERSION_NAME", '\"' + versionName + '\"'

android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.smartdevicelink.proxy.rpc.enums.PredefinedWindows;
5757
import com.smartdevicelink.proxy.rpc.enums.RequestType;
5858
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
59+
import com.smartdevicelink.util.AndroidTools;
5960
import com.smartdevicelink.util.DebugTool;
6061

6162
import java.lang.ref.WeakReference;
@@ -134,7 +135,9 @@ public void start(CompletionListener listener) {
134135
public void dispose() {
135136
// send broadcast to close lock screen if open
136137
if (context.get() != null) {
137-
context.get().sendBroadcast(new Intent(SDLLockScreenActivity.CLOSE_LOCK_SCREEN_ACTION));
138+
Intent intent = new Intent(SDLLockScreenActivity.CLOSE_LOCK_SCREEN_ACTION)
139+
.setPackage(context.get().getPackageName());
140+
context.get().sendBroadcast(intent);
138141
try {
139142
context.get().unregisterReceiver(mLockscreenDismissedReceiver);
140143
lockscreenDismissReceiverRegistered = false;
@@ -332,7 +335,9 @@ private void launchLockScreenActivity() {
332335
// pass in icon, background color, and custom view
333336
if (lockScreenEnabled && isApplicationForegrounded && context.get() != null) {
334337
if (isLockscreenDismissible && !lockscreenDismissReceiverRegistered) {
335-
context.get().registerReceiver(mLockscreenDismissedReceiver, new IntentFilter(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED));
338+
AndroidTools.registerReceiver(context.get(), mLockscreenDismissedReceiver,
339+
new IntentFilter(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED),
340+
Context.RECEIVER_NOT_EXPORTED);
336341
lockscreenDismissReceiverRegistered = true;
337342

338343
}
@@ -373,7 +378,9 @@ private void closeLockScreenActivity() {
373378
if (context.get() != null) {
374379
LockScreenStatus status = getLockScreenStatus();
375380
if (status == LockScreenStatus.OFF || (status == LockScreenStatus.OPTIONAL && displayMode != LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED)) {
376-
context.get().sendBroadcast(new Intent(SDLLockScreenActivity.CLOSE_LOCK_SCREEN_ACTION));
381+
Intent intent = new Intent(SDLLockScreenActivity.CLOSE_LOCK_SCREEN_ACTION)
382+
.setPackage(context.get().getPackageName());
383+
context.get().sendBroadcast(intent);
377384
}
378385
}
379386
lastIntentUsed = null;
@@ -428,6 +435,7 @@ public void onImageRetrieved(Bitmap icon) {
428435
intent.putExtra(SDLLockScreenActivity.LOCKSCREEN_DEVICE_LOGO_EXTRA, deviceLogoEnabled);
429436
intent.putExtra(SDLLockScreenActivity.LOCKSCREEN_DEVICE_LOGO_BITMAP, deviceLogo);
430437
if (context.get() != null) {
438+
intent.setPackage(context.get().getPackageName());
431439
context.get().sendBroadcast(intent);
432440
}
433441
}

android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import android.widget.TextView;
5353

5454
import com.smartdevicelink.R;
55+
import com.smartdevicelink.util.AndroidTools;
5556

5657
public class SDLLockScreenActivity extends Activity {
5758

@@ -106,7 +107,8 @@ protected void onCreate(Bundle savedInstanceState) {
106107
lockscreenFilter.addAction(LOCKSCREEN_DEVICE_LOGO_DOWNLOADED);
107108

108109
// register broadcast receivers
109-
registerReceiver(lockScreenBroadcastReceiver, lockscreenFilter);
110+
AndroidTools.registerReceiver(this, lockScreenBroadcastReceiver, lockscreenFilter,
111+
RECEIVER_NOT_EXPORTED);
110112
}
111113

112114
@Override
@@ -284,7 +286,9 @@ private class SwipeUpGestureListener extends GestureDetector.SimpleOnGestureList
284286
public boolean onFling(MotionEvent event1, MotionEvent event2,
285287
float velocityX, float velocityY) {
286288
if ((event2.getY() - event1.getY()) > MIN_SWIPE_DISTANCE) {
287-
sendBroadcast(new Intent(KEY_LOCKSCREEN_DISMISSED));
289+
Intent intent = new Intent(KEY_LOCKSCREEN_DISMISSED)
290+
.setPackage(getPackageName());
291+
sendBroadcast(intent);
288292
finish();
289293
}
290294
return true;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ public void startUpSequence() {
12421242

12431243
IntentFilter filter = new IntentFilter();
12441244
filter.addAction(REGISTER_WITH_ROUTER_ACTION);
1245-
registerReceiver(mainServiceReceiver, filter);
1245+
AndroidTools.registerReceiver(this, mainServiceReceiver, filter, RECEIVER_EXPORTED);
12461246

12471247
if (!connectAsClient) {
12481248
if (bluetoothAvailable()) {
@@ -1890,6 +1890,7 @@ public void onTransportConnected(final TransportRecord record) {
18901890
//the developer can use this pendingIntent to start their SdlService from the context of
18911891
//the active RouterService
18921892
Intent pending = new Intent();
1893+
pending.setPackage(getPackageName());
18931894
PendingIntent pendingIntent = PendingIntent.getForegroundService(this, (int) System.currentTimeMillis(), pending, PendingIntent.FLAG_MUTABLE | Intent.FILL_IN_COMPONENT);
18941895
startService.putExtra(TransportConstants.PENDING_INTENT_EXTRA, pendingIntent);
18951896
}
@@ -3013,6 +3014,7 @@ private Intent createPingIntent() {
30133014
//the developer can use this pendingIntent to start their SdlService from the context of
30143015
//the active RouterService
30153016
Intent pending = new Intent();
3017+
pending.setPackage(getPackageName());
30163018
PendingIntent pendingIntent = PendingIntent.getForegroundService(this, (int) System.currentTimeMillis(), pending, PendingIntent.FLAG_MUTABLE | Intent.FILL_IN_COMPONENT);
30173019
pingIntent.putExtra(TransportConstants.PENDING_INTENT_EXTRA, pendingIntent);
30183020
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.smartdevicelink.transport.enums.TransportType;
5151
import com.smartdevicelink.transport.utl.SdlDeviceListener;
5252
import com.smartdevicelink.transport.utl.TransportRecord;
53+
import com.smartdevicelink.util.AndroidTools;
5354
import com.smartdevicelink.util.DebugTool;
5455

5556
import java.lang.ref.WeakReference;
@@ -412,7 +413,8 @@ synchronized void enterLegacyMode(final String info) {
412413
IntentFilter intentFilter = new IntentFilter();
413414
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
414415
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
415-
contextWeakReference.get().registerReceiver(legacyDisconnectReceiver, intentFilter);
416+
AndroidTools.registerReceiver(contextWeakReference.get(),
417+
legacyDisconnectReceiver, intentFilter, Context.RECEIVER_EXPORTED);
416418
}
417419
} else {
418420
new Handler(Looper.myLooper()).postDelayed(new Runnable() {

android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
package com.smartdevicelink.util;
3434

35+
import android.annotation.SuppressLint;
36+
import android.content.BroadcastReceiver;
3537
import android.Manifest;
3638
import android.content.ComponentName;
3739
import android.content.Context;
@@ -397,6 +399,29 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str
397399
}
398400
}
399401

402+
/**
403+
* A helper method to handle adding flags to registering a run time broadcast receiver.
404+
*
405+
* @param context a context that will be used to register the receiver with
406+
* @param receiver the receiver that will be registered
407+
* @param filter the filter that will be use to filter intents sent to the broadcast receiver
408+
* @param flags any flags that should be used to register the receiver. In most cases this
409+
* will be {@link Context#RECEIVER_NOT_EXPORTED} or
410+
* {@link Context#RECEIVER_EXPORTED}
411+
* @see Context#registerReceiver(BroadcastReceiver, IntentFilter)
412+
* @see Context#registerReceiver(BroadcastReceiver, IntentFilter, int)
413+
*/
414+
@SuppressLint("UnspecifiedRegisterReceiverFlag")
415+
public static void registerReceiver(Context context, BroadcastReceiver receiver, IntentFilter filter, int flags) {
416+
if (context != null && receiver != null && filter != null) {
417+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
418+
context.registerReceiver(receiver, filter, flags);
419+
} else {
420+
context.registerReceiver(receiver, filter);
421+
}
422+
}
423+
}
424+
400425
/**
401426
* A helper method is used to see if this app has permission for UsbAccessory.
402427
* We need UsbAccessory permission if we are plugged in via AOA and do not have BLUETOOTH_CONNECT

android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ private void updateBroadcastReceiver() {
261261
}
262262
unregisterBroadcastReceiver();
263263
//Re-register receiver
264-
context.registerReceiver(broadcastReceiver, intentFilter);
265-
264+
AndroidTools.registerReceiver(context, broadcastReceiver, intentFilter,
265+
Context.RECEIVER_EXPORTED);
266266
}
267267

268268
}

android/sdl_android/src/main/java/com/smartdevicelink/util/ServiceFinder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public ServiceFinder(Context context, String packageName, final ServiceFinderCal
7474

7575
this.sdlMultiMap = AndroidTools.getSdlEnabledApps(context, packageName);
7676

77-
this.context.registerReceiver(mainServiceReceiver, new IntentFilter(this.receiverLocation));
77+
AndroidTools.registerReceiver(this.context, mainServiceReceiver,
78+
new IntentFilter(this.receiverLocation), Context.RECEIVER_EXPORTED);
7879

7980
timeoutRunnable = new Runnable() {
8081
@Override

0 commit comments

Comments
 (0)