microsoft / appcenter-sdk-android

Development repository for the App Center SDK for Android
Other
277 stars 134 forks source link

Installing app through in-app update do an IO in main thread (ANR) #1612

Closed TedaLIEz closed 2 years ago

TedaLIEz commented 2 years ago

Description

User will be stuck at in-app update after he/her downloads the update and install.

image

Repro Steps

Please list the steps used to reproduce your issue.

  1. Install apk from appcenter distribution, finish the appcenter login to enable in-app update
  2. release a new build and open the app
  3. there is a dialog notifying the update, download the update
  4. install the new build

Details

  1. Which SDK version are you using?

    • 4.4.3
  2. Which OS version did you experience the issue on?

    • Android 10
    • Android 11
  3. What device version did you see this error on? Were you using an emulator or a physical device?

    • Google Pixel XL, Surface Duo
  4. Please enable verbose logging for your app using AppCenter.setLogLevel(Log.VERBOSE) before your call to AppCenter.start(...) and include the logs here:

    2022-03-29 03:48:52.36 [31901][5643] AppCenter: Network 113 is lost.
    2022-03-29 03:48:52.38 [31901][5643] AppCenter: Network has been disconnected.
    2022-03-29 03:48:53.98 [31901][5643] AppCenter: Network 114 is available.
    2022-03-29 03:48:53.98 [31901][5643] AppCenter: Network has been connected.
    2022-03-29 10:06:33.60 [31901][2] AppCenterDistribute: Resetting workflow on entering foreground.
    2022-03-29 10:06:33.64 [31901][5630] AppCenterDistribute: A check for update is already ongoing.
    2022-03-29 10:06:33.84 [31901][2] AppCenterDistribute: Resume distribute workflow...
    2022-03-29 10:06:33.84 [31901][2] AppCenterDistribute: Calling listener.onReleaseAvailable.
    2022-03-29 10:06:33.84 [31901][2] AppCenterDistribute: Show default update dialog.
    2022-03-29 10:06:33.85 [31901][2] AppCenterDistribute: Already checking or checked latest release.
    2022-03-29 10:06:34.08 [31901][2] AppCenterDistribute: Resume distribute workflow...
    2022-03-29 10:06:34.08 [31901][2] AppCenterDistribute: Calling listener.onReleaseAvailable.
    2022-03-29 10:06:34.08 [31901][2] AppCenterDistribute: Show default update dialog.
    2022-03-29 10:06:34.10 [31901][2] AppCenterDistribute: Already checking or checked latest release.
    2022-03-29 10:06:38.98 [31901][2] AppCenterDistribute: Resume distribute workflow...
    2022-03-29 10:06:38.98 [31901][2] AppCenterDistribute: Calling listener.onReleaseAvailable.
    2022-03-29 10:06:38.98 [31901][2] AppCenterDistribute: Show default update dialog.
    2022-03-29 10:06:39.00 [31901][2] AppCenterDistribute: Already checking or checked latest release.
    2022-03-29 10:07:10.10 [31901][2] AppCenterDistribute: Resetting workflow on entering foreground.
    2022-03-29 10:07:10.10 [31901][2] AppCenterDistribute: Resume distribute workflow...
    2022-03-29 10:07:10.10 [31901][2] AppCenterDistribute: Calling listener.onReleaseAvailable.
    2022-03-29 10:07:10.10 [31901][2] AppCenterDistribute: Previous dialog is still being shown in the same activity.
    2022-03-29 10:07:10.10 [31901][2] AppCenterDistribute: Already checking or checked latest release.
    2022-03-29 10:07:11.04 [31901][2] AppCenterDistribute: Schedule download...
    2022-03-29 10:07:11.05 [31901][6748] AppCenterDistribute: Start downloading new release from <apk url>
    2022-03-29 10:07:36.09 [31901][6748] AppCenterDistribute: Check download id=829
    2022-03-29 10:07:36.10 [31901][6753] AppCenterDistribute: Download was successful for id=829
    2022-03-29 10:07:36.11 [31901][2] AppCenterDistribute: Post a notification as the download finished in background.
    2022-03-29 10:07:53.05 [31901][6753] AppCenterDistribute: Download was successful for id=829
    2022-03-29 10:07:53.07 [31901][2] AppCenterDistribute: Release is downloaded. Starting to install it.
    2022-03-29 10:07:53.07 [31901][2] AppCenterDistribute: Delete notification
    2022-03-29 10:07:53.07 [31901][2] AppCenterDistribute: Hide the install progress dialog.
    2022-03-29 10:07:53.07 [31901][2] AppCenterDistribute: Stored release details: group id=53c422e7-0582-443a-8c9c-944c78072889 release hash=54d590c4bca369697989e09324bef6ff617169aa29a40682afffbb70d59db80e release id=2017
    2022-03-29 10:07:53.07 [31901][2] AppCenter: Start installing new release...

I think there is a code defect in InstallerUtils https://github.com/microsoft/appcenter-sdk-android/blob/4.4.3/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/InstallerUtils.java#L151 that trying to do an IO in main thread. This may cause an ANR in application.

We got a similar report about this ANR:

libcore.io.Linux.readBytes Linux.java
libcore.io.Linux.read Linux.java:190
libcore.io.ForwardingOs.read ForwardingOs.java:177
libcore.io.BlockGuardOs.read BlockGuardOs.java:303
libcore.io.ForwardingOs.read ForwardingOs.java:177
libcore.io.IoBridge.read IoBridge.java:513
android.os.FileBridge$FileBridgeOutputStream.writeCommandAndBlock FileBridge.java:170
android.os.FileBridge$FileBridgeOutputStream.fsync FileBridge.java:162
android.content.pm.PackageInstaller$Session.fsync PackageInstaller.java:978
com.microsoft.appcenter.distribute.InstallerUtils.installPackage InstallerUtils.java:173
com.microsoft.appcenter.distribute.ReleaseInstallerListener.startInstall ReleaseInstallerListener.java:101
com.microsoft.appcenter.distribute.Distribute.installUpdate Distribute.java:1940
com.microsoft.appcenter.distribute.Distribute.showSystemSettingsDialogOrStartInstalling Distribute.java:1959
com.microsoft.appcenter.distribute.ReleaseDownloadListener$3.run ReleaseDownloadListener.java:103
android.os.Handler.handleCallback Handler.java:883
android.os.Handler.dispatchMessage Handler.java:100
android.os.Looper.loop Looper.java:214
android.app.ActivityThread.main ActivityThread.java:7356
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:492
com.android.internal.os.ZygoteInit.main ZygoteInit.java:930
TedaLIEz commented 2 years ago

Btw this should be a bug, should not be tagged as support but somehow the issue is assigned with a support tag

AnatolyPristensky commented 2 years ago

Hello @TedaLIEz, We filed an item on our internal dashboard to check this case, we will update this conversation once got results.

DmitriyKirakosyan commented 2 years ago

The fix has been released! I'm closing the issue, but feel free to reopen if you face it again.