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