Search code examples
androidbroadcastreceiveralarmmanageralarmandroid-pendingintent

Android pending Intent - Alarm - same code six(6) apps


I found something strange yesterday. While testing app with localization versions(different apps-dif. packages, the same code) I found one interesting bug - the app sets alarm with the AlarmManager and pending Intent - when the broadcast is fired , only one app gets activated and executes the pending intent and all others apps(only different language) are not reacting at all. Is this android bug?? I'm expecting that the set Alarm will trigger every one app that has it's own set Alarm but Android is starting or the last active app is triggered by the broadcast or receive broadcast? how is the pending Intent associated with the Broadcast from the System? How the System knows which app is expecting Broadcast and which one for this .apk? It may seems strange or hard to understand but Im confused too..

public class AlarmSetter  {

    public void SetAlarma(Context context){

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.SECOND, 57);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.HOUR_OF_DAY, 23); 
    calendar.add(Calendar.DAY_OF_MONTH, 0);

     Intent intent = new Intent(context, AlarmKicked.class);
     PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1333333, intent, PendingIntent.FLAG_UPDATE_CURRENT);
     AlarmManager am =(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
     am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,
             pendingIntent);       
    }

}

Solution

  • OK, waiting for confirmation about the bug

    OK, finally!!!!

    It is a LVL BUG: So , the app is bg.google.myapppackage.apk .. nothing wrong.. uses LVL license - ServerManagedPolicy - customized - bcs google says the developers are using the example..

    In the ServerManagedPolicy.java we have " private static final String DEFAULT_MAX_RETRIES = "0";" I just did " private static final String DEFAULT_MAX_RETRIES = "10";" That means 10 times to start before lockdown.. nothing new , the user can to start the app before the 10 checks are gone.. nice, isn't it?

    BUT! the problem is in the LVL , every start is registered by the system in very strange way.. how? simply: every start adds number to the package , like this

    03-17 00:25:45.318: I/PackageManager(59): /data/app/bg.google.myapppackage-1.apk changed; unpacking

    03-17 00:25:45.318: I/PackageManager(59): /data/app/bg.google.myapppackage-2.apk changed; unpacking

    03-17 00:25:45.318: I/PackageManager(59): /data/app/bg.google.myapppackage-3.apk changed; unpacking

    those are the times that the app was started... ok still nothing wrong... Nope!THIS IS WRONG! If you start the activity from package bg.google.myapppackage-1.apk and this package sets Alarm with the AlarmManager and you close the app , later the Alarm will be fired but the receiver will no any more exist.. bcs if the users close the app and start it again then we have bg.google.myapppackage-2.apk and the second package sets Alarm two, but when it is beeing closed the package doesn't exist any more... The system fires Broadcast but there is no Receiver and the app is not reacting at all. this was the problem in my case.. testing the app and never got Broadcast or only the active app registered the brodcast and the others didn't..

    So if you have app that is doing some update that is triggered by the AlarmManager, you must to set the " private static final String DEFAULT_MAX_RETRIES = "0";" to 0 otherwise in the retries period your app will show malfunction, or missing functionality // I think that Google must to fix that with changing the name of the package and someone must to post BUG Ticket.. This thing costed me almost 3 days(days I study IT, and nights I work at home.. so sleeping is something that I miss, and losing time like this is not wanted..)

    03-14 18:22:51.860: D/PackageManager(199): New package installed in /data/app/bg.google.myapppackage-1.apk

    03-17 00:25:45.348: D/installd(35): DexInv: --- BEGIN '/data/app/bg.google.myapppackage-1.apk' ---

    03-17 00:25:47.599: D/installd(35): DexInv: --- END '/data/app/bg.google.myapppackage-1.apk' (success) ---

    03-17 00:25:47.748: I/installd(35): move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex