microg/GmsCore · error · UnsupportedOperationException

UnsupportedOperationException

Error message

UnsupportedOperationException

What it means

SleepClassifyEvent.extractEvents(Intent) is a stub in this pure-Java/play-services-artifacts source: it unconditionally throws UnsupportedOperationException. The real implementation only exists inside Google Play services on a device; the class bundled with the client library contains no logic.

Source

Thrown at play-services-location/src/main/java/com/google/android/gms/location/SleepClassifyEvent.java:33

import java.util.List;

/**
 * Represents a sleep classification event including the classification timestamp, the sleep confidence, and the
 * supporting data such as device motion and ambient light level. Classification events are reported at a regular
 * intervals, such as every 10 minutes.
 */
public class SleepClassifyEvent extends AutoSafeParcelable {
    public static final Creator<SleepClassifyEvent> CREATOR = new AutoCreator<>(SleepClassifyEvent.class);

    /**
     * Extracts the {@code SleepClassifyEvent} from an {@code Intent}.
     *
     * @param intent the {@code Intent} to extract from
     * @return a list of {@link SleepClassifyEvent}s if the intent has events, or an empty list if the intent doesn't
     * contain any events.
     */
    public static List<SleepClassifyEvent> extractEvents(Intent intent) {
        throw new UnsupportedOperationException();
    }

    /**
     * Returns a sleep confidence value between 0 and 100. Higher values indicate that the user is more likely sleeping,
     * while lower values indicate that the user is more likely awake.
     */
    public int getConfidence() {
        throw new UnsupportedOperationException();
    }

    /**
     * Returns the brightness of the space around the device, based on the device's ambient light sensor readings. Value
     * ranges from 1 to 6, inclusive. Higher values indicate brighter surroundings, while lower values indicate darker
     * surroundings.
     */
    public int getLight() {
        throw new UnsupportedOperationException();
    }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Don't call this stub directly; rely on the runtime Play services implementation on a real device with Google Play services available.
  2. Guard the call behind a GoogleApiAvailability check and fall back gracefully.
  3. In unit tests, avoid invoking it or mock the static method.
  4. Check that the app is using the correct play-services-location dependency and that activity-recognition/sleep APIs are actually available on the target device.

Example fix

// before
List<SleepClassifyEvent> events = SleepClassifyEvent.extractEvents(intent);
// after
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
    List<SleepClassifyEvent> events = SleepClassifyEvent.extractEvents(intent);
} else {
    List<SleepClassifyEvent> events = Collections.emptyList(); // fallback
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean available = GoogleApiAvailability.getInstance()
    .isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS;
if (!available) return Collections.emptyList();

Try / catch

try {
    return SleepClassifyEvent.extractEvents(intent);
} catch (UnsupportedOperationException e) {
    return Collections.emptyList();
}

Prevention

When it happens

Trigger: Calling SleepClassifyEvent.extractEvents(intent) with any Intent, in any environment, since the method body is only 'throw new UnsupportedOperationException()'.

Common situations: Calling the method in unit tests or on an emulator, or linking against a client-library artifact where the runtime Google Play services portion is absent (or the code path runs before Play services delivers the actual implementation).

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/2e0ef0f1bff0f0dd. Report an issue: GitHub.