DeviceFarmer / adbkit

A pure Node.js client for the Android Debug Bridge.
Other
238 stars 54 forks source link

Install exception handling. Cleanup after install command. #403

Closed DonVietnam closed 1 year ago

DonVietnam commented 1 year ago

When installing an application on an android device, we use a package manager, giving it a command to install an application that is preloaded on the device.

Problem:

In response to the installation command, we expect to receive one of two Success or Failure statuses, in the case when the code "OKAY' is returned. However, there is a situation when the Exception status is returned, for example, if there is not enough memory on the device, in this case adbkit parses the response to the end, does not find a match and throws the error "prematureoferror", which cannot be called correct behavior. Throwing out this error confuses developers, as they think that the error is related to data transmission, while it is not.

This behavior is demonstrated here #366.

Also, when installing applications using the "remoteInstall" method, the temporary apk file was not always deleted, which again can lead to pm errors such as this.

Solution:

Such errors can be easily calculated by the Exception keyword, and processed in the same way as Failure, in fact, this behavior was implemented.

Errors of this kind should also be handled by the developer of the android application, since they occur at the level of the android device and are in no way related to the STF system itself, therefore they should be communicated to the end user, which are Android developers.

To return malicious errors, a status has been added that does not overlap any of the existing package manager statuses: INSTALL_EXCEPTION.

Also, file deletion was added to finally to clean up the garbage after a successful or unsuccessful installation.

All possible error code can be find here: https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/content/pm/PackageManager.java