Add Automotive eligibility check am: 8176b22e2d
am: 9ef2eb0c17
Change-Id: I809a1ff6146aef8cf2226e0ce00e2e61a32dc4ae
diff --git a/src/com/android/settings/intelligence/suggestions/eligibility/AutomotiveEligibilityChecker.java b/src/com/android/settings/intelligence/suggestions/eligibility/AutomotiveEligibilityChecker.java
new file mode 100644
index 0000000..db8b1d7
--- /dev/null
+++ b/src/com/android/settings/intelligence/suggestions/eligibility/AutomotiveEligibilityChecker.java
@@ -0,0 +1,31 @@
+package com.android.settings.intelligence.suggestions.eligibility;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.util.Log;
+
+public class AutomotiveEligibilityChecker {
+ private static final String TAG = "AutomotiveEligibility";
+
+ /**
+ * When running with {@link PackageManager#FEATURE_AUTOMOTIVE}, suggestion must have
+ * {@link #META_DATA_AUTOMOTIVE_ELIGIBLE} defined as true for the suggestion to be eligible.
+ */
+ private static final String META_DATA_AUTOMOTIVE_ELIGIBLE =
+ "com.android.settings.automotive_eligible";
+
+ public static boolean isEligible(Context context, String id, ResolveInfo info) {
+ PackageManager packageManager = context.getPackageManager();
+ boolean isAutomotive = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
+ boolean isAutomotiveEligible =
+ info.activityInfo.metaData.getBoolean(META_DATA_AUTOMOTIVE_ELIGIBLE, false);
+ if (isAutomotive) {
+ if (!isAutomotiveEligible) {
+ Log.i(TAG, "Suggestion is ineligible for FEATURE_AUTOMOTIVE: " + id);
+ }
+ return isAutomotiveEligible;
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/intelligence/suggestions/model/CandidateSuggestion.java b/src/com/android/settings/intelligence/suggestions/model/CandidateSuggestion.java
index b53d16f..c468ab9 100644
--- a/src/com/android/settings/intelligence/suggestions/model/CandidateSuggestion.java
+++ b/src/com/android/settings/intelligence/suggestions/model/CandidateSuggestion.java
@@ -32,6 +32,7 @@
import android.util.Log;
import com.android.settings.intelligence.suggestions.eligibility.AccountEligibilityChecker;
+import com.android.settings.intelligence.suggestions.eligibility.AutomotiveEligibilityChecker;
import com.android.settings.intelligence.suggestions.eligibility.ConnectivityEligibilityChecker;
import com.android.settings.intelligence.suggestions.eligibility.DismissedChecker;
import com.android.settings.intelligence.suggestions.eligibility.FeatureEligibilityChecker;
@@ -156,6 +157,9 @@
if (!DismissedChecker.isEligible(mContext, mId, mResolveInfo, mIgnoreAppearRule)) {
return false;
}
+ if (!AutomotiveEligibilityChecker.isEligible(mContext, mId, mResolveInfo)) {
+ return false;
+ }
return true;
}