1 package com.android.settings.intelligence.suggestions.eligibility;
2 
3 import android.content.Context;
4 import android.content.pm.PackageManager;
5 import android.content.pm.ResolveInfo;
6 import android.util.Log;
7 
8 public class AutomotiveEligibilityChecker {
9     private static final String TAG = "AutomotiveEligibility";
10 
11     /**
12      * When running with {@link PackageManager#FEATURE_AUTOMOTIVE}, suggestion must have
13      * {@link #META_DATA_AUTOMOTIVE_ELIGIBLE} defined as true for the suggestion to be eligible.
14      */
15     private static final String META_DATA_AUTOMOTIVE_ELIGIBLE =
16             "com.android.settings.automotive_eligible";
17 
isEligible(Context context, String id, ResolveInfo info)18     public static boolean isEligible(Context context, String id, ResolveInfo info) {
19         PackageManager packageManager = context.getPackageManager();
20         boolean isAutomotive = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
21         boolean isAutomotiveEligible =
22                 info.activityInfo.metaData.getBoolean(META_DATA_AUTOMOTIVE_ELIGIBLE, false);
23         if (isAutomotive) {
24             if (!isAutomotiveEligible) {
25                 Log.i(TAG, "Suggestion is ineligible for FEATURE_AUTOMOTIVE: " + id);
26             }
27             return isAutomotiveEligible;
28         }
29         return true;
30     }
31 }
32