Android 5.0/Lollipop: Force rescan of /system/priv-app

匿名 (未验证) 提交于 2019-12-03 02:48:02

问题:

In Android 4.x, it was enough to put an APK-file into /system/priv-app, and the package-manager recognized that new file and (un-)installed the corresponding application or service.

Since Android L, it seems to be not enough to just put the file into that directory - a reboot of the system is required to force Android to recognize that change.

Has anyone an idea how to circumvent this? Maybe with any setprop ctl.restart xxx or by killing a dedicated service?

EDIT:

Here are some logs from logcat:

1. Move APK from /system to /system/priv-app (=installation)

su mount -o remount rw /system cd /system/priv-app mv ../AARSCService.apk . // move from /system to /system/priv-app  W/mv      ( 3268): type=1400 audit(0.0:53): avc: denied { rename } for name="AARSCService.apk" dev="mmcblk0p22" ino=23041 scontext=u:r:init:s0 tcontext=u:object_r:system_file:s0 tclass=file 

(but file HAS been moved as the current root-implementation for Nexus 7 Android Android L P2 disables SELinux for the root-commands!)

-> APK NOT loaded and not listed in app-list -> NOT as expected, APK is going to be automatically installed once put into priv-app folder on Android 4.4.

2. Reboot device, having APK inside /system/priv-app

reboot  I/PackageManager(  567): /system/priv-app/AARSCService.apk changed; collecting certs 

-> APK IS loaded and listed in app-list -> as expected

3. Move APK from /system/priv-app to /system (=deinstallation)

su mount -o remount rw /system cd /system/priv-app mv AARSCService.apk .. // move from /system/priv-app to /system  W/mv      ( 3189): type=1400 audit(0.0:31): avc: denied { rename } for name="AARSCService.apk" dev="mmcblk0p22" ino=23041 scontext=u:r:init:s0 tcontext=u:object_r:system_file:s0 tclass=file 

(but file HAS been moved as the current root-implementation for Nexus 7 Android Android L P2 disables SELinux for the root-commands!)

-> APK still loaded and listed inside app-list, service inside app can still be bound from another app -> NOT as expected, APK is going to be automatically uninstalled once removed from priv-app folder on Android 4.4.

4. Reboot device, having APK NOT inside /system/priv-app

reboot   W/PackageManager(  570): System package eu.airaudio.aarscservice no longer exists; wiping its data 

-> APK is no more loaded and no more listed in app-list -> as expected

EDIT 2:

There's the same behaviour on unrooted Android L (21) emulator - sure, without the SELinux-warning. But the APK is also just (un-)installed after reboot (=kill zygote).

回答1:

Comparing the source code of PackageManagerService between KitKat and Lollipop you can see significant changes, and some that are obviously related to this change.

PackageManagerService.java on Lollipop

PackageManagerService.java on KitKat

The most significant change to the question topic is the removal of all references to AppDirObserver (a nested class of PackageManagerService) that was initialized to monitor all directories (the attached image shows a comparison of the relevant code where it was used. Right side shows KitKat code and left side shows Lollipop)

Still haven't found a solution for this but might help someone figure it out.



回答2:

Based on your logcat messages, looks like the PackageManagerService is not even seeing the folder/file changes.

Here is one way to circumvent/trigger a rescan, simulate a a "boot completed" event with broadcast action:

    adb shell am broadcast -a android.intent.action.BOOT_COMPLETED 

This should trigger a rescan by the PackageManagerService



回答3:

pms will scan /system/app(priv-app) at start. so just kill process systemserver :) it work at my lollipop emulator. just take a little while to showing "upgrade android, opt app..."



回答4:

  1. Push apk to /system/priv-app/
  2. Run command: adb shell > su > am restart (using this command you don't loose adb connection)
  3. Wait for system boots - install script can wait for clean output of command: "adb shell dumpsys phone"

Snippet:

def am_restart(self):     """Restarts am waits for complete Android boot."""      self._log.info('Restarting application manager!')      ret, out, err = self.shell('am restart', require_root=True)     if ret != 0:         self.log_failure('am restart', ret, out, err)         return False      on_main_screen = False     while not on_main_screen:         sleep(2)         ret, out, err = self.shell('dumpsys phone')         if ret != 0:             self.log_failure('dumpsys phone', ret, out, err)             return False         if not (out or err):             on_main_screen = True             self._log.info('Application manager successfully restarted!')      return True 


回答5:

I had the exact same problem. Turns out when I coped the package back to priv-app it was copied with different permission

Permissions of all packages in priv-app (and app) :

rwx-r-x-r-x 

Permission of the package I copied back :

rwx-------- 

A simple chmod -R a+rw <path/to/package> solved the problem

EDIT: Make sure your /system/ is not readonly by issuing mount -o remount,rw /system/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!