Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onesignal React Native: Package causes Android widgets onUpdate each time app is opened and closed #1392

Open
Davescat opened this issue May 24, 2022 · 3 comments
Assignees

Comments

@Davescat
Copy link

Description:

This issue is affecting the React native Android Widgets.

The Onesignal package is causing widgets to update when opening/closing any activity, causing reloads and unnecessary refreshes. The intent action ACTION_APPWIDGET_UPDATE should be sent when the app widget provider is instantiated or when the update interval causes it to update (docs).

What I think is happening is that the app widget provider is being reinitialized since the action is being sent more than it should and the widget view is not refreshing/updating but instead being "restarted". Before adding the package when the widget would refresh the values would be updated, now the view returns to an empty state and re-fetches everything. I've also noticed the widget gets refreshed more than usual when observing logs. The update interval we have set is every 30 minutes but it seems like it's getting updated every 3-6 minutes, which could be taking a lot of battery life.

Keep in mind that in the logs below the widget should not be updating at all in these scenarios, and work accordingly when onesignal is removed from the project.

The logs below is what happens when the activity is put into the background and I've highlighted where the widget get's updated with arrows.

On activity close/background

D/OneSignal: onActivityPaused: web.project.com.MainActivity@70949f0
D/OneSignal: ActivityLifecycleHandler Handling lost focus
D/OneSignal: Application stopped focus time: 275926580 timeElapsed: 109
D/OneSignal: FocusTimeProcessorUnattributed:saveUnsentActiveData with lastFocusTimeInfluences: [SessionInfluence{influenceChannel=iam, influenceType=UNATTRIBUTED, ids=null}, SessionInfluence{influenceChannel=notification, influenceType=UNATTRIBUTED, ids=null}]
D/OneSignal: FocusTimeProcessorUnattributed:getUnsentActiveTime: 36
D/OneSignal: FocusTimeProcessorUnattributed:saveUnsentActiveTime: 145
D/OneSignal: curActivity is NOW: null
D/OneSignal: onActivityStopped: web.project.com.MainActivity@70949f0
D/OneSignal: curActivity is NOW: null
D/OneSignal: Running destroyTimeout with runnable: com.onesignal.OSFocusHandler$startOnStopFocusWork$1@b82c1a1
D/OneSignal: Running startTimeout with timeout: 1500 and runnable: com.onesignal.OSFocusHandler$startOnStopFocusWork$1@b82c1a1
-----> V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
-----> V/WIDGET_UPDATE: onUpdate called
D/OneSignal: OSFocusHandler running onAppLostFocus
D/OneSignal: Application lost focus initDone: true
D/OneSignal: Last session time set to: 1653407136241
D/OneSignal: GMSLocationController onFocusChange!
D/OneSignal: Application backgrounded focus time: 275926580
D/OneSignal: FocusTimeProcessorUnattributed:getUnsentActiveTime: 145
D/OneSignal: FocusTimeProcessorUnattributed:sendUnsentTimeNow with time: 145 and influences: []
D/OneSignal: FocusTimeProcessorUnattributed sendTime with: BACKGROUND
D/OneSignal: FocusTimeProcessorUnattributed:getUnsentActiveTime: 145
V/OneSignal: OSSyncService scheduleSyncTask:SYNC_AFTER_BG_DELAY_MS: 30000
V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:atTime: 30000
I/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:result: 1
D/OneSignal: OneSignal scheduleSyncService unsyncedChanges: false
D/OneSignal: LocationController scheduleUpdate not possible, location permission not enabled
D/OneSignal: OneSignal scheduleSyncService locationScheduled: false
D/OneSignal: OSFocusHandler setting stop state: true
-----> V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
-----> V/WIDGET_UPDATE: onUpdate called

On activity open

 D/OneSignal: OSFocusHandler running onAppStartFocusLogic
 D/OneSignal: onActivityResumed: web.project.com.MainActivity@70949f0
 D/OneSignal: curActivity is NOW: web.project.com.MainActivity:web.project.com.MainActivity@70949f0
 D/OneSignal: ActivityLifecycleHandler handleFocus, nextResumeIsFirstActivity: false
 D/OneSignal: ActivityLifecycleHandler reset background state, call app focus
 D/OneSignal: OSFocusHandler running onAppFocus
 D/OneSignal: Application on focus
 D/OneSignal: GMSLocationController onFocusChange!
 D/OneSignal: Application foregrounded focus time: 276276715
 D/OneSignal: isPastOnSessionTime currentTimeMillis: 1653407375600 lastSessionTime: 1653407136241 difference: 239359
 D/OneSignal: Starting new session with appEntryState: APP_OPEN
 D/OneSignal: OneSignal cleanOutcomes for session
 D/OneSignal: OneSignal save unattributedUniqueOutcomeEvents: []
 D/OneSignal: OneSignal SessionManager restartSessionIfNeeded with entryAction: APP_OPEN
influenceType=UNATTRIBUTED, indirectIds=null, directId=null}, OSChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}]
 D/OneSignal: OneSignal ChannelTracker getLastReceivedIds lastChannelObjectReceived: []
 D/OneSignal: OneSignal SessionManager restartSessionIfNeeded lastIds: []
 D/OneSignal: OneSignal ChannelTracker getLastReceivedIds lastChannelObjectReceived: []
 D/OneSignal: OneSignal SessionManager restartSessionIfNeeded lastIds: []
 D/OneSignal: OneSignal SessionManager sendSessionEndingWithInfluences with influences: []
 D/OneSignal: Last session time set to: 1653407375602
 D/OneSignal: initWithCachedInAppMessages: null
 I/OneSignal: Location permissions not added on AndroidManifest file
 D/OneSignal: LocationController sendAndClearPromptHandlers from non prompt flow
 D/OneSignal: registerUser:registerForPushFired:true, locationFired: true, remoteParams: com.onesignal.OneSignalRemoteParams$2@1d51105, appId: hidden_id
 D/OneSignal: LocationController scheduleUpdate not possible, location permission not enabled
 D/OneSignal: OSSyncService cancel background sync
 I/OneSignal: Device registered, push token = hidden_token
 D/OneSignal: registerForPushToken completed with id: hidden_id status: 1
 D/OneSignal: registerUser:registerForPushFired:true, locationFired: true, remoteParams: com.onesignal.OneSignalRemoteParams$2@1d51105, appId: hidden_id
 D/OneSignal: registerUserTask calling readyToUpdate
 E/OneSignal: Already initialized the OneSignal React-Native SDK
 D/OneSignal: registerUserTask calling readyToUpdate
 -----> V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
----->  V/WIDGET_UPDATE: onUpdate called
 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: true jsonBody: {"app_id":"hidden_id"}
 D/OneSignal: OneSignalRestClient: Making request to: https://api.onesignal.com/players/hidden_id/on_session
 D/OneSignal: OneSignalRestClient: POST SEND JSON: {"app_id":"hidden_id"}
 V/OneSignal: OneSignalRestClient: After con.getResponseCode to: https://api.onesignal.com/players/hidden_idon_session
 D/OneSignal: OneSignalRestClient: Successfully finished request to: https://api.onesignal.com/players/hidden_id/on_session
 D/OneSignal: OneSignalRestClient: POST RECEIVED JSON: {"success":true,"id":"hidden_id"}
 D/OneSignal: doCreateOrNewSession:response: {"success":true,"id":"hidden_id"}
 I/OneSignal: Device registered, UserId = hidden_id
 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: null
----->  V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
----->  V/WIDGET_UPDATE: onUpdate called

Here's the logs that show the widget's being updated every 3-6 minutes:

2022-05-24 11:50:52.409 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 11:50:52.410 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called
2022-05-24 11:53:52.984 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 11:53:52.984 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called
2022-05-24 11:56:53.570 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 11:56:53.570 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called
2022-05-24 11:56:53.572 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 11:56:53.572 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called
2022-05-24 12:02:54.730 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 12:02:54.730 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called
2022-05-24 12:08:56.001 15028-15028/co.company.project.internal V/WIDGET_UPDATE: intent action: android.appwidget.action.APPWIDGET_UPDATE
2022-05-24 12:08:56.001 15028-15028/co.company.project.internal V/WIDGET_UPDATE: onUpdate called

Environment

  1. Onesignal version: "^4.3.9"
  2. React native version: "0.67.2"
  3. Followed docs and used yarn

Steps to Reproduce Issue:

  1. Install the OneSignal React native SDK using yarn into your project
  2. Build a simple widget that fetches data or includes a simulated loading time to show refreshing
  3. Put logs in the onReceive function the outputs when the android.appwidget.action.APPWIDGET_UPDATE is called.
  4. close/open the app and observe if it happens for you as well.

Anything else:

Thanks for investigating!

@kesheshyan
Copy link
Contributor

Thanks for reporting, we are looking into this.

@kesheshyan
Copy link
Contributor

Seems like it is a similar issue to this one OneSignal/OneSignal-Android-SDK#1577

@jkasten2 jkasten2 changed the title Onesignal React Native: Package breaks Android widgets Onesignal React Native: Package causes Android widgets onUpdate each time app is opened and closed Jun 28, 2022
@olegk00
Copy link

olegk00 commented Jan 17, 2023

Hi, are there any updates on this issue from the OneSignal team? @kesheshyan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants