Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 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 | |
Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 20 | import android.mtp.MtpConstants; |
Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 21 | |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 22 | class MtpDeviceRecord { |
| 23 | public final int deviceId; |
| 24 | public final String name; |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 25 | public final @Nullable String deviceKey; |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 26 | public final boolean opened; |
| 27 | public final MtpRoot[] roots; |
Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 28 | public final @Nullable int[] operationsSupported; |
| 29 | public final @Nullable int[] eventsSupported; |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 30 | |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 31 | MtpDeviceRecord(int deviceId, String name, @Nullable String deviceKey, boolean opened, |
| 32 | MtpRoot[] roots, @Nullable int[] operationsSupported, |
| 33 | @Nullable int[] eventsSupported) { |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 34 | this.deviceId = deviceId; |
| 35 | this.name = name; |
| 36 | this.opened = opened; |
| 37 | this.roots = roots; |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 38 | this.deviceKey = deviceKey; |
Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 39 | this.operationsSupported = operationsSupported; |
Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 40 | this.eventsSupported = eventsSupported; |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 41 | } |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 42 | |
| 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) { |
Daichi Hirono | 77a1c656 | 2016-03-28 14:37:12 +0900 | [diff] [blame] | 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; |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static boolean isWritingSupported(@Nullable int[] supportedList) { |
| 71 | return isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT_INFO) && |
| 72 | isSupported(supportedList, MtpConstants.OPERATION_SEND_OBJECT); |
| 73 | } |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 74 | } |