1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.intelligence.suggestions.eligibility; 18 19 import android.content.Context; 20 import android.content.pm.ResolveInfo; 21 import android.support.annotation.VisibleForTesting; 22 import android.text.TextUtils; 23 import android.util.Log; 24 25 public class FeatureEligibilityChecker { 26 27 private static final String TAG = "FeatureEligibility"; 28 29 /** 30 * If defined, only returns this suggestion if the feature is supported. 31 */ 32 @VisibleForTesting 33 static final String META_DATA_REQUIRE_FEATURE = "com.android.settings.require_feature"; 34 35 public static boolean isEligible(Context context, String id, ResolveInfo info) { 36 final String featuresRequired = info.activityInfo.metaData 37 .getString(META_DATA_REQUIRE_FEATURE); 38 if (featuresRequired != null) { 39 for (String feature : featuresRequired.split(",")) { 40 if (TextUtils.isEmpty(feature)) { 41 Log.i(TAG, "Found empty substring when parsing required features: " 42 + featuresRequired); 43 } else if (!context.getPackageManager().hasSystemFeature(feature)) { 44 Log.i(TAG, id + " requires unavailable feature " + feature); 45 return false; 46 } 47 } 48 } 49 return true; 50 } 51 } 52