Fix feature flag check for FEATURE_COMPANION_DEVICE_SETUP
Fix: 237723969 Test: manually tested association flow and verified the feature flag has been checked. Change-Id: I556089e2b024eaf87937e57e8825ae0e7c61e02c
This commit is contained in:
@@ -30,6 +30,7 @@ import android.companion.CompanionDeviceService;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.FeatureInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.PackageInfoFlags;
|
import android.content.pm.PackageManager.PackageInfoFlags;
|
||||||
@@ -39,8 +40,6 @@ import android.content.pm.ServiceInfo;
|
|||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -65,17 +64,20 @@ final class PackageUtils {
|
|||||||
|
|
||||||
static void enforceUsesCompanionDeviceFeature(@NonNull Context context,
|
static void enforceUsesCompanionDeviceFeature(@NonNull Context context,
|
||||||
@UserIdInt int userId, @NonNull String packageName) {
|
@UserIdInt int userId, @NonNull String packageName) {
|
||||||
final boolean requested = ArrayUtils.contains(
|
String requiredFeature = FEATURE_COMPANION_DEVICE_SETUP;
|
||||||
getPackageInfo(context, userId, packageName).reqFeatures,
|
|
||||||
FEATURE_COMPANION_DEVICE_SETUP);
|
|
||||||
|
|
||||||
if (requested) {
|
FeatureInfo[] requestedFeatures = getPackageInfo(context, userId, packageName).reqFeatures;
|
||||||
throw new IllegalStateException("Must declare uses-feature "
|
for (int i = 0; i < requestedFeatures.length; i++) {
|
||||||
+ FEATURE_COMPANION_DEVICE_SETUP
|
if (requiredFeature.equals(requestedFeatures[i].name)) {
|
||||||
+ " in manifest to use this API");
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException("Must declare uses-feature "
|
||||||
|
+ requiredFeature
|
||||||
|
+ " in manifest to use this API");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list of {@link CompanionDeviceService}-s per package for a given user.
|
* @return list of {@link CompanionDeviceService}-s per package for a given user.
|
||||||
* Services marked as "primary" would always appear at the head of the lists, *before*
|
* Services marked as "primary" would always appear at the head of the lists, *before*
|
||||||
|
|||||||
Reference in New Issue
Block a user