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 import java.util.ArrayList;
     20 import java.util.List;
     21 
     22 /**
     23  * Encapsulates the ObjectPropList dataset used by the GetObjectPropList command.
     24  * The fields of this class are read by JNI code in android_media_MtpDatabase.cpp
     25  */
     26 
     27 class MtpPropertyList {
     28 
     29     // list of object handles (first field in quadruplet)
     30     private List<Integer> mObjectHandles;
     31     // list of object property codes (second field in quadruplet)
     32     private List<Integer> mPropertyCodes;
     33     // list of data type codes (third field in quadruplet)
     34     private List<Integer> mDataTypes;
     35     // list of long int property values (fourth field in quadruplet, when value is integer type)
     36     private List<Long> mLongValues;
     37     // list of long int property values (fourth field in quadruplet, when value is string type)
     38     private List<String> mStringValues;
     39 
     40     // Return value of this operation
     41     private int mCode;
     42 
     43     public MtpPropertyList(int code) {
     44         mCode = code;
     45         mObjectHandles = new ArrayList<>();
     46         mPropertyCodes = new ArrayList<>();
     47         mDataTypes = new ArrayList<>();
     48         mLongValues = new ArrayList<>();
     49         mStringValues = new ArrayList<>();
     50     }
     51 
     52     public void append(int handle, int property, int type, long value) {
     53         mObjectHandles.add(handle);
     54         mPropertyCodes.add(property);
     55         mDataTypes.add(type);
     56         mLongValues.add(value);
     57         mStringValues.add(null);
     58     }
     59 
     60     public void append(int handle, int property, String value) {
     61         mObjectHandles.add(handle);
     62         mPropertyCodes.add(property);
     63         mDataTypes.add(MtpConstants.TYPE_STR);
     64         mStringValues.add(value);
     65         mLongValues.add(0L);
     66     }
     67 
     68     public int getCode() {
     69         return mCode;
     70     }
     71 
     72     public int getCount() {
     73         return mObjectHandles.size();
     74     }
     75 
     76     public int[] getObjectHandles() {
     77         return mObjectHandles.stream().mapToInt(Integer::intValue).toArray();
     78     }
     79 
     80     public int[] getPropertyCodes() {
     81         return mPropertyCodes.stream().mapToInt(Integer::intValue).toArray();
     82     }
     83 
     84     public int[] getDataTypes() {
     85         return mDataTypes.stream().mapToInt(Integer::intValue).toArray();
     86     }
     87 
     88     public long[] getLongValues() {
     89         return mLongValues.stream().mapToLong(Long::longValue).toArray();
     90     }
     91 
     92     public String[] getStringValues() {
     93         return mStringValues.toArray(new String[0]);
     94     }
     95 }
     96