推荐使用 极客导航125啦极客导航(http://www.biumall.com/jike.html)

最近被第三方软坑了一下,断电后软件又回去了,一直说是我这边的问题。

好了,最后看到网上大牛也分析过,因此摘抄于此,记录一下。

如果更新或者升级后系统内置应用,遇到重启Android系统后内置应用被还原,那是因为手动安装的APK版本号和系统内置API版本号一样。

1、Android系统应用更新机制
系统为每个应用在AndroidMainfest.xml提供了versionName、versionCode两个属性。
versionName:String类型,用来给应用的使用者来查看版本.
versionCode:Integer类型,作为系统判断应用是否能升级的依据。

2、Android系统内置应用更新判断代码

代码来自frameworks/base/services/java/com/android/server/PackageManagerService.java 中 scanPackageLI函数的package更新判断条件(约第2580-2621行附近)

PS:直接收红色字体就到了

// First check if this is a system package that may involve an update
if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
    if (!ps.codePath.equals(scanFile)) {
      // The path has changed from what was last scanned...  check the
      // version of the new path against what we have stored to determine
      // what to do.
      if (pkg.mVersionCode < ps.versionCode) {
          // The system package has been updated and the code path does not match
          // Ignore entry. Skip it.

修改如下,只要把“<”改为“<=”即可

 if (pkg.mVersionCode <= ps.versionCode) {

还没看懂的可以参考其他大神的《Android系统内置应用更新或升级后被还原的原因》和《Android重启后已升级的内置应用被还原

相关文章

暂无评论

none
暂无评论...