// This file is auto-generated. DO NOT MODIFY.
// Args: com.android.systemfeatures.RoFeatures \
//            --readonly=true \
//            --feature=WATCH:1 \
//            --feature=WIFI:0 \
//            --feature=VULKAN:UNAVAILABLE \
//            --feature=AUTO: \
//            --feature-apis=WATCH,PC
package com.android.systemfeatures;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.util.ArrayMap;
import com.android.aconfig.annotations.AssumeFalseForR8;
import com.android.aconfig.annotations.AssumeTrueForR8;

/**
 * @hide
 */
public final class RoFeatures {
    /**
     * Check for FEATURE_WATCH.
     *
     * @hide
     */
    @AssumeTrueForR8
    public static boolean hasFeatureWatch(Context context) {
        return true;
    }

    /**
     * Check for FEATURE_PC.
     *
     * @hide
     */
    public static boolean hasFeaturePc(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_PC);
    }

    /**
     * Check for FEATURE_WIFI.
     *
     * @hide
     */
    @AssumeTrueForR8
    public static boolean hasFeatureWifi(Context context) {
        return true;
    }

    /**
     * Check for FEATURE_VULKAN.
     *
     * @hide
     */
    @AssumeFalseForR8
    public static boolean hasFeatureVulkan(Context context) {
        return false;
    }

    /**
     * Check for FEATURE_AUTO.
     *
     * @hide
     */
    public static boolean hasFeatureAuto(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_AUTO);
    }

    private static boolean hasFeatureFallback(Context context, String featureName) {
        return context.getPackageManager().hasSystemFeature(featureName, 0);
    }

    /**
     * @hide
     */
    @Nullable
    public static Boolean maybeHasFeature(String featureName, int version) {
        switch (featureName) {
            case PackageManager.FEATURE_WATCH: return 1 >= version;
            case PackageManager.FEATURE_WIFI: return 0 >= version;
            case PackageManager.FEATURE_VULKAN: return false;
            default: break;
        }
        return null;
    }

    /**
     * Gets features marked as available at compile-time, keyed by name.
     *
     * @hide
     */
    @NonNull
    public static ArrayMap<String, FeatureInfo> getReadOnlySystemEnabledFeatures() {
        ArrayMap<String, FeatureInfo> features = new ArrayMap<>(2);
        FeatureInfo fi = new FeatureInfo();
        fi.name = PackageManager.FEATURE_WATCH;
        fi.version = 1;
        features.put(fi.name, new FeatureInfo(fi));
        fi.name = PackageManager.FEATURE_WIFI;
        fi.version = 0;
        features.put(fi.name, new FeatureInfo(fi));
        return features;
    }
}
