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 c.d.b.a.a; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; 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 static final String TAG = "RemoteInput"; 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; public static final class Builder { private boolean mAllowFreeFormTextInput = true; private final Set mAllowedDataTypes = new HashSet(); private CharSequence[] mChoices; private int mEditChoicesBeforeSending = 0; private final Bundle mExtras = new Bundle(); private CharSequence mLabel; private final String mResultKey; public Builder(@NonNull String str) { if (str != null) { this.mResultKey = str; return; } throw new IllegalArgumentException("Result key can't be null"); } @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); } @NonNull public Bundle getExtras() { return this.mExtras; } @NonNull public Builder setAllowDataType(@NonNull String str, boolean z2) { if (z2) { this.mAllowedDataTypes.add(str); } else { this.mAllowedDataTypes.remove(str); } return this; } @NonNull public Builder setAllowFreeFormInput(boolean z2) { this.mAllowFreeFormTextInput = z2; 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; } } @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 RemoteInput(String str, CharSequence charSequence, CharSequence[] charSequenceArr, boolean z2, int i, Bundle bundle, Set set) { this.mResultKey = str; this.mLabel = charSequence; this.mChoices = charSequenceArr; this.mAllowFreeFormTextInput = z2; this.mEditChoicesBeforeSending = i; this.mExtras = bundle; this.mAllowedDataTypes = set; if (getEditChoicesBeforeSending() == 2 && !getAllowFreeFormInput()) { throw new IllegalArgumentException("setEditChoicesBeforeSending requires setAllowFreeFormInput"); } } public static void addDataResultToIntent(RemoteInput remoteInput, Intent intent, Map map) { if (Build.VERSION.SDK_INT >= 26) { android.app.RemoteInput.addDataResultToIntent(fromCompat(remoteInput), intent, map); return; } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { clipDataIntentFromIntent = new Intent(); } for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); Uri value = entry.getValue(); if (key != null) { Bundle bundleExtra = clipDataIntentFromIntent.getBundleExtra(getExtraResultsKeyForData(key)); if (bundleExtra == null) { bundleExtra = new Bundle(); } bundleExtra.putString(remoteInput.getResultKey(), value.toString()); clipDataIntentFromIntent.putExtra(getExtraResultsKeyForData(key), bundleExtra); } } intent.setClipData(ClipData.newIntent("android.remoteinput.results", clipDataIntentFromIntent)); } public static void addResultsToIntent(RemoteInput[] remoteInputArr, Intent intent, Bundle bundle) { if (Build.VERSION.SDK_INT >= 26) { android.app.RemoteInput.addResultsToIntent(fromCompat(remoteInputArr), intent, bundle); return; } Bundle resultsFromIntent = getResultsFromIntent(intent); int resultsSource = getResultsSource(intent); if (resultsFromIntent != null) { resultsFromIntent.putAll(bundle); bundle = resultsFromIntent; } for (RemoteInput remoteInput : remoteInputArr) { Map dataResultsFromIntent = getDataResultsFromIntent(intent, remoteInput.getResultKey()); android.app.RemoteInput.addResultsToIntent(fromCompat(new RemoteInput[]{remoteInput}), intent, bundle); if (dataResultsFromIntent != null) { addDataResultToIntent(remoteInput, intent, dataResultsFromIntent); } } setResultsSource(intent, resultsSource); } @RequiresApi(20) 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()); if (Build.VERSION.SDK_INT >= 29) { addExtras.setEditChoicesBeforeSending(remoteInput.getEditChoicesBeforeSending()); } return addExtras.build(); } @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(16) 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("android.remoteinput.results")) { return clipData.getItemAt(0).getIntent(); } return null; } public static Map getDataResultsFromIntent(Intent intent, String str) { String string; if (Build.VERSION.SDK_INT >= 26) { return android.app.RemoteInput.getDataResultsFromIntent(intent, str); } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { return null; } HashMap hashMap = new HashMap(); for (String str2 : clipDataIntentFromIntent.getExtras().keySet()) { if (str2.startsWith("android.remoteinput.dataTypeResultsData")) { String substring = str2.substring(39); if (!substring.isEmpty() && (string = clipDataIntentFromIntent.getBundleExtra(str2).getString(str)) != null && !string.isEmpty()) { hashMap.put(substring, Uri.parse(string)); } } } if (hashMap.isEmpty()) { return null; } return hashMap; } private static String getExtraResultsKeyForData(String str) { return a.t("android.remoteinput.dataTypeResultsData", str); } public static Bundle getResultsFromIntent(Intent intent) { return android.app.RemoteInput.getResultsFromIntent(intent); } public static int getResultsSource(@NonNull Intent intent) { if (Build.VERSION.SDK_INT >= 28) { return android.app.RemoteInput.getResultsSource(intent); } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { return 0; } return clipDataIntentFromIntent.getExtras().getInt("android.remoteinput.resultsSource", 0); } public static void setResultsSource(@NonNull Intent intent, int i) { if (Build.VERSION.SDK_INT >= 28) { android.app.RemoteInput.setResultsSource(intent, i); return; } Intent clipDataIntentFromIntent = getClipDataIntentFromIntent(intent); if (clipDataIntentFromIntent == null) { clipDataIntentFromIntent = new Intent(); } clipDataIntentFromIntent.putExtra("android.remoteinput.resultsSource", i); intent.setClipData(ClipData.newIntent("android.remoteinput.results", clipDataIntentFromIntent)); } public boolean getAllowFreeFormInput() { return this.mAllowFreeFormTextInput; } public Set getAllowedDataTypes() { return this.mAllowedDataTypes; } public CharSequence[] getChoices() { return this.mChoices; } public int getEditChoicesBeforeSending() { return this.mEditChoicesBeforeSending; } public Bundle getExtras() { return this.mExtras; } public CharSequence getLabel() { return this.mLabel; } public String getResultKey() { return this.mResultKey; } public boolean isDataOnly() { return !getAllowFreeFormInput() && (getChoices() == null || getChoices().length == 0) && getAllowedDataTypes() != null && !getAllowedDataTypes().isEmpty(); } }