HMS-Core / hms-react-native-plugin

This repo contains all of React-Native HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
241 stars 68 forks source link

Location Kit causes crash on Android 14 #333

Closed megaacheyounes closed 4 months ago

megaacheyounes commented 4 months ago

Description when initializing Location Kit on Android 14, the initializer function tries to register a broadcast receiver which throws an exception:

HMSLocation.LocationKit.Native.init()

throw exception :

HMSBroadcastReceiver.init java.lang.SecurityException - com.package.name: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED  should be specified when a receiver isn't being registered exclusively for system broadcasts.

The code responsible for the exception is here: https://github.com/HMS-Core/hms-react-native-plugin/blob/master/react-native-hms-location/android/src/main/java/com/huawei/hms/rn/location/backend/helpers/HMSBroadcastReceiver.java#L159

To solve this, we simply need to pass third parameter, as this is a local broadcast receiver that does not receive broadcasts from other apps, we can pass RECEIVER_NOT_EXPORTED, example:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
      context.registerReceiver(getInstance(), getIntentFilter(context),RECEIVER_NOT_EXPORTED);      
}else {
      context.registerReceiver(getInstance(), getIntentFilter(context)); 
}

the crash happens on Android 14, but the flag above was introduced in Android 13

Android docs: https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter)

I understand location kit works only on Huawei phones, which may not support Android 14 yet, but its still an issue that needs to be fixed.

Thanks .

ozkulbeng commented 4 months ago

Hello @megaacheyounes Huawei Flutter Location plugin is a wrapper around Huawei Location SDK and currently, Huawei Location SDK does not support Android 14. For any questions related to Native SDKs please submit a ticket online.

CMLCNL commented 3 weeks ago

same issue