PacketManager.setComponentEnabledSetting() API


Last Updated:

  1. siromik

    siromik Member This Topic's Starter

    Joined:
    Oct 21, 2009
    Messages:
    8
    Likes Received:
    0
    We found that apparently PacketManager.setComponentEnabledSetting() is a permanent setting which does not reset with an abrupt device power-cycle or task termination. The changes from setComponentEnabledSetting() are written into packages.xml. To enable/disable the setting one needs to call setComponentEnabledSetting() with appropriate flags from the code base.

    This means that if for example you registered a receiver in a manifest and then disabled that receiver through setComponentEnabledSetting(), and then the device crashed, the receiver in that manifest will no longer be working.

    I am wandering why google designed this the way they did.

    Did anyone see the same issue?
     

    Advertisement
  2. KeithG

    KeithG Well-Known Member

    Joined:
    Nov 15, 2009
    Messages:
    103
    Likes Received:
    3
    This is so you can have lots of Intent receivers or broadcast receivers and have them all be disabled by default via the manifest. Then programatically enable / disable them based on some logic.

    Example: receiving the BOOT_COMPLETED broadcast. You want to be able to start a service on boot, but you want to be able to have this be optional. So maybe you have a check box or button to enable disable.

    If the settings were not persistent, you could not disable this reception of this broadcast without uninstalling, or you'd need to have a boot completed receiver that then has to check some DB setting to see if it should continue processing .. and then possibly start a service via an intent call.

    The persistence removes the logic requiring that check. Every well written app that wants to do something on boot, would in fact have to have this boiler plate code in it. The persistence removes this necessity.
     
  3. siromik

    siromik Member This Topic's Starter

    Joined:
    Oct 21, 2009
    Messages:
    8
    Likes Received:
    0
    The primary issue I see is what happens if the device abnormally terminates.... which, is what we are currently debugging. Disabling a component will over-write the manifest and survive power-cycle which would mean broadcasts like BOOT_COMPLETED would never get triggered after power-cycle.
     
  4. rashmiks

    rashmiks New Member

    Joined:
    Dec 12, 2010
    Messages:
    1
    Likes Received:
    0
    Hi,
    I am trying to disable the application by using following code in android

    PackageManager pm = this.getPackageManager();
    pm.setComponentEnabledSetting(new ComponentName("com.sas.remotesample",".Player"),
    PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

    and with permission in Androimanifest.xml is
    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>

    But it is giving me the exception

    java.lang.SecurityException: Permission Denial: attempt to change component state

    Please give me the solution
     

Share This Page

Loading...