[Q] "pm disable" - Where's it store the list?

Aou

Senior Member
Aug 4, 2008
794
777
0
Arizona
I know of three ways to disable/freeze unwanted apps:
  1. Using the command pm disable PACKAGE_OR_COMPONENT
  2. Titanium Backup Pro
  3. Disable the app through the built-in Application Manager (does not work for all apps)

Here's some details I could find about pm disable: http://www.kpbird.com/2013/05/android-shell-command-pm-package-manager.html

But my question to the community: When an app is disabled/frozen by any of these methods, what keeps track of these? Where is this data stored?

If nobody can answer my question above, then I have a different question: Are there any apps/commands that would allow you to view/log filesystem changes on-the-fly? (goal with this: start this "watcher" app, then disable an app using pm, and figure out what changed).

Thanks!
 

Aou

Senior Member
Aug 4, 2008
794
777
0
Arizona
I found it! After quite some time grepping around, I found that the list of enabled/disabled apps is located here:
/data/system/users/0/package-restrictions.xml

Now, all I need to do is find a way to update this file in bash, without relying on any external programs. I plan to make a flashable zip to run a simple script that searches for each of the following three lines:
Code:
<pkg name="com.wssyncmldm" enabled="1" />
<pkg name="com.LocalFota" enabled="1" />
<pkg name="com.sec.android.fwupgrade" enabled="1" />
And updates each to a "2".

If any of the three lines are not found, the script should add them near the end of the file, on new lines immediately before this one:
Code:
<preferred-activities />
One more thing: it's possible that a person might have multiple user accounts on their phone (seems rare...), there could be other package-restrictions.xml files in other directories (maybe a /data/system/users/1/ or example). It would be ideal if the script could search for other user accounts and make the same modifications.

Any scripting-heroes willing to make this up for me?? :D


BTW: the point/purpose of this is to disable the OTA updates from a flashable zip, in a custom recovery, without requiring a rooted system.
 
  • Like
Reactions: danarama
J

jetlitheone

Guest
I found it! After quite some time grepping around, I found that the list of enabled/disabled apps is located here:
/data/system/users/0/package-restrictions.xml

Now, all I need to do is find a way to update this file in bash, without relying on any external programs. I plan to make a flashable zip to run a simple script that searches for each of the following three lines:
Code:
<pkg name="com.wssyncmldm" enabled="1" />
<pkg name="com.LocalFota" enabled="1" />
<pkg name="com.sec.android.fwupgrade" enabled="1" />
And updates each to a "2".

If any of the three lines are not found, the script should add them near the end of the file, on new lines immediately before this one:
Code:
<preferred-activities />
One more thing: it's possible that a person might have multiple user accounts on their phone (seems rare...), there could be other package-restrictions.xml files in other directories (maybe a /data/system/users/1/ or example). It would be ideal if the script could search for other user accounts and make the same modifications.

Any scripting-heroes willing to make this up for me?? :D


BTW: the point/purpose of this is to disable the OTA updates from a flashable zip, in a custom recovery, without requiring a rooted system.
I could probably make a flashable zip that replaces package-restrictions.xml with a modified version that disables OTA

do you have that file?


the bash script looking for and replacing lines is not possible AFAIK via recovery.
 
Last edited:

Aou

Senior Member
Aug 4, 2008
794
777
0
Arizona
I could probably make a flashable zip that replaces package-restrictions.xml with a modified version that disables OTA

do you have that file?


the bash script looking for and replacing lines is not possible AFAIK via recovery.
Well, I've done this sort of thing in MS-DOS batch, using For loops (reading the file, line-by-line and processing it). I'll have to look into the bash equivalent.

Also, simply replacing the file is far too dangerous. If any entries in that file mismatch what's installed on the system, the device will not boot properly (TouchWiz launcher will not load, for one). Every time you enable/disable an app, the entire file shifts around and changes. It's a nightmare. But dealing with it line-by-line would be feasible...
 
J

jetlitheone

Guest
Well, I've done this sort of thing in MS-DOS batch, using For loops (reading the file, line-by-line and processing it). I'll have to look into the bash equivalent.

Also, simply replacing the file is far too dangerous. If any entries in that file mismatch what's installed on the system, the device will not boot properly (TouchWiz launcher will not load, for one). Every time you enable/disable an app, the entire file shifts around and changes. It's a nightmare. But dealing with it line-by-line would be feasible...
Yeah I know what you mean I don't know it might be possible. Only thing I know of is applications that run bash scripts on boot up. But not of running one via a flashable zip in recovery

Sent from my SGH-I337 using Tapatalk 4 Beta
 

Aou

Senior Member
Aug 4, 2008
794
777
0
Arizona
Based on some of the flashable zips out there, I think it's possible to use busybox to execute a bash script. I came up with a little bit of crappy psuedocode for what needs to happen:
Code:
set foundFlag = 0
if (file exists: /system/app/<app>.apk) do:
	for (each line of package-restrictions.xml) do:
		if ( line = <pkg name="com.wssyncmldm" enabled="1" /> ) do:
			echo <pkg name="com.wssyncmldm" enabled="2" />  into newfile
			set foundFlag = 1
		else do:
			echo line into newfile
		end if
	end for
	if (foundFlag != 1) do:
		for (each line of package-restrictions.xml) do:
			if ( line = <preferred-activities /> ) do:
				echo <pkg name="com.wssyncmldm" enabled="2" />  into newfile
				echo <preferred-activities />  into newfile
			else do:
				echo line into newfile
			end if
		end for
	end if
	move newfile -> package-restrictions.xml
end if
The above would need to be repeated 3 times for the 3 apk's that need to be disabled.
 

lebigmac

Senior Member
Jan 31, 2017
267
29
28
Hi. I edited this package-restrictions.xml file as root but every time I reboot the phone, the file resets itself to default values. Why is this happening? Thanks.