blob: 393c4de89ea4e3a8940f57b0da651e6bdfb6d653 [file] [log] [blame]
Daichi Hirono20754c52015-12-15 18:52:26 +09001/*
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
17package com.android.mtp;
18
Daichi Hirono148954a2016-01-21 19:55:45 +090019import android.annotation.Nullable;
Daichi Hirono0f325372016-02-21 15:50:30 +090020import android.mtp.MtpConstants;
Daichi Hirono148954a2016-01-21 19:55:45 +090021
Daichi Hirono20754c52015-12-15 18:52:26 +090022class MtpDeviceRecord {
23 public final int deviceId;
24 public final String name;
Daichi Hironoebd24052016-02-06 21:05:57 +090025 public final @Nullable String deviceKey;
Daichi Hirono20754c52015-12-15 18:52:26 +090026 public final boolean opened;
27 public final MtpRoot[] roots;
Daichi Hirono148954a2016-01-21 19:55:45 +090028 public final @Nullable int[] operationsSupported;
29 public final @Nullable int[] eventsSupported;
Daichi Hirono20754c52015-12-15 18:52:26 +090030
Daichi Hironoebd24052016-02-06 21:05:57 +090031 MtpDeviceRecord(int deviceId, String name, @Nullable String deviceKey, boolean opened,
32 MtpRoot[] roots, @Nullable int[] operationsSupported,
33 @Nullable int[] eventsSupported) {
Daichi Hirono20754c52015-12-15 18:52:26 +090034 this.deviceId = deviceId;
35 this.name = name;
36 this.opened = opened;
37 this.roots = roots;
Daichi Hironoebd24052016-02-06 21:05:57 +090038 this.deviceKey = deviceKey;
Daichi Hirono1d4779c2016-01-06 16:43:32 +090039 this.operationsSupported = operationsSupported;
Daichi Hirono148954a2016-01-21 19:55:45 +090040 this.eventsSupported = eventsSupported;
Daichi Hirono20754c52015-12-15 18:52:26 +090041 }
Daichi Hirono0f325372016-02-21 15:50:30 +090042
43 /**
44 * Helper method to check operations/events are supported by the device or not.
45 */
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
58 static boolean isPartialReadSupported(@Nullable int[] supportedList, long fileSize) {
59 return fileSize <= 0xffffffffl &&
60 isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT);
61 }
62
63 static boolean isWritingSupported(@Nullable int[] supportedList) {
64 return isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT_INFO) &&
65 isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT);
66 }
Daichi Hirono20754c52015-12-15 18:52:26 +090067}