Add @NonNull / @Nullable annotations to android.mtp API.

BUG=26758882

Change-Id: Ic86d2253114b487d68a069f3e63f19b200d6cb97
This commit is contained in:
Daichi Hirono
2016-07-07 17:36:26 +09:00
parent ae76412b99
commit 0639fe0aa9
3 changed files with 32 additions and 15 deletions

View File

@@ -16,6 +16,8 @@
package android.mtp;
import android.annotation.NonNull;
/**
* This class encapsulates information about an MTP device.
* This corresponds to the DeviceInfo Dataset described in
@@ -39,7 +41,7 @@ public class MtpDeviceInfo {
*
* @return the manufacturer name
*/
public final String getManufacturer() {
public final @NonNull String getManufacturer() {
return mManufacturer;
}
@@ -48,7 +50,7 @@ public class MtpDeviceInfo {
*
* @return the model name
*/
public final String getModel() {
public final @NonNull String getModel() {
return mModel;
}
@@ -57,7 +59,7 @@ public class MtpDeviceInfo {
*
* @return the device version
*/
public final String getVersion() {
public final @NonNull String getVersion() {
return mVersion;
}
@@ -66,7 +68,7 @@ public class MtpDeviceInfo {
*
* @return the serial number
*/
public final String getSerialNumber() {
public final @NonNull String getSerialNumber() {
return mSerialNumber;
}
@@ -110,7 +112,7 @@ public class MtpDeviceInfo {
* @see MtpConstants#OPERATION_SET_OBJECT_REFERENCES
* @see MtpConstants#OPERATION_SKIP
*/
public final int[] getOperationsSupported() {
public final @NonNull int[] getOperationsSupported() {
return mOperationsSupported;
}
@@ -137,7 +139,7 @@ public class MtpDeviceInfo {
* @see MtpEvent#EVENT_OBJECT_PROP_DESC_CHANGED
* @see MtpEvent#EVENT_OBJECT_REFERENCES_CHANGED
*/
public final int[] getEventsSupported() {
public final @NonNull int[] getEventsSupported() {
return mEventsSupported;
}
@@ -163,7 +165,7 @@ public class MtpDeviceInfo {
* Returns if the code set contains code.
* @hide
*/
private static boolean isSupported(int[] set, int code) {
private static boolean isSupported(@NonNull int[] set, int code) {
for (final int element : set) {
if (element == code) {
return true;

View File

@@ -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;
}

View File

@@ -16,6 +16,8 @@
package android.mtp;
import android.annotation.NonNull;
/**
* This class encapsulates information about a storage unit on an MTP device.
* This corresponds to the StorageInfo Dataset described in
@@ -68,7 +70,7 @@ public final class MtpStorageInfo {
*
* @return the storage unit description
*/
public final String getDescription() {
public final @NonNull String getDescription() {
return mDescription;
}
@@ -77,7 +79,7 @@ public final class MtpStorageInfo {
*
* @return the storage volume identifier
*/
public final String getVolumeIdentifier() {
public final @NonNull String getVolumeIdentifier() {
return mVolumeIdentifier;
}
}