• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 com.android.mtp;
18 
19 import android.annotation.Nullable;
20 import android.mtp.MtpConstants;
21 
22 class MtpDeviceRecord {
23     public final int deviceId;
24     public final String name;
25     public final @Nullable String deviceKey;
26     public final boolean opened;
27     public final MtpRoot[] roots;
28     public final @Nullable int[] operationsSupported;
29     public final @Nullable int[] eventsSupported;
30 
MtpDeviceRecord(int deviceId, String name, @Nullable String deviceKey, boolean opened, MtpRoot[] roots, @Nullable int[] operationsSupported, @Nullable int[] eventsSupported)31     MtpDeviceRecord(int deviceId, String name, @Nullable String deviceKey, boolean opened,
32                     MtpRoot[] roots, @Nullable int[] operationsSupported,
33                     @Nullable int[] eventsSupported) {
34         this.deviceId = deviceId;
35         this.name = name;
36         this.opened = opened;
37         this.roots = roots;
38         this.deviceKey = deviceKey;
39         this.operationsSupported = operationsSupported;
40         this.eventsSupported = eventsSupported;
41     }
42 
43     /**
44      * Helper method to check operations/events are supported by the device or not.
45      */
isSupported(@ullable int[] supportedList, int code)46     static boolean isSupported(@Nullable int[] supportedList, int code) {
47         if (supportedList == null) {
48             return false;
49         }
50         for (int i = 0; i < supportedList.length; i++) {
51             if (supportedList[i] == code) {
52                 return true;
53             }
54         }
55         return false;
56     }
57 
isPartialReadSupported(@ullable int[] supportedList, long fileSize)58     static boolean isPartialReadSupported(@Nullable int[] supportedList, long fileSize) {
59         if (isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT_64)) {
60             return true;
61         }
62         if (0 <= fileSize &&
63                 fileSize <= 0xffffffffL &&
64                 isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT)) {
65             return true;
66         }
67         return false;
68     }
69 
isWritingSupported(@ullable int[] supportedList)70     static boolean isWritingSupported(@Nullable int[] supportedList) {
71         return isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT_INFO) &&
72                 isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT);
73     }
74 }
75