diff options
Diffstat (limited to 'media/java/android/mtp/MtpObjectInfo.java')
-rw-r--r-- | media/java/android/mtp/MtpObjectInfo.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/media/java/android/mtp/MtpObjectInfo.java b/media/java/android/mtp/MtpObjectInfo.java index 02092b177fe0..35d8dfbad84a 100644 --- a/media/java/android/mtp/MtpObjectInfo.java +++ b/media/java/android/mtp/MtpObjectInfo.java @@ -16,8 +16,13 @@ package android.mtp; +import android.annotation.NonNull; +import android.os.Build; + import com.android.internal.util.Preconditions; +import dalvik.system.VMRuntime; + /** * This class encapsulates information about an object on an MTP device. * This corresponds to the ObjectInfo Dataset described in @@ -40,10 +45,10 @@ public final class MtpObjectInfo { private int mAssociationType; private int mAssociationDesc; private int mSequenceNumber; - private String mName; + private String mName = ""; private long mDateCreated; private long mDateModified; - private String mKeywords; + private String mKeywords = ""; // only instantiated via JNI or via a builder private MtpObjectInfo() { @@ -311,7 +316,7 @@ public final class MtpObjectInfo { * * @return the object's name */ - public final String getName() { + public final @NonNull String getName() { return mName; } @@ -340,7 +345,7 @@ public final class MtpObjectInfo { * * @return the object's keyword list */ - public final String getKeywords() { + public final @NonNull String getKeywords() { return mKeywords; } @@ -435,12 +440,20 @@ public final class MtpObjectInfo { return this; } - public Builder setKeywords(String value) { + public Builder setKeywords(@NonNull String value) { + if (VMRuntime.getRuntime().getTargetSdkVersion() > Build.VERSION_CODES.N_MR1) { + Preconditions.checkNotNull(value); + } else if (value == null) { + // Before N_MR1 we accept null value and it was regarded as an empty string in + // MtpDevice#sendObjectInfo. + value = ""; + } mObjectInfo.mKeywords = value; return this; } - public Builder setName(String value) { + public Builder setName(@NonNull String value) { + Preconditions.checkNotNull(value); mObjectInfo.mName = value; return this; } |