Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Updated CredentialClient to utilize ProviderResolver methods (#143)
Browse files Browse the repository at this point in the history
* Updated CredentialClient to utilize ProviderResolver methods

* Fixed import order to pass checkstyle
  • Loading branch information
nerdyverde authored and iainmcgin committed Nov 4, 2017
1 parent 49e6117 commit ff0de4b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions api/java/org/openyolo/api/CredentialClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
Expand All @@ -44,6 +43,7 @@
import org.openyolo.api.internal.FinishWithResultActivity;
import org.openyolo.api.internal.KnownProviders;
import org.openyolo.api.internal.ProviderPickerActivity;
import org.openyolo.api.internal.ProviderResolver;
import org.openyolo.api.persistence.AppSettings;
import org.openyolo.api.persistence.internal.AppSettingsImpl;
import org.openyolo.protocol.Credential;
Expand Down Expand Up @@ -213,7 +213,8 @@ public Intent getCredentialRetrieveIntent(CredentialRetrieveRequest request) {
*/
@NonNull
public Intent getHintRetrieveIntent(final HintRetrieveRequest request) {
List<ComponentName> hintProviders = findProviders(HINT_CREDENTIAL_ACTION);
List<ComponentName> hintProviders =
ProviderResolver.findProviders(mApplicationContext, HINT_CREDENTIAL_ACTION);

if (hintProviders.isEmpty()) {
ActivityResult result = ActivityResult.of(
Expand Down Expand Up @@ -282,7 +283,8 @@ public Intent getSaveIntent(final Credential credential) {
*/
@NonNull
public Intent getSaveIntent(final CredentialSaveRequest saveRequest) {
List<ComponentName> saveProviders = findProviders(SAVE_CREDENTIAL_ACTION);
List<ComponentName> saveProviders =
ProviderResolver.findProviders(mApplicationContext, SAVE_CREDENTIAL_ACTION);

if (saveProviders.isEmpty()) {
ActivityResult result = ActivityResult.of(
Expand Down Expand Up @@ -360,7 +362,7 @@ public Intent getDeleteIntent(@NonNull CredentialDeleteRequest request) {
require(request, notNullValue());

List<ComponentName> deleteProviders =
findProviders(DELETE_CREDENTIAL_ACTION);
ProviderResolver.findProviders(mApplicationContext, DELETE_CREDENTIAL_ACTION);

if (deleteProviders.isEmpty()) {
ActivityResult result = ActivityResult.of(
Expand Down Expand Up @@ -632,23 +634,6 @@ public void disableAutoSignIn() {
mDeviceState.setIsAutoSignInDisabled(true);
}

private List<ComponentName> findProviders(@NonNull String action) {
Intent saveIntent = new Intent(action);
saveIntent.addCategory(OPENYOLO_CATEGORY);

List<ResolveInfo> resolveInfos =
mApplicationContext.getPackageManager().queryIntentActivities(saveIntent, 0);

ArrayList<ComponentName> responders = new ArrayList<>();
for (ResolveInfo info : resolveInfos) {
responders.add(new ComponentName(
info.activityInfo.packageName,
info.activityInfo.name));
}

return responders;
}

@Nullable
private ComponentName getPreferredProvider(@NonNull List<ComponentName> providers) {
// In the future, the user will be able to explicitly set their preferred provider in
Expand Down

0 comments on commit ff0de4b

Please sign in to comment.