package androidx.core.app; import android.app.RemoteInput; import android.content.ClipData; import android.content.ClipDescription; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; /* loaded from: classes.dex */ public final class RemoteInput { public static final int EDIT_CHOICES_BEFORE_SENDING_AUTO = 0; public static final int EDIT_CHOICES_BEFORE_SENDING_DISABLED = 1; public static final int EDIT_CHOICES_BEFORE_SENDING_ENABLED = 2; private static final String EXTRA_DATA_TYPE_RESULTS_DATA = "android.remoteinput.dataTypeResultsData"; public static final String EXTRA_RESULTS_DATA = "android.remoteinput.resultsData"; private static final String EXTRA_RESULTS_SOURCE = "android.remoteinput.resultsSource"; public static final String RESULTS_CLIP_LABEL = "android.remoteinput.results"; public static final int SOURCE_CHOICE = 1; public static final int SOURCE_FREE_FORM_INPUT = 0; private final boolean mAllowFreeFormTextInput; private final Set mAllowedDataTypes; private final CharSequence[] mChoices; private final int mEditChoicesBeforeSending; private final Bundle mExtras; private final CharSequence mLabel; private final String mResultKey; @Retention(RetentionPolicy.SOURCE) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public @interface EditChoicesBeforeSending { } @Retention(RetentionPolicy.SOURCE) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public @interface Source { } public boolean getAllowFreeFormInput() { return this.mAllowFreeFormTextInput; } @Nullable public Set getAllowedDataTypes() { return this.mAllowedDataTypes; } @Nullable public CharSequence[] getChoices() { return this.mChoices; } public int getEditChoicesBeforeSending() { return this.mEditChoicesBeforeSending; } @NonNull public Bundle getExtras() { return this.mExtras; } @Nullable public CharSequence getLabel() { return this.mLabel; } @NonNull public String getResultKey() { return this.mResultKey; } public RemoteInput(String str, CharSequence charSequence, CharSequence[] charSequenceArr, boolean z, int i, Bundle bundle, Set set) { this.mResultKey = str; this.mLabel = charSequence; this.mChoices = charSequenceArr; this.mAllowFreeFormTextInput = z; this.mEditChoicesBeforeSending = i; this.mExtras = bundle; this.mAllowedDataTypes = set; if (getEditChoicesBeforeSending() == 2 && !getAllowFreeFormInput()) { throw new IllegalArgumentException("setEditChoicesBeforeSending requires setAllowFreeFormInput"); } } public boolean isDataOnly() { return (getAllowFreeFormInput() || (getChoices() != null && getChoices().length != 0) || getAllowedDataTypes() == null || getAllowedDataTypes().isEmpty()) ? false : true; } public static final class Builder { private CharSequence[] mChoices; private CharSequence mLabel; private final String mResultKey; private final Set mAllowedDataTypes = new HashSet(); private final Bundle mExtras = new Bundle(); private boolean mAllowFreeFormTextInput = true; private int mEditChoicesBeforeSending = 0; @NonNull public Bundle getExtras() { return this.mExtras; } @NonNull public Builder setAllowFreeFormInput(boolean z) { this.mAllowFreeFormTextInput = z; return this; } @NonNull public Builder setChoices(@Nullable CharSequence[] charSequenceArr) { this.mChoices = charSequenceArr; return this; } @NonNull public Builder setEditChoicesBeforeSending(int i) { this.mEditChoicesBeforeSending = i; return this; } @NonNull public Builder setLabel(@Nullable CharSequence charSequence) { this.mLabel = charSequence; return this; } public Builder(@NonNull String str) { if (str == null) { throw new IllegalArgumentException("Result key can't be null"); } this.mResultKey = str; } @NonNull public Builder setAllowDataType(@NonNull String str, boolean z) { if (z) { this.mAllowedDataTypes.add(str); } else { this.mAllowedDataTypes.remove(str); } return this; } @NonNull public Builder addExtras(@NonNull Bundle bundle) { if (bundle != null) { this.mExtras.putAll(bundle); } return this; } @NonNull public RemoteInput build() { return new RemoteInput(this.mResultKey, this.mLabel, this.mChoices, this.mAllowFreeFormTextInput, this.mEditChoicesBeforeSending, this.mExtras, this.mAllowedDataTypes); } } @Nullable public static Map getDataResultsFromIntent(@NonNull Intent intent, @NonNull String str) { return Api26Impl.getDataResultsFromIntent(intent, str); } @Nullable public static Bundle getResultsFromIntent(@NonNull Intent intent) { return Api20Impl.getResultsFromIntent(intent); } public static void addResultsToIntent(@NonNull RemoteInput[] remoteInputArr, @NonNull Intent intent, @NonNull Bundle bundle) { Api20Impl.addResultsToIntent(fromCompat(remoteInputArr), intent, bundle); } public static void addDataResultToIntent(@NonNull RemoteInput remoteInput, @NonNull Intent intent, @NonNull Map map) { Api26Impl.addDataResultToIntent(remoteInput, intent, map); } public static void setResultsSource(@NonNull Intent intent, int i) { if (Build.VERSION.SDK_INT >= 28) { Api28Impl.setResultsSource(intent, i); return; } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { clipDataIntentFromIntent = new Intent(); } clipDataIntentFromIntent.putExtra(EXTRA_RESULTS_SOURCE, i); intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipDataIntentFromIntent)); } public static int getResultsSource(@NonNull Intent intent) { if (Build.VERSION.SDK_INT >= 28) { return Api28Impl.getResultsSource(intent); } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { return 0; } return clipDataIntentFromIntent.getExtras().getInt(EXTRA_RESULTS_SOURCE, 0); } private static String getExtraResultsKeyForData(String str) { return EXTRA_DATA_TYPE_RESULTS_DATA + str; } @RequiresApi(20) public static android.app.RemoteInput[] fromCompat(RemoteInput[] remoteInputArr) { if (remoteInputArr == null) { return null; } android.app.RemoteInput[] remoteInputArr2 = new android.app.RemoteInput[remoteInputArr.length]; for (int i = 0; i < remoteInputArr.length; i++) { remoteInputArr2[i] = fromCompat(remoteInputArr[i]); } return remoteInputArr2; } @RequiresApi(20) public static android.app.RemoteInput fromCompat(RemoteInput remoteInput) { return Api20Impl.fromCompat(remoteInput); } @RequiresApi(20) public static RemoteInput fromPlatform(android.app.RemoteInput remoteInput) { return Api20Impl.fromPlatform(remoteInput); } private static Intent getClipDataIntentFromIntent(Intent intent) { ClipData clipData = intent.getClipData(); if (clipData == null) { return null; } ClipDescription description = clipData.getDescription(); if (description.hasMimeType("text/vnd.android.intent") && description.getLabel().toString().contentEquals(RESULTS_CLIP_LABEL)) { return clipData.getItemAt(0).getIntent(); } return null; } @RequiresApi(26) public static class Api26Impl { private Api26Impl() { } public static Map getDataResultsFromIntent(Intent intent, String str) { return android.app.RemoteInput.getDataResultsFromIntent(intent, str); } public static Set getAllowedDataTypes(Object obj) { return ((android.app.RemoteInput) obj).getAllowedDataTypes(); } public static void addDataResultToIntent(RemoteInput remoteInput, Intent intent, Map map) { android.app.RemoteInput.addDataResultToIntent(RemoteInput.fromCompat(remoteInput), intent, map); } public static RemoteInput.Builder setAllowDataType(RemoteInput.Builder builder, String str, boolean z) { return builder.setAllowDataType(str, z); } } @RequiresApi(20) public static class Api20Impl { private Api20Impl() { } public static Bundle getResultsFromIntent(Intent intent) { return android.app.RemoteInput.getResultsFromIntent(intent); } public static void addResultsToIntent(Object obj, Intent intent, Bundle bundle) { android.app.RemoteInput.addResultsToIntent((android.app.RemoteInput[]) obj, intent, bundle); } public static RemoteInput fromPlatform(Object obj) { android.app.RemoteInput remoteInput = (android.app.RemoteInput) obj; Builder addExtras = new Builder(remoteInput.getResultKey()).setLabel(remoteInput.getLabel()).setChoices(remoteInput.getChoices()).setAllowFreeFormInput(remoteInput.getAllowFreeFormInput()).addExtras(remoteInput.getExtras()); Set allowedDataTypes = Api26Impl.getAllowedDataTypes(remoteInput); if (allowedDataTypes != null) { Iterator it = allowedDataTypes.iterator(); while (it.hasNext()) { addExtras.setAllowDataType(it.next(), true); } } if (Build.VERSION.SDK_INT >= 29) { addExtras.setEditChoicesBeforeSending(Api29Impl.getEditChoicesBeforeSending(remoteInput)); } return addExtras.build(); } public static android.app.RemoteInput fromCompat(RemoteInput remoteInput) { RemoteInput.Builder addExtras = new RemoteInput.Builder(remoteInput.getResultKey()).setLabel(remoteInput.getLabel()).setChoices(remoteInput.getChoices()).setAllowFreeFormInput(remoteInput.getAllowFreeFormInput()).addExtras(remoteInput.getExtras()); Set allowedDataTypes = remoteInput.getAllowedDataTypes(); if (allowedDataTypes != null) { Iterator it = allowedDataTypes.iterator(); while (it.hasNext()) { Api26Impl.setAllowDataType(addExtras, it.next(), true); } } if (Build.VERSION.SDK_INT >= 29) { Api29Impl.setEditChoicesBeforeSending(addExtras, remoteInput.getEditChoicesBeforeSending()); } return addExtras.build(); } } @RequiresApi(29) public static class Api29Impl { private Api29Impl() { } public static int getEditChoicesBeforeSending(Object obj) { return ((android.app.RemoteInput) obj).getEditChoicesBeforeSending(); } public static RemoteInput.Builder setEditChoicesBeforeSending(RemoteInput.Builder builder, int i) { return builder.setEditChoicesBeforeSending(i); } } @RequiresApi(28) public static class Api28Impl { private Api28Impl() { } public static void setResultsSource(Intent intent, int i) { android.app.RemoteInput.setResultsSource(intent, i); } public static int getResultsSource(Intent intent) { return android.app.RemoteInput.getResultsSource(intent); } } }