简体   繁体   English

Android:从另一个具有相同签名的应用程序访问内部存储

[英]Android: access internal storage from another app with same signature

Context: I have two apps, both signed with the same signature.上下文:我有两个应用程序,都使用相同的签名进行签名。 The first app has data stored in internal storage that I would like to migrate to the second app.第一个应用程序的数据存储在内部存储中,我想迁移到第二个应用程序。

Question: How can I access the data in the first app from the second app?问题:如何从第二个应用程序访问第一个应用程序中的数据? The Android documentation makes reference to "signature permissions" ( https://developer.android.com/guide/topics/permissions/overview#signature and https://developer.android.com/training/articles/security-tips#StoringData ) and hints that it is possible to share data between apps with the same signature, but I cannot find clear guidelines about how to do this. The Android documentation makes reference to "signature permissions" ( https://developer.android.com/guide/topics/permissions/overview#signature and https://developer.android.com/training/articles/security-tips#StoringData ) 并暗示可以在具有相同签名的应用程序之间共享数据,但我找不到有关如何执行此操作的明确指南。

It seems like it might be possible by creating a content provider?似乎可以通过创建内容提供者来实现? Or is it possible to directly access the files, since I understand from the docs that they will be running with the same user / same process?或者是否可以直接访问这些文件,因为我从文档中了解到它们将使用相同的用户/相同的进程运行?

Ideally this process can happen with minimal intervention from the user, and can all happen from the second app (eg the second app can recognize that the first app is installed, prompt the user to migrate, and then read the data from the first app and move it to the second).理想情况下,这个过程可以在用户干预最少的情况下发生,并且都可以从第二个应用程序发生(例如,第二个应用程序可以识别第一个应用程序已安装,提示用户迁移,然后从第一个应用程序读取数据并将其移至第二个)。 It would be even better if it was possible to move the files (rather than copy) because we potentially have a lot of data and the user may not have enough disk space to copy the data.如果可以移动文件(而不是复制)会更好,因为我们可能有很多数据,而用户可能没有足够的磁盘空间来复制数据。

It seems like it might be possible by creating a content provider?似乎可以通过创建内容提供者来实现?

Yes.是的。 You can create a signature-level permission and use that to protect access to any of the standard IPC options in Android, including ContentProvider and Service .您可以创建签名级权限并使用它来保护对 Android 中任何标准 IPC 选项的访问,包括ContentProviderService

Or is it possible to directly access the files, since I understand from the docs that they will be running with the same user / same process?或者是否可以直接访问这些文件,因为我从文档中了解到它们将使用相同的用户/相同的进程运行?

No, two apps signed by the same signing key to not run as the same user, let alone in the same process.不,由相同签名密钥签名的两个应用程序不会以同一用户身份运行,更不用说在同一进程中运行了。 android:sharedUserId has the apps run as the same user. android:sharedUserId让应用程序以同一用户身份运行。 This was never a great idea, is deprecated, and is likely to go away soon.这从来都不是一个好主意,已被弃用,并且很可能很快就会被 go 淘汰。

It would be even better if it was possible to move the files (rather than copy) because we potentially have a lot of data and the user may not have enough disk space to copy the data.如果可以移动文件(而不是复制)会更好,因为我们可能有很多数据,而用户可能没有足够的磁盘空间来复制数据。

That suggests that having two apps is a bug, not a feature, from the standpoint of the user.这表明从用户的角度来看,拥有两个应用程序是一个错误,而不是一个功能。 The closest you will be able to do to a "move" operation is "delete-after-copy", so plan your copies to be as granular as possible so you can delete as you go.您可以执行的最接近“移动”操作的是“复制后删除”,因此计划您的副本尽可能细化,以便您可以像 go 一样删除。

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

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