简体   繁体   中英

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.

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 .

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. This was never a great idea, is deprecated, and is likely to go away soon.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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