Home » Android » How can an App freeze Android OS

How can an App freeze Android OS

Posted by: admin June 15, 2020 Leave a comment


I am developing an Android app that is causing the OS to Freeze.

My question is rather simple but after lengthy searches I have come no closer to an answer.

The question is, how can an app which is sandboxed, cause the entire Android OS (4.0.4, 4.1.1, 4.1.2) to freeze?

Specifically, the entire OS freezes. No logcat, no adb, nothing! It is as frozen as an OS can get. The device is a Samsung Galaxy Tab 2. The app uses the UsbManager and the library from the usb-serial-for-android project. While the library may use the NDK, my app does not. Essentially, the app communicates serially with a propriety board, receiving data and sending serial commands. This is done on a worker thread that is disposed of in this manner:

try {

        while(thread.getState() != Thread.State.TERMINATED){
              // wait until thread finishes

} catch (InterruptedException e) {

It all works fine, that is until the freeze occurs – when I disconnect the usb cable or instruct the library object to disconnect. Either way, the entire OS gets unstable and will freeze immediately or upon connecting the usb again (board or computer). I have posted this freeze issue to the usb-serial-for-android project but have not received any comments yet. I believe I am following the proper protocols when disengaging the usb.

I understand many things can go wrong – my app can crash et. al. But again how does a sandboxed app crash the OS – it does not seem to be very sandboxed if it can do that.


I have after much experimentation found that by removing the thread.interrupt(); line that it works without crashing the app or freezing the OS. It still freezes the OS if the USB is unplugged without first dismounting it.

I still desire to understand how a sandboxed app can freeze the entire OS though. There are comments here that elude to an answer, but are not an answer alone.

How to&Answers:

Where is your code sample above located?

It should be be on a UI thread, potentially blocking user interaction.

Are you also getting ANR messages before the freeze?


will block indefinitely. See Thread.join() documentation.

Also, the following looks like a busy loop to me.

What are you doing at the comment? If nothing, then the loop will spin like crazy (think while (true) { }).

    while(thread.getState() != Thread.State.TERMINATED){
          // wait until thread finishes