package androidx.core.app; import android.app.Person; import android.os.Bundle; import android.os.PersistableBundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.core.graphics.drawable.IconCompat; import c.d.b.a.a; public class Person { private static final String ICON_KEY = "icon"; private static final String IS_BOT_KEY = "isBot"; private static final String IS_IMPORTANT_KEY = "isImportant"; private static final String KEY_KEY = "key"; private static final String NAME_KEY = "name"; private static final String URI_KEY = "uri"; @Nullable public IconCompat mIcon; public boolean mIsBot; public boolean mIsImportant; @Nullable public String mKey; @Nullable public CharSequence mName; @Nullable public String mUri; public static class Builder { @Nullable public IconCompat mIcon; public boolean mIsBot; public boolean mIsImportant; @Nullable public String mKey; @Nullable public CharSequence mName; @Nullable public String mUri; public Builder() { } public Builder(Person person) { this.mName = person.mName; this.mIcon = person.mIcon; this.mUri = person.mUri; this.mKey = person.mKey; this.mIsBot = person.mIsBot; this.mIsImportant = person.mIsImportant; } @NonNull public Person build() { return new Person(this); } @NonNull public Builder setBot(boolean z2) { this.mIsBot = z2; return this; } @NonNull public Builder setIcon(@Nullable IconCompat iconCompat) { this.mIcon = iconCompat; return this; } @NonNull public Builder setImportant(boolean z2) { this.mIsImportant = z2; return this; } @NonNull public Builder setKey(@Nullable String str) { this.mKey = str; return this; } @NonNull public Builder setName(@Nullable CharSequence charSequence) { this.mName = charSequence; return this; } @NonNull public Builder setUri(@Nullable String str) { this.mUri = str; return this; } } public Person(Builder builder) { this.mName = builder.mName; this.mIcon = builder.mIcon; this.mUri = builder.mUri; this.mKey = builder.mKey; this.mIsBot = builder.mIsBot; this.mIsImportant = builder.mIsImportant; } @NonNull @RequiresApi(28) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public static Person fromAndroidPerson(@NonNull android.app.Person person) { return new Builder().setName(person.getName()).setIcon(person.getIcon() != null ? IconCompat.createFromIcon(person.getIcon()) : null).setUri(person.getUri()).setKey(person.getKey()).setBot(person.isBot()).setImportant(person.isImportant()).build(); } @NonNull public static Person fromBundle(@NonNull Bundle bundle) { Bundle bundle2 = bundle.getBundle(ICON_KEY); return new Builder().setName(bundle.getCharSequence("name")).setIcon(bundle2 != null ? IconCompat.createFromBundle(bundle2) : null).setUri(bundle.getString("uri")).setKey(bundle.getString("key")).setBot(bundle.getBoolean(IS_BOT_KEY)).setImportant(bundle.getBoolean(IS_IMPORTANT_KEY)).build(); } @NonNull @RequiresApi(22) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public static Person fromPersistableBundle(@NonNull PersistableBundle persistableBundle) { return new Builder().setName(persistableBundle.getString("name")).setUri(persistableBundle.getString("uri")).setKey(persistableBundle.getString("key")).setBot(persistableBundle.getBoolean(IS_BOT_KEY)).setImportant(persistableBundle.getBoolean(IS_IMPORTANT_KEY)).build(); } @Nullable public IconCompat getIcon() { return this.mIcon; } @Nullable public String getKey() { return this.mKey; } @Nullable public CharSequence getName() { return this.mName; } @Nullable public String getUri() { return this.mUri; } public boolean isBot() { return this.mIsBot; } public boolean isImportant() { return this.mIsImportant; } @NonNull @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public String resolveToLegacyUri() { String str = this.mUri; if (str != null) { return str; } if (this.mName == null) { return ""; } StringBuilder P = a.P("name:"); P.append((Object) this.mName); return P.toString(); } @NonNull @RequiresApi(28) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public android.app.Person toAndroidPerson() { return new Person.Builder().setName(getName()).setIcon(getIcon() != null ? getIcon().toIcon() : null).setUri(getUri()).setKey(getKey()).setBot(isBot()).setImportant(isImportant()).build(); } @NonNull public Builder toBuilder() { return new Builder(this); } @NonNull public Bundle toBundle() { Bundle bundle = new Bundle(); bundle.putCharSequence("name", this.mName); IconCompat iconCompat = this.mIcon; bundle.putBundle(ICON_KEY, iconCompat != null ? iconCompat.toBundle() : null); bundle.putString("uri", this.mUri); bundle.putString("key", this.mKey); bundle.putBoolean(IS_BOT_KEY, this.mIsBot); bundle.putBoolean(IS_IMPORTANT_KEY, this.mIsImportant); return bundle; } @NonNull @RequiresApi(22) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public PersistableBundle toPersistableBundle() { PersistableBundle persistableBundle = new PersistableBundle(); CharSequence charSequence = this.mName; persistableBundle.putString("name", charSequence != null ? charSequence.toString() : null); persistableBundle.putString("uri", this.mUri); persistableBundle.putString("key", this.mKey); persistableBundle.putBoolean(IS_BOT_KEY, this.mIsBot); persistableBundle.putBoolean(IS_IMPORTANT_KEY, this.mIsImportant); return persistableBundle; } }