Gregor
Gregor

Reputation: 91

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 (e.g. 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.

Upvotes: 2

Views: 462

Answers (2)

user3394003
user3394003

Reputation: 139

You may need to define a query for Android 11 (API level 30)

<manifest package="com.example.app">
  <queries>
    <!-- Specific apps you interact with, eg: -->
    <package android:name="com.example.service" />
  </queries>
  ...
</manifest>

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007296

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.

Upvotes: 2

Related Questions