I have a custom hardware and I also have access to the signing keys. I have created a system app by signing the app with the platform-key and adding android:sharedUserId="android.uid.system" in the manifest file. One of the features of this system app is to use it to rescue install a device-owner app. This custom hardware also includes a device-owner, but the rescue install is to be used in case something bad goes with the device-owner.
In android 11, after testing a bunch of things, I found that, to use pm install ... command, the apk file has to be located inside /data/local/tmp. So, my questions are as follows:
- How to copy a file to
/data/local/tmpfrom the system-app. - How to install that specific apk using
pm installby using the system-app.
What I have tried is that first download the apk to something like /sdcard/Downloads. Then, I have the following code:
val apkPath: File = .... // file inside the Downloads folder
val tmpFile = File("/data/local/tmp", apkPath.name)
apkPath.copyTo(tmpFile, true) // this fails
The last line fails by throwing the error:
05-24 15:42:19.461 24772 24772 E AndroidRuntime: java.io.FileNotFoundException: /data/local/tmp/myapp.apk: open failed: EACCES (Permission denied)
Furthermore, if the myapp.apk file is already present in the /data/local/tmp folder then, when executing pm install ... i get the following error:
05-24 15:44:23.603 25073 25073 E AndroidRuntime: com.***.***: Error: Unable to open file: /data/local/tmp/maypp.apk
05-24 15:44:23.603 25073 25073 E AndroidRuntime: Error: Can't open file: /data/local/tmp/myapp.apk
05-24 15:44:23.603 25073 25073 E AndroidRuntime:
05-24 15:44:23.603 25073 25073 E AndroidRuntime: Exception occurred while executing 'install':
05-24 15:44:23.603 25073 25073 E AndroidRuntime: java.lang.IllegalArgumentException: Error: Can't open file: /data/local/tmp/myapp.apk