Home | History | Annotate | Download | only in mtp
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.mtp;
     18 
     19 /**
     20  * This class encapsulates information about an MTP device.
     21  * This corresponds to the DeviceInfo Dataset described in
     22  * section 5.1.1 of the MTP specification.
     23  */
     24 public class MtpDeviceInfo {
     25 
     26     private String mManufacturer;
     27     private String mModel;
     28     private String mVersion;
     29     private String mSerialNumber;
     30     private int[] mOperationsSupported;
     31     private int[] mEventsSupported;
     32 
     33     // only instantiated via JNI
     34     private MtpDeviceInfo() {
     35     }
     36 
     37     /**
     38      * Returns the manufacturer's name for the MTP device
     39      *
     40      * @return the manufacturer name
     41      */
     42     public final String getManufacturer() {
     43         return mManufacturer;
     44     }
     45 
     46     /**
     47      * Returns the model name for the MTP device
     48      *
     49      * @return the model name
     50      */
     51     public final String getModel() {
     52         return mModel;
     53     }
     54 
     55     /**
     56      * Returns the version string the MTP device
     57      *
     58      * @return the device version
     59      */
     60     public final String getVersion() {
     61         return mVersion;
     62     }
     63 
     64     /**
     65      * Returns the unique serial number for the MTP device
     66      *
     67      * @return the serial number
     68      */
     69     public final String getSerialNumber() {
     70         return mSerialNumber;
     71     }
     72 
     73     /**
     74      * Returns operation code supported by the device.
     75      *
     76      * @return supported operation code. Can be null if device does not provide the property.
     77      * @see MtpConstants#OPERATION_GET_DEVICE_INFO
     78      * @see MtpConstants#OPERATION_OPEN_SESSION
     79      * @see MtpConstants#OPERATION_CLOSE_SESSION
     80      * @see MtpConstants#OPERATION_GET_STORAGE_I_DS
     81      * @see MtpConstants#OPERATION_GET_STORAGE_INFO
     82      * @see MtpConstants#OPERATION_GET_NUM_OBJECTS
     83      * @see MtpConstants#OPERATION_GET_OBJECT_HANDLES
     84      * @see MtpConstants#OPERATION_GET_OBJECT_INFO
     85      * @see MtpConstants#OPERATION_GET_OBJECT
     86      * @see MtpConstants#OPERATION_GET_THUMB
     87      * @see MtpConstants#OPERATION_DELETE_OBJECT
     88      * @see MtpConstants#OPERATION_SEND_OBJECT_INFO
     89      * @see MtpConstants#OPERATION_SEND_OBJECT
     90      * @see MtpConstants#OPERATION_INITIATE_CAPTURE
     91      * @see MtpConstants#OPERATION_FORMAT_STORE
     92      * @see MtpConstants#OPERATION_RESET_DEVICE
     93      * @see MtpConstants#OPERATION_SELF_TEST
     94      * @see MtpConstants#OPERATION_SET_OBJECT_PROTECTION
     95      * @see MtpConstants#OPERATION_POWER_DOWN
     96      * @see MtpConstants#OPERATION_GET_DEVICE_PROP_DESC
     97      * @see MtpConstants#OPERATION_GET_DEVICE_PROP_VALUE
     98      * @see MtpConstants#OPERATION_SET_DEVICE_PROP_VALUE
     99      * @see MtpConstants#OPERATION_RESET_DEVICE_PROP_VALUE
    100      * @see MtpConstants#OPERATION_TERMINATE_OPEN_CAPTURE
    101      * @see MtpConstants#OPERATION_MOVE_OBJECT
    102      * @see MtpConstants#OPERATION_COPY_OBJECT
    103      * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT
    104      * @see MtpConstants#OPERATION_INITIATE_OPEN_CAPTURE
    105      * @see MtpConstants#OPERATION_GET_OBJECT_PROPS_SUPPORTED
    106      * @see MtpConstants#OPERATION_GET_OBJECT_PROP_DESC
    107      * @see MtpConstants#OPERATION_GET_OBJECT_PROP_VALUE
    108      * @see MtpConstants#OPERATION_SET_OBJECT_PROP_VALUE
    109      * @see MtpConstants#OPERATION_GET_OBJECT_REFERENCES
    110      * @see MtpConstants#OPERATION_SET_OBJECT_REFERENCES
    111      * @see MtpConstants#OPERATION_SKIP
    112      */
    113     public final int[] getOperationsSupported() {
    114         return mOperationsSupported;
    115     }
    116 
    117     /**
    118      * Returns event code supported by the device.
    119      *
    120      * @return supported event code. Can be null if device does not provide the property.
    121      * @see MtpEvent#EVENT_UNDEFINED
    122      * @see MtpEvent#EVENT_CANCEL_TRANSACTION
    123      * @see MtpEvent#EVENT_OBJECT_ADDED
    124      * @see MtpEvent#EVENT_OBJECT_REMOVED
    125      * @see MtpEvent#EVENT_STORE_ADDED
    126      * @see MtpEvent#EVENT_STORE_REMOVED
    127      * @see MtpEvent#EVENT_DEVICE_PROP_CHANGED
    128      * @see MtpEvent#EVENT_OBJECT_INFO_CHANGED
    129      * @see MtpEvent#EVENT_DEVICE_INFO_CHANGED
    130      * @see MtpEvent#EVENT_REQUEST_OBJECT_TRANSFER
    131      * @see MtpEvent#EVENT_STORE_FULL
    132      * @see MtpEvent#EVENT_DEVICE_RESET
    133      * @see MtpEvent#EVENT_STORAGE_INFO_CHANGED
    134      * @see MtpEvent#EVENT_CAPTURE_COMPLETE
    135      * @see MtpEvent#EVENT_UNREPORTED_STATUS
    136      * @see MtpEvent#EVENT_OBJECT_PROP_CHANGED
    137      * @see MtpEvent#EVENT_OBJECT_PROP_DESC_CHANGED
    138      * @see MtpEvent#EVENT_OBJECT_REFERENCES_CHANGED
    139      */
    140     public final int[] getEventsSupported() {
    141         return mEventsSupported;
    142     }
    143 
    144     /**
    145      * Returns if the given operation is supported by the device or not.
    146      * @param code Operation code.
    147      * @return If the given operation is supported by the device or not.
    148      */
    149     public boolean isOperationSupported(int code) {
    150         return isSupported(mOperationsSupported, code);
    151     }
    152 
    153     /**
    154      * Returns if the given event is supported by the device or not.
    155      * @param code Event code.
    156      * @return If the given event is supported by the device or not.
    157      */
    158     public boolean isEventSupported(int code) {
    159         return isSupported(mEventsSupported, code);
    160     }
    161 
    162     /**
    163      * Returns if the code set contains code.
    164      * @hide
    165      */
    166     private static boolean isSupported(int[] set, int code) {
    167         for (final int element : set) {
    168             if (element == code) {
    169                 return true;
    170             }
    171         }
    172         return false;
    173     }
    174 }
    175