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

Fatal Exception: java.lang.SecurityException !@Too many alarms (500) #627

Closed
vhontar opened this issue Nov 14, 2019 · 7 comments
Closed

Comments

@vhontar
Copy link

vhontar commented Nov 14, 2019

Goals

I want to avoid background crashes which happened to the users all the time.

Expected Results

https://github.com/facebook/facebook-android-sdk/blob/5.x-branch/facebook-core/src/main/java/com/facebook/AccessTokenManager.java#L157

Could you please at least put alarm set to try/catch to avoid crashes in the background

try {
alarmManager.set(
                AlarmManager.RTC,
                accessToken.getExpires().getTime(),
                alarmIntent);
} catch (SecurityException e) {}

Actual Results

Fatal Exception: java.lang.SecurityException
!@Too many alarms (500) registered from uid 10126
android.os.Parcel.createException (Parcel.java:1966)
android.app.AlarmManager.set (AlarmManager.java:379)
com.facebook.AccessTokenManager.setTokenExpirationBroadcastAlarm (AccessTokenManager.java:172)
com.facebook.AccessTokenManager.setCurrentAccessToken (AccessTokenManager.java:135)
com.facebook.AccessTokenManager.setCurrentAccessToken (AccessTokenManager.java:115)
com.facebook.AccessTokenManager$4.onBatchCompleted (AccessTokenManager.java:364)
com.facebook.GraphRequest$5.run (GraphRequest.java:1400)
android.os.Handler.handleCallback (Handler.java:873)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

Steps to Reproduce

If you've set up already more than 500 alarms by the app. Some devices, especially Samsung (android 7) has some security measures to forbid to create more than 500 alarms.

Is it possible to add this try/catch code to avoid such crashes in the future?

@emreyanik
Copy link

In addition to this, could you change pending intent flag to PendingIntent.FLAG_UPDATE_CURRENT from 0 to prevent alarm duplication on some Samsung devices.

https://github.com/facebook/facebook-android-sdk/blob/5.x-branch/facebook-core/src/main/java/com/facebook/AccessTokenManager.java#L170

Expected Result

PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

@vhontar
Copy link
Author

vhontar commented Nov 21, 2019

The problem is that I have to set alarms for different local notifications for different times. So request code is different for all pending intents. That's why they are all different. If I understand right FLAG_UPDATE_CURRENT doesn't help in that case if only request code isn't the same

 private fun cancelAlarm(myBookingNotification: MyBookingNotification) {
        val notificationIntent = getNotificationIntent(myBookingNotification)
        val pendingIntent = PendingIntent.getBroadcast(context, myBookingNotification.uniqueNotificationId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
        val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        if (pendingIntent != null) {
            alarmManager.cancel(pendingIntent)
        }
    }

private fun schedulerAlarm(myBookingNotification: MyBookingNotification) {
        val notificationIntent = getNotificationIntent(myBookingNotification)
        val pendingIntent = PendingIntent.getBroadcast(context, myBookingNotification.uniqueNotificationId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)

        val futureInMillis = System.currentTimeMillis() + delay
        val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        try {
            alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMillis, pendingIntent)
        } catch (e: SecurityException) { }
}

@emreyanik
Copy link

I think there is a misunderstanding. You're right about alarms with different request code doesn't need FLAG_UPDATE_CURRENT. But my suggestion was for facebook sdk, not for you. Because facebook set same alarm with same request code so some samsung devices throw exception when exceeds the alarm limit. Actually I increased your suggestion :)

@stale
Copy link

stale bot commented Feb 19, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Feb 19, 2020
@vhontar
Copy link
Author

vhontar commented Feb 20, 2020 via email

@stale stale bot removed the Stale label Feb 20, 2020
@iceteahh
Copy link

@vhontar What is the solution for it? I'm facing this problem too

@ryutb
Copy link

ryutb commented Oct 30, 2020

@vhontar What is the solution for it? I'm facing this problem too

Me too

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

6 participants
@iceteahh @emreyanik @KylinChang @vhontar @ryutb and others