| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.autofill; |
| 18 |
|
| 19 |
import static android.service.autofill.AutofillService.EXTRA_ERROR; |
| 20 |
import static android.service.autofill.AutofillService.EXTRA_RESULT; |
| 21 |
|
| 22 |
import static com.android.internal.util.Preconditions.checkArgumentInRange; |
| 23 |
|
| 24 |
import static java.util.Objects.requireNonNull; |
| 25 |
|
| 26 |
import android.annotation.NonNull; |
| 27 |
import android.os.Bundle; |
| 28 |
import android.os.DeadObjectException; |
| 29 |
import android.os.RemoteException; |
| 30 |
import android.util.Log; |
| 31 |
|
| 32 |
import com.android.internal.os.IResultReceiver; |
| 33 |
|
| 34 |
import java.util.Set; |
| 35 |
|
| 36 |
final class SavedDatasetsInfoCallbackImpl implements SavedDatasetsInfoCallback { |
| 37 |
private static final String TAG = "AutofillService"; |
| 38 |
|
| 39 |
@NonNull |
| 40 |
private final IResultReceiver mReceiver; |
| 41 |
@NonNull |
| 42 |
private final String mType; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
SavedDatasetsInfoCallbackImpl(@NonNull IResultReceiver receiver, @NonNull String type) { |
| 50 |
mReceiver = requireNonNull(receiver); |
| 51 |
mType = requireNonNull(type); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void onSuccess(@NonNull Set<SavedDatasetsInfo> results) { |
| 56 |
requireNonNull(results); |
| 57 |
if (results.isEmpty()) { |
| 58 |
send(1, null); |
| 59 |
return; |
| 60 |
} |
| 61 |
int count = -1; |
| 62 |
for (SavedDatasetsInfo info : results) { |
| 63 |
if (mType.equals(info.getType())) { |
| 64 |
count = info.getCount(); |
| 65 |
} |
| 66 |
} |
| 67 |
if (count < 0) { |
| 68 |
send(1, null); |
| 69 |
return; |
| 70 |
} |
| 71 |
Bundle bundle = new Bundle( 1); |
| 72 |
bundle.putInt(EXTRA_RESULT, count); |
| 73 |
send(0, bundle); |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public void onError(@Error int error) { |
| 78 |
checkArgumentInRange(error, ERROR_OTHER, ERROR_NEEDS_USER_ACTION, "error"); |
| 79 |
Bundle bundle = new Bundle( 1); |
| 80 |
bundle.putInt(EXTRA_ERROR, error); |
| 81 |
send(1, bundle); |
| 82 |
} |
| 83 |
|
| 84 |
private void send(int resultCode, Bundle bundle) { |
| 85 |
try { |
| 86 |
mReceiver.send(resultCode, bundle); |
| 87 |
} catch (DeadObjectException e) { |
| 88 |
Log.w(TAG, "Failed to send onSavedPasswordCountRequest result: " + e); |
| 89 |
} catch (RemoteException e) { |
| 90 |
throw e.rethrowAsRuntimeException(); |
| 91 |
} |
| 92 |
} |
| 93 |
} |