Search code examples
androidmountapk-expansion-files

OnObbStateChangeListener not called when mounting .obb


We've been successfully using the APK expansion file technology in our app for some time by expanding the .obb file into another directory for reading of the various pieces. We finally decided to try reading directly out of the bob by mounting it using StorageManager. The code we are using seems pretty common on the net.

We make the call:

        if ( storageManager.mountObb( obbFile.getAbsolutePath(), null, obbListener ) )
        {
            Log.d( "STORAGE_MNT", "SUCCESSFULLY QUEUED" );
        }
        else
        {
            Log.d( "STORAGE_MNT", "FAILED" );
        }

and this succeeds as "SUCCESSFULLY QUEUED". However the obbListener is never called afterwards. If you look in the LogCat you do see the following:

Calling a method in the system process without a qualified user: 
android.app.ContextImpl.bindService:1543 
com.android.server.MountService$ObbActionHandler.connectToService:2458 
com.android.server.MountService$ObbActionHandler.handleMessage:2337 
android.os.Handler.dispatchMessage:102 android.os.Looper.loop:136 

I assume this is related to the problem but I have been unable to find much on why there is no "qualified user". Can someone please explain what could be going on here?

We have verified that obbFile.exists() is true. This file is there.

While searching for an answer I've see lots of references to broken a JOBB tool. It also seems like Android 4.4 had a bug that prevented this from working (although I'm using 4.4.2 right now). I'm wondering if this is stable enough to use for production code.


Solution

  • Well, I think I finally figured out what is happening. It looks like the obb file in question was already mounted. The file was an APK expansion file and it would appear this is automatically mounted for you by the system.

    If, before trying to mount it, I execute:

            if (storageManager.isObbMounted( obbFile.getAbsolutePath() ))
            {
                Log.d("", "obb file mounted at " + storageManager.getMountedObbPath( obbFile.getAbsolutePath() ));
            }
    

    without first explicitly mounting it, I get a valid mount path. I really wish the docs (or LogCat messages) were more explicit about this. It took me about a day to discover this. It wasn't until I explicitly used an (necessary) encryption key on the obb that I saw a message in LogCat saying the file was already mounted.