简体   繁体   English

Android Q:卸载后权限保持状态

[英]Android Q: Permissions maintaining state after uninstall

I am having an app which is targeting android 27 API.我有一个针对 android 27 API 的应用程序。 I am testing this app from playstore on device Android Q which work managed device.我正在设备 Android Q 上从 Playstore 测试此应用程序,该应用程序可运行受管设备。 Steps i followed on device Android Q having build build 6 - Steps i followed on device Android Q having build build 6 -

  1. Installed app and allowed all the permissions(additional permission also which are custom permissions).已安装应用程序并允许所有权限(附加权限也是自定义权限)。
  2. Uninstalled app from device.从设备卸载的应用程序。
  3. Installed again app from playstore and found that app is asking custom permission only instead no permission.从 Playstore 再次安装应用程序,发现该应用程序仅要求自定义权限,而不是没有权限。

Is it the expected behavior?这是预期的行为吗? Anyone know how this is?有谁知道这是怎么回事?

This is something called Auto Backup .这就是所谓的自动备份

Files that are backed up备份的文件

By default, Auto Backup includes files in most of the directories that are assigned to your app by the system:默认情况下,自动备份包含系统分配给您的应用程序的大多数目录中的文件:

  1. Shared preferences files.共享首选项文件。
  2. Files saved to your app's internal storage, accessed by getFilesDir() or getDir(String, int).保存到应用程序内部存储的文件,通过 getFilesDir() 或 getDir(String, int) 访问。
  3. Files in the directory returned by getDatabasePath(String), which also includes files created with the SQLiteOpenHelper class. getDatabasePath(String) 返回的目录中的文件,其中还包括使用 SQLiteOpenHelper 类创建的文件。
  4. Files on external storage in the directory returned by getExternalFilesDir(String). getExternalFilesDir(String) 返回的目录中外部存储上的文件。

Auto Backup excludes files in directories returned by getCacheDir(), getCodeCacheDir(), or getNoBackupFilesDir().自动备份排除 getCacheDir()、getCodeCacheDir() 或 getNoBackupFilesDir() 返回的目录中的文件。 The files saved in these locations are only needed temporarily, or are intentionally excluded from backup operations.保存在这些位置的文件只是暂时需要,或者有意从备份操作中排除。

You can manage it by AndroidManifest.xml .您可以通过AndroidManifest.xml管理它。 See android:allowBackup参见android:allowBackup

<manifest ... >
    ...
    <application android:allowBackup="true" ... >
        ...
    </application>
</manifest>

EDIT编辑

android:fullBackupContent="false"
android:fullBackupOnly="false"

There are 2 more rules available to set.还有 2 条规则可供设置。

EDIT 2编辑 2

I just found more useful information at the android official website.我刚刚在android官方网站上找到了更多有用的信息。 see here这里

Note: Any permissions a user grants to your app are automatically backed up and restored by the system on devices running Android 7.0 (API 24) or newer.注意:运行 Android 7.0 (API 24) 或更高版本的设备上的系统会自动备份和恢复用户授予您的应用程序的任何权限。 However, if a user uninstalls your app, then the system clears any granted permission and the user must grant them again.但是,如果用户卸载您的应用程序,则系统会清除任何授予的权限,用户必须再次授予它们。

My best guess is there should be some difference(like 24hours) until the user settings/permissions will be deleted from the system device/cloud.我最好的猜测是应该有一些差异(比如 24 小时),直到用户设置/权限将从系统设备/云中删除。

Hopes this will answer your query in some way.希望这会以某种方式回答您的查询。

Regarding whether this is an expected behavior in Android Q: This issue does not reproduce on Android Q emulator.关于这是否是 Android Q 中的预期行为:此问题不会在 Android Q 模拟器上重现。 I guess it counts as a baseline.我想它算作基线。

More technical details :更多技术细节

Runtime permissions logic in Android is mostly located in PackageManagerService (mostly book keeping for each package) and ActivityManagerService (mostly request runtime permission logic) Android中的运行时权限逻辑主要位于PackageManagerService (主要是每个包的簿记)和ActivityManagerService (主要是请求运行时权限逻辑)

When package gets deleted, the data cleanup method removePackageDataLIF gets called.当包被删除时,数据清理方法removePackageDataLIF被调用。 It is responsible for cleaning up everything including the app permissions.它负责清理包括应用程序权限在内的所有内容。 This logic hasn't changed Android Q.这个逻辑并没有改变 Android Q。

The permissions info is stored in system data directory, not the application's so the app data backup doesn't affect it either.权限信息存储在系统数据目录中,而不是应用程序的目录中,因此应用程序数据备份也不会影响它。

But the question remains : How could this happen?但问题仍然存在:这怎么会发生?

One of the possible explanations could be the flag PackageManager.DELETE_KEEP_DATA可能的解释之一可能是标志PackageManager.DELETE_KEEP_DATA

You can easily delete package while keeping its data directory after uninstall:您可以在卸载后轻松删除包,同时保留其数据目录:

$ adb shell cmd package uninstall -k your.app.id

(-k is for keep data) (-k 用于保留数据)

Now to check whether the permissions are kept in place along with the data directory:现在检查权限是否与数据目录一起保留:

$ adb root && adb shell cat /data/system/users/0/runtime-permissions.xml | grep your.app.id -A 10

(this command requires a debuggable phone firmware build) (此命令需要可调试的手机固件版本)

Looking at the source of removePackageDataLIF and trying it on my Pixel with debuggable firmware the application permission is kept intact if you kept its data.查看removePackageDataLIF的来源并在我的 Pixel 上尝试使用可调试固件,如果您保留其数据,应用程序权限将保持不变。


Another explanation另一种解释

PackageManagerService has an another interesting method setKeepUninstalledPackages Which basically forces android to keep all the data for specified apps even if they were uninstalled. PackageManagerService有另一个有趣的方法setKeepUninstalledPackages ,它基本上强制 android 保留指定应用程序的所有数据,即使它们被卸载。

As you said the device is work managed.正如你所说,设备是工作管理的。 Usually management is done with DevicePolicyManager .通常管理是通过DevicePolicyManager完成的。 One of the available policies is setKeepUninstalledPackages , which calls the mentioned above PackageManagerService method.可用的策略之一是setKeepUninstalledPackages ,它调用上面提到的PackageManagerService方法。

Please check your Device admin app code to verify.请检查您的设备管理应用程序代码以进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM