microg/GmsCore · error · IllegalArgumentException

priority {priority} must be a Priority.PRIORITY_* constant

Error message

priority {priority} must be a Priority.PRIORITY_* constant

What it means

PriorityUtil.checkValidPriority validates that the given @Priority int is one of the Priority.PRIORITY_* constants defined by the library (isValidPriority). Any integer outside the allowed set throws IllegalArgumentException, since location requests require a well-defined priority.

Source

Thrown at play-services-location/src/main/java/org/microg/gms/location/PriorityUtil.java:26

import androidx.annotation.NonNull;
import com.google.android.gms.location.Priority;

public class PriorityUtil {
    public static boolean isValidPriority(@Priority int priority) {
        switch (priority) {
            default:
                return false;
            case Priority.PRIORITY_HIGH_ACCURACY:
            case Priority.PRIORITY_BALANCED_POWER_ACCURACY:
            case Priority.PRIORITY_LOW_POWER:
            case Priority.PRIORITY_PASSIVE:
                return true;
        }
    }

    public static int checkValidPriority(@Priority int priority) {
        if (!isValidPriority(priority)) {
            throw new IllegalArgumentException("priority " + priority + " must be a Priority.PRIORITY_* constant");
        }
        return priority;
    }

    @NonNull
    public static String priorityToString(@Priority int priority) {
        switch (priority) {
            case Priority.PRIORITY_HIGH_ACCURACY:
                return "HIGH_ACCURACY";
            case Priority.PRIORITY_BALANCED_POWER_ACCURACY:
                return "BALANCED_POWER_ACCURACY";
            case Priority.PRIORITY_LOW_POWER:
                return "LOW_POWER";
            case Priority.PRIORITY_PASSIVE:
                return "PASSIVE";
            default:
                throw new IllegalArgumentException();
        }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Use only Priority.PRIORITY_* constants (e.g. PRIORITY_HIGH_ACCURACY, PRIORITY_BALANCED_POWER_ACCURACY, PRIORITY_LOW_POWER, PRIORITY_PASSIVE)
  2. Do not combine priority constants with bitwise OR
  3. Validate user/config supplied values against isValidPriority before constructing requests

Example fix

// before
LocationRequest request = new LocationRequest.Builder(0) // invalid priority
    .build();
// after
LocationRequest request = new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

static boolean isKnownPriority(int p) {
    return p == Priority.PRIORITY_HIGH_ACCURACY
        || p == Priority.PRIORITY_BALANCED_POWER_ACCURACY
        || p == Priority.PRIORITY_LOW_POWER
        || p == Priority.PRIORITY_PASSIVE;
}

Try / catch

try { PriorityUtil.checkValidPriority(p); } catch (IllegalArgumentException e) { p = Priority.PRIORITY_BALANCED_POWER_ACCURACY; }

Prevention

When it happens

Trigger: Passing an invalid priority to checkValidPriority or to a LocationRequest builder that validates it — e.g. 0, 100, a bitfield, or a constant from a different enum (granularity/throttle behavior) mistakenly used as a priority.

Common situations: Hard-coded numeric priorities copied from old com.google.android.gms.location.LocationRequest (e.g. PRIORITY_HIGH_ACCURACY as 100) mixed with new constants; using Camera or other library constants; JSON/config-driven values not whitelisted.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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