마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

SecurityException: !@Too many alarms 문의 ㅠㅠ

0 추천
안녕하세요.

어플을 실행하면

SecurityException: !@Too many alarms 라는 에러로 인해 어플이 강제종료되어 문의드립니다..

노트5로 하고있는데

SecurityException: !@Too many alarms 라는 에러가 왜 나는건가요 ?

해당 어플에서 사용하는 Alarm은 한개 뿐인데 저런 에러가 나네요 ..
음무 (17,820 포인트) 님이 2016년 1월 8일 질문

3개의 답변

+1 추천
 
채택된 답변

아, 그렇군요. AltBeacon/android-beacon-library author 인 davidgyoung 에 따르면 아래와 같습니다.

davidgyoung commented on 18 Jun 2015

I have verified the change in 2.3-beta4 fixes this issue.

  • used a Samsung Galaxy S6 Edge with 5.0.2 from the Samsung Remote Test Lab
  • I modified a copy of the reference application to restart alarms every 1.1 seconds while the app was ranging in the foreground. I also modified it to track counts of the number of alarms restarted and the number of SecurityExceptions captured. I modified the RangingActivity to display these two counts on the screen.

The end result showed that the count of alarm restarts climbed over 500 with no exceptions being thrown.

2.3-beta4 에서 위의 문제 (삼성단말에서 알람 제한 500개)가 해결되었다고 합니다.
그리고 자신이 직접 검증했다고 screenshot 까지 첨부했습니다.
https://github.com/AltBeacon/android-beacon-library/issues/184
(이곳 마지막 쯤 보시면 첨부한 screenshots 있습니다.)

그리고 fix된 버전은 아래에서 다운로드 가능합니다.

The 2.3-beta4 release is available for download here:

https://github.com/AltBeacon/android-beacon-library/releases/tag/2.3-beta4

This has the proposed fix for the 500 Alarm limit on Samsung devices:

please try the 2.3-beta4 release linked above. Try linking it with your app then running it to see if you still get the crash. If you still get it, try uninstalling and reinstalling your app linked with 2.3-beta4 and test again. (Re-installation may be needed to clear out the count of alarms started... this is still unclear.)

밑줄을 보시면 일단 2.3-beta4로 link 해서 테스트 해보고 그래도 발생하면
앱을 제거(uninstall) 하고 2.3-beta4로 link한 버전으로 다시 설치해서 테스트 해보라고 합니다.
(제거하는 이유는 알람 카운트를 clear 하기 위해서...)
 

 i hope this may help you.

 

익명사용자 님이 2016년 1월 8일 답변
음무님이 2016년 1월 8일 채택됨
0 추천
저장하는 알람은 하나뿐인데 그 하나뿐인 알람을 계속적으로 저장하는거 아닐까요?

호출 부분에서 여러번 호출한다던지 등의..
캬옹이 (37,920 포인트) 님이 2016년 1월 8일 답변
같은 코드를 가진 알람을 계속적으로 호출하면 위와같이 문제가 발생하나요 ?
0 추천

Source: http://stackoverflow.com/questions/29344971/java-lang-securityexception-too-many-alarms-500-registered-from-pid-10790-u

Unlike what the comment suggests, this might not be your fault. This started happening for us in production code somewhere mid March, this only happens on Samsung with Lollipop which only recently started to be rolled out.

Update: This issue finally happened on one of the phones we have available.

like @goncalossilva said the problem is due to use of FLAG_CANCEL_CURRENT, it seems that Samsung introduces a cap of 500 on the amount of alarms and no other vendor have this limit.

when creating a PendingIntent with FLAG_CANCEL_CURRENT it will cancel the pending intent (obviously) won't cancel the alarm (also obvious), later if you cancel the alarm using the new pending intent it won't cancel the alarm (less obvious as Intent.filterEquals should be true). That being said, because the pending intent was canceled the old alarm won't actually fire, so there it no fear in introducing bugs by switching FLAG_UPDATE_CURRENT.

regarding the need to restart the device after changing to FLAG_UPDATE_CURRENT, you don't have to restart you just need to wait for one of the alarms to fire so that you have a new slot for a new alarm.

you can try this code to reproduce the issue, then change to FLAG_UPDATE_CURRENT to see what happens. you should also run "adb shell dumpsys alarm" to see all the generated alarms

AlarmManager alarmManager =
    (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);

    for (int i = 0; i<1000; i++)
    {
        Intent intent = new Intent("FOOFOOFOO");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
            this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        alarmManager.cancel(pendingIntent);

        long firstTime = SystemClock.elapsedRealtime() + 1000;
        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                firstTime, pendingIntent);
    } 

...

Using adb shell dumpsys alarm I found out that our app had been leaking alarms all along, it just wasn't visible before this. Changing FLAG_CANCEL_CURRENT to FLAG_UPDATE_CURRENT and making sure the PendingIntents were identical (extracting their creation to a common method) solved it for us. – Sampo Jul 30 '15 at 10:41

 

이곳도 확인 해보시기 바랍니다.

Source: https://github.com/AltBeacon/android-beacon-library/issues/184

starts the alarm with:

PendingIntent.getBroadcast(mContext, 0, wakeupIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

and cancels it with:

long milliseconds = Long.MAX_VALUE; // 2.9 million years from now
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(
        Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +
        milliseconds, getWakeUpOperation());

 

i hope this may help you.

 

익명사용자 님이 2016년 1월 8일 답변
2016년 1월 8일 수정
실제로 저도 altbeacon 라이브러리를 사용한 어플에서 에러가 발생합니다만
영어가 짧아 어떻게 처리하라는건지 알기가 힘드네요 .. ㅠㅠ
...