Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KoheiMoroi opened this issue Aug 7, 2024 · 7 comments
Assignees

Comments

@KoheiMoroi
Copy link

KoheiMoroi commented Aug 7, 2024

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:

  • SDK Name & Version [e.g. com.google.mlkit:face-detection:16.1.3]
    com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1

Smartphone:

  • Device:
  1. Google PIxel 5a (Android13)
  • Google Play services version: 24.26.32(190400-650348549)
  • Crash frequency: 4 out of 5 attempts
  1. Google Pixel 4a (Android14)
  • Google Play services version: 24.28.35(190400-657754416)
  • Crash frequency: 1 out of 5 attempts

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

  • IDE Eversion: [e.g. Xcode 13.1, Android Studio 4.2]
  • Laptop/Desktop: [e.g. iMac Pro (2017), HP Z840 Workstation]
  • Laptop/Desktop OS/version: [e.g. macOS 12.0.1]

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 SilverDestiny self-assigned this Aug 9, 2024
@SilverDestiny
Copy link
Collaborator

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
Copy link
Author

@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
Copy link
Collaborator

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
Copy link
Author

KoheiMoroi commented Aug 19, 2024

@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
Copy link
Collaborator

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
Copy link
Author

@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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants