Permission changed event not sent
Description:
I confirm that I searched in existing issues and can't find anything related to this.
I'm using react-native-onesignal on my project, and I'm listening to permission change event using the permission observer.
It seems that on Android, when navigating from the device settings to the app and toggling the "disable push notifications", the send app focus event is not sent, so I didn't receive any event in my listener, privating me the ability to display an up to date message to my user regarding his permissions.
Regarding the adb logcat output, I notice one difference between the happy and the sad (broken) flow: Happy flow:
07-21 15:10:00.302 10620 10620 D OneSignal: onActivityResumed: com.myapp.MainActivity@518cae6
07-21 15:10:00.302 10620 10620 D OneSignal: curActivity is NOW: com.myapp.MainActivity:com.myapp.MainActivity@518cae6
07-21 15:10:00.303 10620 10620 D OneSignal: ActivityLifecycleHandler handleFocus, with runnable: AppFocusRunnable{backgrounded=true, completed=true} nextResumeIsFirstActivity: false
07-21 15:10:00.303 10620 10620 D OneSignal: ActivityLifecycleHandler reset background state, call app focus
07-21 15:10:00.303 10620 10620 D OneSignal: Application on focus
07-21 15:10:00.310 10620 10620 D OneSignal: Application foregrounded focus time: 11784606
07-21 15:10:00.310 10620 10620 D OneSignal: isPastOnSessionTime currentTimeMillis: 1626873000310 lastSessionTime: 1626873000001 difference: 309
Sad flow:
07-21 16:26:29.278 17347 17347 D OneSignal: onActivityResumed: com.myapp.MainActivity@518cae6
07-21 16:26:29.278 17347 17347 D OneSignal: curActivity is NOW: com.myapp.MainActivity:com.myapp.MainActivity@518cae6
07-21 16:26:29.278 17347 17347 D OneSignal: ActivityLifecycleHandler handleFocus, with runnable: AppFocusRunnable{backgrounded=false, completed=true} nextResumeIsFirstActivity: false
07-21 16:26:29.278 17347 17347 D OneSignal: ActivityLifecycleHandler cancel background lost focus sync task
07-21 16:26:29.279 17347 17347 D OneSignal: OSFocusDelaySync cancel background sync
So it seems that in the bad flow, the backgrounded boolean value is false, and the app on focus logic is not called or something like that.
Note that the bad flow happens more often when switching fast between device settings and the app.
Environment
- Android SDK 29
- The SDK was added to my project using react-native-onesignal with RN auto linking.
Steps to Reproduce Issue:
- Create a new RN project with
npx react-native init RNOneSignalExample - Paste the following code in your
App.jsfile: (Be sure to replaceMY_APP_IDwith yours)
import React, { useEffect } from "react";
import {
Alert,
SafeAreaView,
ScrollView,
StatusBar,
View,
Text,
} from "react-native";
import OneSignal from "react-native-onesignal";
const App: () => Node = () => {
useEffect(() => {
OneSignal.setLogLevel(6, 0);
OneSignal.setAppId("MY_APP_ID");
OneSignal.addPermissionObserver(() => {
Alert.alert("Perm changed", "changed");
});
}, []);
return (
<SafeAreaView>
<StatusBar barStyle="light-content" />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View>
<Text>RNOneSignalExample</Text>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default App;
- Run the project on a real android device, open the device settings, then try to switch between your device app notifications settings and your app multiple time, toggling the value of your notifications permissions each times
- See that permissions changes aren't detected sometimes
Anything else:
- My real device: Samsung Galaxy A40
- Android version: 10
- Node version: 12.14.1
- npm package version: [email protected]
I post the issue here because all my searches seems to point directly the onesignal-android-sdk and not the react-native-onesignal package.
I'm not a Java expert, but I'm pretty sure that something is broken in the logic here: https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/src/main/java/com/onesignal/ActivityLifecycleHandler.java
I can confirm that it happens on a blank project with the latest RN version and the latest rn-onesignal version. Feel free to ask for more information.
Hi @nbdn, thanks for reporting with your investigation,
Your information was helpful for a recent fix for the permission observer that is released in native OneSignal-Android-SDK v4.6.6.
This fix is available in react-native-onesignal v4.3.6.
Please upgrade to fix this issue, and I am going to close for now. Please feel free to reach out with any problems and we can re-open in the future.