ISNIT0 / zipternet

1 stars 0 forks source link

Handle insufficient space on device elegantly #10

Open julianharty opened 5 years ago

julianharty commented 5 years ago

When testing on a mid-range Android device (a Samsung Galaxy J2 Prime) which had only around 46MB available on internal storage, the app starts and then crashes almost immediately and before any splash screen appears.

It would be great if we can handle the problem in the app rather than leaving Android runtime to cope with the crash.

Note: I installed the app locally using gradle commands, I don't know whether the app store would allow the app to be installed with low free space so this may only be an issue in rare circumstances e.g. if a user deletes an OBB file somehow, then starts our app while there's not enough space for the OBB file to be reinstalled.

From the device's log we can see the following error and crash.

07-16 18:04:37.554   701   783 D StatusBarManagerService: manageDisableList userId=0 what=0x0 pkg=Window{e18725e u0 d0 p8725 app.zimternet.traveleurope/app.zimternet.traveleurope.MainActivity}
07-16 18:04:37.564   701  1483 D VoldConnector: SND -> {9 volume mkdirs /storage/emulated/0/Android/obb/app.zimternet.traveleurope/}
07-16 18:04:37.564   216   291 D VoldCmdListener: volume mkdirs /storage/emulated/0/Android/obb/app.zimternet.traveleurope/
07-16 18:04:37.564   216   291 D VoldCmdListener: CommandListener::runCommand() cmd:mkdirs
07-16 18:04:37.564   216   291 D epmd    : Added EPM Instance (PID:216)
07-16 18:04:37.574   216   291 D epmd    : Terminated seperator: 1
07-16 18:04:37.574   232   232 D GraphicBuffer: free, handle(0xb58a0b40) (w:507 h:930 s:512 f:0x1 u:0x000b00)
07-16 18:04:37.574   232   232 I [MALI][Gralloc]: [-]hnd(0xb58a0b40), client(30), share_fd(50)
07-16 18:04:37.574   232   232 I BufferQueueProducer: [FrameBufferSurface_0](this:0xb3216000,id:0,api:1,p:232,c:232) queueBuffer: fps=11.96 dur=1505.31 max=1020.56 min=14.35
07-16 18:04:37.574   216   291 E cutils  : Failed to mkdirat(/storage/emulated/0/Android/obb/app.zimternet.traveleurope): No space left on device
07-16 18:04:37.574  8725  8725 W ContextImpl: Failed to ensure /storage/emulated/0/Android/obb/app.zimternet.traveleurope: 400
07-16 18:04:37.574  8725  8725 D AndroidRuntime: Shutting down VM
07-16 18:04:37.574   216   291 D SocketClient: SocketClient sendData done: 400 9 Command failed
07-16 18:04:37.574   701  1033 D VoldConnector: RCV <- {400 9 Command failed}
07-16 18:04:37.614  8725  8725 E AndroidRuntime: FATAL EXCEPTION: main
07-16 18:04:37.614  8725  8725 E AndroidRuntime: Process: app.zimternet.traveleurope, PID: 8725
07-16 18:04:37.614  8725  8725 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {app.zimternet.traveleurope/app.zimternet.traveleurope.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File[] java.io.File.listFiles()' on a null object reference
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread.deliverResults(ActivityThread.java:5004)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread.handleSendResult(ActivityThread.java:5047)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread.access$1600(ActivityThread.java:229)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7406)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
07-16 18:04:37.614  8725  8725 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File[] java.io.File.listFiles()' on a null object reference
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at app.zimternet.traveleurope.MainActivity.loadContent(MainActivity.kt:146)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at app.zimternet.traveleurope.MainActivity.onRequestPermissionsResult(MainActivity.kt:118)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7291)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.Activity.dispatchActivityResult(Activity.java:7169)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    at android.app.ActivityThread.deliverResults(ActivityThread.java:5000)
07-16 18:04:37.614  8725  8725 E AndroidRuntime:    ... 9 more
07-16 18:04:37.624   701  3992 D InputDispatcher: Focused application set to: xxxx
07-16 18:04:37.624   701  3992 W ActivityManager:   Force finishing activity app.zimternet.traveleurope/.MainActivity
julianharty commented 5 years ago

An update: after freeing up over 1GB (plenty for this app's content (roughly 300MB) to fit on the device with space to spare) and restarting the app, it still crashes, this time with the following stack trace:

07-16 18:13:37.134  9695  9695 D ZIMT    : Using obbDir [/storage/emulated/0/Android/obb/app.zimternet.traveleurope]
07-16 18:13:37.134  9695  9695 D AndroidRuntime: Shutting down VM
07-16 18:13:37.164  9695  9695 E AndroidRuntime: FATAL EXCEPTION: main
07-16 18:13:37.164  9695  9695 E AndroidRuntime: Process: app.zimternet.traveleurope, PID: 9695
07-16 18:13:37.164  9695  9695 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{app.zimternet.traveleurope/app.zimternet.traveleurope.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread.access$1100(ActivityThread.java:229)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7406)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
07-16 18:13:37.164  9695  9695 E AndroidRuntime: Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at app.zimternet.traveleurope.MainActivity.loadContent(MainActivity.kt:152)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at app.zimternet.traveleurope.MainActivity.onCreate(MainActivity.kt:61)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:6904)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
07-16 18:13:37.164  9695  9695 E AndroidRuntime:    ... 9 more
07-16 18:13:37.164   701  3991 W ActivityManager:   Force finishing activity app.zimternet.traveleurope/.MainActivity
07-16 18:13:37.174   701  3991 D InputDispatcher: Focused application set to: xxxx
julianharty commented 5 years ago

Here's a link to the Google Guide for working with expansion files in the app https://developer.android.com/google/play/expansion-files which may provide a useful template for implementing support in the app to download the file(s) when needed.