googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.51k stars 2.92k forks source link

[Bug report] MLKit Subject Segmentation crashes intermittently after Google Play services storage data deletion #858

Open KoheiMoroi opened 1 month ago

KoheiMoroi commented 1 month ago

Describe the bug MLKit Subject Segmentation crashes intermittently after Google Play services storage data is deleted. The issue occurs during the processing of Subject Segmentation. Our app already implements proactive checks for Google Play services API availability before using MLKit features.

GoogleApiAvailability.isGooglePlayServicesAvailable(context)

The crash is not consistently reproducible, suggesting a race condition for timing-related issue.

The following error log appears after deleting Google Play services storage data. This error likely causes the crash, I guess.

Error log: Failed to get service from broker. java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'. at android.os.Parcel.createExceptionOrNull(Parcel.java:3183) at android.os.Parcel.createException(Parcel.java:3167) at android.os.Parcel.readException(Parcel.java:3150) at android.os.Parcel.readException(Parcel.java:3092) at m.gg.q(:com.google.android.gms.optional_mlkit_subject_segmentation@242632042@24.26.32 (100400-0):198) at m.fe.run(:com.google.android.gms.optional_mlkit_subject_segmentation@242632042@24.26.32 (100400-0):54) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85)

To Reproduce Example Steps to reproduce the behavior in sample app:

  1. Go to Google Play services settings
  2. Delete all Storage data for Google Play services
  3. Return to the app
  4. Attempt to use background feature using MLKit's Subject Segmentation
  5. Observe intermittent crash

Expected behavior The Subject Segmentation should process the image successfully or handle the error gracefully without crashing.

SDK Info:

Smartphone:

Development Environment: (For Android issue feel free to skip this section)

This issue is unlikely in real-world usage as users rarely delete Google Play services data manually. However, we would appreciate any insights or potential solutions to this issue; even a workaround is welcome. Please let me know if you need any additional information or if there are any specific diagnostic steps we can take to assist in resolving this issue. Thank you.

SilverDestiny commented 1 month ago

Hi,

Why do you need to delete all Storage data for Google Play services? This is unusual operation and It may cause unforeseen errors as Google Play services might need some time to init everything as pre-setup. Sometimes it needs a reboot as well.

KoheiMoroi commented 1 month ago

@SilverDestiny Thank you for your response. We were specifically testing a scenario that simulates a fresh installation or situation where required modules might need to be reinstalled. This is to ensure our app's robustness in various edge cases. Based on your feedback, it seems the behavior we're experiencing might not be a crash, but rather an initialization process. Is that correct? If so, how would you recommend we handle such situation?

SilverDestiny commented 1 month ago

From the error log:

Failed to get service from broker. java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'. at android.os.Parcel.createExceptionOrNull(Parcel.java:3183) at android.os.Parcel.createException(Parcel.java:3167) at android.os.Parcel.readException(Parcel.java:3150) at android.os.Parcel.readException(Parcel.java:3092) at m.gg.q(:com.google.android.gms.optional_mlkit_subject_segmentation@242632042@24.26.32 (100400-0):198) at m.fe.run(:com.google.android.gms.optional_mlkit_subject_segmentation@242632042@24.26.32 (100400-0):54) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85)

It looks like Google Play services package is somehow not found, but this is hard to tell what was wrong.

To ensure the module is available before running inference, I'd recommend using Google Play services module install API to check and verify: https://developers.google.com/android/guides/module-install-apis

SubjectSegmenter could be used directly by the module install API.

KoheiMoroi commented 3 weeks ago

@SilverDestiny Thank you for your response and suggestions regarding the issue. I wanted to inform you that we have already implemented this approach in our code before executing the API. Specifically, we're using the module install API to check and ensure the availability of the required modules before attempting to run the inference.

moduleInstallClient
  .installModules(moduleInstallRequest)
  .addOnSuccessListener {
    if (it.areModulesAlreadyInstalled()) {
      // Modules are already installed when the request is sent.
    }
  }
  .addOnFailureListener {
    // Handle failure…
  }

Despite having this check in place, we're still encountering the issue where the Google Play services package appears to be not found. Given that we've already implemented the recommended solution, we're wondering if there might be other factors at play or if you have any additional insights or troubleshooting steps we could try.

SilverDestiny commented 2 weeks ago

We submitted the fix for the SecurityException error. The fix will roll out in ~1 month or less.

Please try again later and thanks a lot for reporting the bug!

KoheiMoroi commented 2 weeks ago

@SilverDestiny I appreciate you taking the time to address this issue and provide an update on its status. It's great to hear that a fix has been submitted and is scheduled to release within next month. I will certainly try the app again after the estimated rollout period.

Could you please let me know which version include this fix?

SilverDestiny commented 2 weeks ago

The fix should be in version 24.36.xx for Google Play services