How to disable/enable apps with ADB in Android

This article will introduce how to disable or enable an app with the adb command in Android.

1. Disable an app: adb shell pm disable --user USER_ID PACKAGE

The following command will change the package com.google.android.youtube to disabled state.

$ adb shell pm disable-user --user 0 com.google.android.youtube
Success

You can check whether the status has been changed to disabled with the following command. enabled=3 means disabled from the logs.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    codePath=/product/app/YouTube
    flags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP KILL_AFTER_RESTORE RESTORE_ANY_VERSION LARGE_HEAP ]
    ....
    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=3 instant=false virtual=false

User 0 means a user of the system(Owner), and when multi-users are created, other user spaces are created like User 10 and User 11.

2. Enable an app: adb shell pm enable --user USER_ID PACKAGE

The following command changes the com.google.android.youtube package to the enabled state.

$ adb shell pm enable --user 0 com.google.android.youtube
Package com.google.android.youtube new state: enabled

You can check whether the status has changed to enabled with the following command. enabled=1 means enabled from the logs.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    codePath=/product/app/YouTube
    flags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP KILL_AFTER_RESTORE RESTORE_ANY_VERSION LARGE_HEAP ]
    ....
    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=1 instant=false virtual=false

3. Change the app to the default state

The following command changes the App to the default state.

The default state means that it will be enabled or disabled based on the enabled attribute value in the App's AndroidManifest.xml

Normally, since Application is not set to android:enabled=false in App, it will mostly be enabled with default state.

$ adb shell pm default-state --user 0 com.google.android.youtube
Package com.google.android.youtube new state: default

You can check whether it has changed to the default state with the following command. enabled=0 means enabled from the logs.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    codePath=/product/app/YouTube
    flags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP KILL_AFTER_RESTORE RESTORE_ANY_VERSION LARGE_HEAP ]
    ....
    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=0 instant=false virtual=false

4. Component's enabled/disabled/default states

You can change the app's component(Activity, Service, Provider, and Receiver) state to disabled, enabled, or default state. You can do this with previous command set, but you need to pass component name instead of package name.

You can change the state of a component like this:

$ adb shell pm disable-user --user 0 com.google.android.youtube/com.google.android.youtube.MainActivity

$ adb shell pm enable --user 0 com.google.android.youtube/com.google.android.youtube.MainActivity

$ adb shell pm default-state --user 0 com.google.android.youtube/com.google.android.youtube.MainActivity

When checking whether the state of a component has been changed, you can check enabledComponents and disabledComponents in the package information as follows.

Included in this list means enable or disable status. If it is not included in this list, it means the default state.

$ adb shell dumpsys package com.google.android.youtube

Packages:
  Package [com.google.android.youtube] (3d1fcc2):
    userId=10121
    pkg=Package{b77ead3 com.google.android.youtube}
    ....

    User 0: ceDataInode=122910 installed=true hidden=false suspended=false distractionFlags=0 stopped=false notLaunched=false enabled=0 instant=false virtual=false
      gids=[3003]
      runtime permissions:
        android.permission.ACCESS_FINE_LOCATION: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
      enabledComponents:
        com.google.android.youtube.ManageNetworkUsageActivity
      disabledComponents:
        androidx.work.impl.background.systemalarm.RescheduleReceiver

Related Posts

codechachaCopyright ©2019 codechacha