Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook's "Messenger" has a SMS Broadcast Receiver that takes highest priority after reboot

Facebook's Messenger, has a priority of 2147483647, for their android.provider.Telephony.SMS_RECEIVED broadcast receiver, declared in their manifest.

(It's sad we are forced to not follow the documentation's standards of max priority being 1000 because other apps make their own rules)

I understand that if my priority is also set to the ridiculously high level of 2147483647 that I'd have to have my app installed first to take precedence over any "ties". No problem, I made a screen to alert users what apps would probably need to be uninstalled then re-installed after my app to function properly.

But, here's the problem - Everything works fine, but as soon as the phone reboots, "Messenger" starts getting precedence over my app. I've looked all over the place to see how they could do this black magic. How do they do this? How do I get priority after reboot, when my app is installed first?

The only thing that has come to mind so far, is package names being ordered alphabetically on boot when registering broadcast receivers.

com. f acebook > com. s trikeforcezero

I was about to attempt to register my broadcast receiver on android.intent.action.BOOT_COMPLETED but I have a feeling this won't work.

Messenger also has another "low priory broadcast receiver" for android.provider.Telephony.SMS_RECEIVED set to -1

like image 881
StrikeForceZero Avatar asked May 08 '13 18:05

StrikeForceZero


People also ask

What does message from broadcast receiver mean?

Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.

Which is the integer that represents the highest priority?

And the highest priority possible would be the maximum integer that android allows, which is (2^31 - 1). SYSTEM_HIGH_PRIORITY (1000): Applications should never use filters with this or higher priorities.


1 Answers

For sure:

If the user downloads your app before facebook, then your receiver will take precedence although both have the priority 2147483647. After a reboot, Facebook's receiver takes precedence although both have the same priority and yours was installed before. Therefore, for sure, the trick is in their BootReceiver.

Guesses:

  1. As a first step, add a boot receiver with the same priority 2147483647 (although priority has no effect but just add it) to your app. Try to install your app before facebook's app and restart the phone. It might be related to the fact that your process starts before facebook in this case and your sms receiver will start before facebook's.
  2. Do the same thing but rename your package name to a.a.a just to have precedence over facebook Alphabetically.
  3. In your Boot Receiver, try to add the following code:

    ComponentName component; component=new ComponentName(this, SmsReceiver.class); getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); component = new ComponentName(this, SmsReceiver.class); getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); 
  4. It might be useful to try to know whether your boot receiver is taking precedence over facebook's boot receiver. I am not sure if that is possible.

  5. Finally, there is the process which can be differentiated in the manifest but am not sure if that can be handy in anyway.

like image 144
Sherif elKhatib Avatar answered Oct 04 '22 17:10

Sherif elKhatib