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  * Encapsulates the ObjectPropList dataset used by the GetObjectPropList command.
21  * The fields of this class are read by JNI code in android_media_MtpDatabase.cpp
22  */
23 
24 class MtpPropertyList {
25 
26     // number of results returned
27     private int             mCount;
28     // maximum number of results
29     private final int       mMaxCount;
30     // result code for GetObjectPropList
31     public int              mResult;
32     // list of object handles (first field in quadruplet)
33     public final int[]      mObjectHandles;
34     // list of object propery codes (second field in quadruplet)
35     public final int[]      mPropertyCodes;
36     // list of data type codes (third field in quadruplet)
37     public final int[]     mDataTypes;
38     // list of long int property values (fourth field in quadruplet, when value is integer type)
39     public long[]     mLongValues;
40     // list of long int property values (fourth field in quadruplet, when value is string type)
41     public String[]   mStringValues;
42 
43     // constructor only called from MtpDatabase
MtpPropertyList(int maxCount, int result)44     public MtpPropertyList(int maxCount, int result) {
45         mMaxCount = maxCount;
46         mResult = result;
47         mObjectHandles = new int[maxCount];
48         mPropertyCodes = new int[maxCount];
49         mDataTypes = new int[maxCount];
50         // mLongValues and mStringValues are created lazily since both might not be necessary
51     }
52 
append(int handle, int property, int type, long value)53     public void append(int handle, int property, int type, long value) {
54         int index = mCount++;
55         if (mLongValues == null) {
56             mLongValues = new long[mMaxCount];
57         }
58         mObjectHandles[index] = handle;
59         mPropertyCodes[index] = property;
60         mDataTypes[index] = type;
61         mLongValues[index] = value;
62     }
63 
append(int handle, int property, String value)64     public void append(int handle, int property, String value) {
65         int index = mCount++;
66         if (mStringValues == null) {
67             mStringValues = new String[mMaxCount];
68         }
69         mObjectHandles[index] = handle;
70         mPropertyCodes[index] = property;
71         mDataTypes[index] = MtpConstants.TYPE_STR;
72         mStringValues[index] = value;
73     }
74 
setResult(int result)75     public void setResult(int result) {
76         mResult = result;
77     }
78 }
79