Merge pull request #2214 from hagau/auth_provider_utils

Add/modify helper for getting authentication provider information
This commit is contained in:
Vincent Breitmoser
2017-11-22 13:14:59 +01:00
committed by GitHub

View File

@@ -26,16 +26,31 @@ import java.util.List;
public class SshAuthenticationApiUtils { public class SshAuthenticationApiUtils {
public static List<String> getAgentProviders(Context context) { public static List<String> getAuthenticationProviderPackageNames(Context context) {
Intent intent = new Intent(SshAuthenticationApi.SERVICE_INTENT); List<ResolveInfo> resolvedInfo = getAuthenticationProviderInfo(context);
List<ResolveInfo> resolvedInfo = context.getPackageManager().queryIntentServices(intent, 0); return getAuthenticationProviderPackageNames(resolvedInfo);
}
public static List<String> getAuthenticationProviderPackageNames(List<ResolveInfo> resolvedInfo) {
ArrayList<String> providers = new ArrayList<>(); ArrayList<String> providers = new ArrayList<>();
if (resolvedInfo != null) { for (ResolveInfo resolveInfoEntry : resolvedInfo) {
for (ResolveInfo resolveInfoEntry : resolvedInfo) { providers.add(resolveInfoEntry.serviceInfo.packageName);
providers.add(resolveInfoEntry.serviceInfo.packageName);
}
} }
return providers; return providers;
} }
public static List<String> getAuthenticationProviderLabel(Context context, List<ResolveInfo> resolvedInfo) {
ArrayList<String> providerLabel = new ArrayList<>();
for (ResolveInfo resolveInfoEntry : resolvedInfo) {
CharSequence label = context.getPackageManager()
.getApplicationLabel(resolveInfoEntry.serviceInfo.applicationInfo);
providerLabel.add(label.toString());
}
return providerLabel;
}
public static List<ResolveInfo> getAuthenticationProviderInfo(Context context) {
Intent intent = new Intent(SshAuthenticationApi.SERVICE_INTENT);
return context.getPackageManager().queryIntentServices(intent, 0);
}
} }