| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.textclassifier; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.UserIdInt; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
|
| 24 |
import com.android.internal.annotations.VisibleForTesting; |
| 25 |
import com.android.internal.annotations.VisibleForTesting.Visibility; |
| 26 |
|
| 27 |
import java.util.Locale; |
| 28 |
import java.util.Objects; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@VisibleForTesting(visibility = Visibility.PACKAGE) |
| 39 |
public final class SystemTextClassifierMetadata implements Parcelable { |
| 40 |
|
| 41 |
|
| 42 |
@NonNull |
| 43 |
private final String mCallingPackageName; |
| 44 |
|
| 45 |
@UserIdInt |
| 46 |
private final int mUserId; |
| 47 |
|
| 48 |
private final boolean mUseDefaultTextClassifier; |
| 49 |
|
| 50 |
public SystemTextClassifierMetadata(@NonNull String packageName, @UserIdInt int userId, |
| 51 |
boolean useDefaultTextClassifier) { |
| 52 |
Objects.requireNonNull(packageName); |
| 53 |
mCallingPackageName = packageName; |
| 54 |
mUserId = userId; |
| 55 |
mUseDefaultTextClassifier = useDefaultTextClassifier; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@UserIdInt |
| 62 |
public int getUserId() { |
| 63 |
return mUserId; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@NonNull |
| 71 |
public String getCallingPackageName() { |
| 72 |
return mCallingPackageName; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public boolean useDefaultTextClassifier() { |
| 79 |
return mUseDefaultTextClassifier; |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
public String toString() { |
| 84 |
return String.format(Locale.US, |
| 85 |
"SystemTextClassifierMetadata {callingPackageName=%s, userId=%d, " |
| 86 |
+ "useDefaultTextClassifier=%b}", |
| 87 |
mCallingPackageName, mUserId, mUseDefaultTextClassifier); |
| 88 |
} |
| 89 |
|
| 90 |
private static SystemTextClassifierMetadata readFromParcel(Parcel in) { |
| 91 |
final String packageName = in.readString(); |
| 92 |
final int userId = in.readInt(); |
| 93 |
final boolean useDefaultTextClassifier = in.readBoolean(); |
| 94 |
return new SystemTextClassifierMetadata(packageName, userId, useDefaultTextClassifier); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public int describeContents() { |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public void writeToParcel(Parcel dest, int flags) { |
| 104 |
dest.writeString(mCallingPackageName); |
| 105 |
dest.writeInt(mUserId); |
| 106 |
dest.writeBoolean(mUseDefaultTextClassifier); |
| 107 |
} |
| 108 |
|
| 109 |
public static final @NonNull Creator<SystemTextClassifierMetadata> CREATOR = |
| 110 |
new Creator<SystemTextClassifierMetadata>() { |
| 111 |
@Override |
| 112 |
public SystemTextClassifierMetadata createFromParcel(Parcel in) { |
| 113 |
return readFromParcel(in); |
| 114 |
} |
| 115 |
|
| 116 |
@Override |
| 117 |
public SystemTextClassifierMetadata[] newArray(int size) { |
| 118 |
return new SystemTextClassifierMetadata[size]; |
| 119 |
} |
| 120 |
}; |
| 121 |
} |