4

Does anyone know why my application still receives the ACTION_BOOT_COMPLETED broadcast even when my app doesn't have the permission android.permission.RECEIVE_BOOT_COMPLETED in the manifest file? I thought it was required but a few tutorials I used also didn't have it. A few did. I use my phone running CyanogenMod for testing but I doubt that matters. LogCat shows my "Notified of boot" log upon each boot. See below for code used.

AndroidManifest.xml

  <receiver android:name="AlarmReceiver">
   <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <category android:name="android.intent.category.HOME" />
   </intent-filter>
  </receiver>

AlarmReceiver class

  public class AlarmReceiver extends BroadcastReceiver {
  private static final String TAG = "MyProgram";

  @Override
  public void onReceive(Context context, Intent intent) {
   try {
          if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
     Log.d(TAG, "Notified of boot");
           }
          Intent newIntent = new Intent(context, MyService.class);
          context.startService(newIntent);
    } catch (Exception e) {
     Log.d(TAG, "An alarm was received but there was an error");
     e.printStackTrace();
     }
    }
  }

I revisited this on the emulator and successfully reproduced the "problem" on Android 2.1, 2.2 and 2.3. I get an ANR (as expected) since the emulator doesn't have the database my app queries. When I remove all declared uses-permissions from the manifest, I get the expected permission denial errors when trying to use my app. However, I still receive the ACTION_BOOT_COMPLETED intent broadcasted upon boot. Any suggestions?

capitalf
  • 471
  • 1
  • 6
  • 14
  • "I use my phone running CyanogenMod for testing but I doubt that matters" -- don't be so sure. Always test anomalies like this against at least an emulator running stock Android, to confirm that it's not something with that ROM. This is not a knock on Cyanogen -- I'd make that same recommendation if you have the same symptoms on a HTC or Motorola device. – CommonsWare Jan 08 '11 at 19:09
  • @CommonsWare: True. Unfortunately, my app uses functionality that isn't available in the emulator. I'll borrow someone's device to continue trying to rule out my current environment. Thanks for the suggestion. – capitalf Jan 08 '11 at 21:53
  • @CommonsWare I revisited this on the emulator and successfully reproduced the "problem" on Android 2.1, 2.2 and 2.3. I get an ANR since the emulator doesn't have the database my app queries. When I remove all declared uses-permissions from the manifest, I get the appropriate related errors when trying to use my app. However, I still receive the ACTION_BOOT_COMPLETED intent broadcasted upon boot. – capitalf Jan 09 '11 at 19:34
  • I will take a look at this sometime this week. – CommonsWare Jan 09 '11 at 23:47
  • I can confirm the same for Android 2.x. ICS seems to have rectified this. (my app stopped working). – leppie Feb 08 '12 at 16:43
  • I just tested this in ICS and it has been fixed. – ethan Apr 25 '12 at 04:24

1 Answers1

7

This would appear to be a bug in Android. I can reproduce the problem on ordinary Nexus One and Nexus S hardware. I have filed a bug report on it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for looking into this. I've starred the issue to keep alerted. I've used several apps installed that start on boot without this permission so this will be nice to see enforced. – capitalf Jan 16 '11 at 17:28