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