-2

I am trying to create a system for performing over-the-air updates for APK and OS on my android devices. My question pertains to the part of actually performing the upgrade once the packages for OS and APK have been downloaded. Please note the following:

  1. I cannot use play-store/play-services since my device does not have play-services installed on it.
  2. I need the update process for both APK and OS to be done silently without any user intervention.
  3. I have root/admin privileges on the devices.
  4. The android versions I will be using are Kitkat, Lollipop and Marshmallow.
  5. I have an APK running on the device which checks for updates from my server and downloads it. I then want it to initiate update for both APK and OS from the code.

Regarding APK update:

I have actually tried and successfully performed APK update by running the shell command pm install -r $PATH_TO_DOWNLOADED_APK, after getting the shell from Runtime.getRuntime().exec("su") in my App code.

My Questions are:

  1. In case something goes wrong while installing the APK- for example if the device shuts down while update is happening , or there was some issue in the APK package or something like that - in this case will android ensure that the APP is rolled back to the previous version correctly and no data is lost or there is something I need to take care of in my code.

Regarding OS update:

I referred to the following link: https://source.android.com/devices/tech/ota/ However, I didn't understand it completely.

My questions are:

  1. Is there a particular folder where I need to keep the downloaded OS package? If yes, then which is the folder? If no then how do I specify the path to it?
  2. What is the equivalent command for pm install -r $PATH_TO_APK in case of OS updates?
  3. How do I boot a device in "recovery mode" as mentioned in point # 3, in the link?
  4. Where are the boot and recovery partitions in the device? Does it vary from device to device? In one of the devices which I have with me, I don't see any /boot or /recovery folder? Does boot mean the / (root) folder?
  5. In case the OS update fails due to some reason( the device shuts down during the update, there was issue in the update package etc)- does android ensure proper rollback and that the device is in a consistent state and no data is lost? If no then how should the code which initiates it handle this?

closed as off-topic by beeshyams, Akhil, Andy Yan, Matthew Read Aug 4 '17 at 13:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about writing and publishing Android apps, writing custom ROMs, and other topics that are primarily of concern to developers are off-topic. Consider taking advantage of other resources that may be appropriate for your question." – Matthew Read
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Hi! There are few things we can help with here, but we do not take programming/development oriented questions. See help center for more info. – Firelord Aug 4 '17 at 6:18
1

Is there a particular folder where I need to keep the downloaded OS package? If yes, then which is the folder? If no then how do I specify the path to it?

Android keeps the downloaded package in cache partition, since data partition is supposedly encrypted nowadays which cannot be mounted by Android in recovery mode without supplying decryption key and there is no other partition big enough to store bigger files. Use root access to move the file into /cache. You may have to set appropriate permission on it as well.

What is the equivalent command for pm install -r $PATH_TO_APK in case of OS updates?

The OS update occurs in recovery mode (a barebone OS) and the recovery may have a provision to allow automatic execution of commands. Android stock recovery (<3e>) reads /cache/recovery/command and executes them automatically. If it is TWRP v2.1 or above, the file is /cache/recovery/openrecoveryscript. Check their links to know more.

How do I boot a device in "recovery mode" as mentioned in point # 3, in the link?

My answer here has it covered.

Where are the boot and recovery partitions in the device? Does it vary from device to device? In one of the devices which I have with me, I don't see any /boot or /recovery folder? Does boot mean the / (root) folder?

They vary from device to device but you can find the cache partition mounted at /cache. Boot partition need not be mounted since all of its content is automatically loaded into memory during boot. You would have to search internet to find partition scheme for your particular device. Izzy's Q&A could help too.

No, boot doesn't mean / folder. It is not even a directory in reality but the root of the largest tree (file hierarchy) created and populated each time the Android boots.

In case the OS update fails due to some reason( the device shuts down during the update, there was issue in the update package etc)- does android ensure proper rollback and that the device is in a consistent state and no data is lost?

No, if recovery starts modifying the system partition and is interrupted, there is no going back. Even if the process completes normally, the boot process may get into trouble.

Finally, OS update/upgrade cannot be called silent at all since there is so much happening on the screen.

  • Things may have changed since Android Nougat. – Firelord Sep 21 '17 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.