Daichi Hirono | 50d17aa | 2015-07-28 15:49:01 +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 | |
| 19 | import android.mtp.MtpStorageInfo; |
| 20 | |
Daichi Hirono | 0910956 | 2015-07-28 20:57:05 +0900 | [diff] [blame] | 21 | import com.android.internal.annotations.VisibleForTesting; |
| 22 | |
Daichi Hirono | 50d17aa | 2015-07-28 15:49:01 +0900 | [diff] [blame] | 23 | class MtpRoot { |
Daichi Hirono | 8b9024f | 2015-08-12 12:59:09 +0900 | [diff] [blame] | 24 | final int mDeviceId; |
Daichi Hirono | e5323b7 | 2015-07-29 16:10:47 +0900 | [diff] [blame] | 25 | final int mStorageId; |
Daichi Hirono | 50d17aa | 2015-07-28 15:49:01 +0900 | [diff] [blame] | 26 | final String mDescription; |
| 27 | final long mFreeSpace; |
| 28 | final long mMaxCapacity; |
| 29 | final String mVolumeIdentifier; |
| 30 | |
Daichi Hirono | 0910956 | 2015-07-28 20:57:05 +0900 | [diff] [blame] | 31 | @VisibleForTesting |
Daichi Hirono | 8b9024f | 2015-08-12 12:59:09 +0900 | [diff] [blame] | 32 | MtpRoot(int deviceId, |
| 33 | int storageId, |
Daichi Hirono | 0910956 | 2015-07-28 20:57:05 +0900 | [diff] [blame] | 34 | String description, |
| 35 | long freeSpace, |
| 36 | long maxCapacity, |
| 37 | String volumeIdentifier) { |
Daichi Hirono | 8b9024f | 2015-08-12 12:59:09 +0900 | [diff] [blame] | 38 | mDeviceId = deviceId; |
| 39 | mStorageId = storageId; |
| 40 | mDescription = description; |
| 41 | mFreeSpace = freeSpace; |
| 42 | mMaxCapacity = maxCapacity; |
| 43 | mVolumeIdentifier = volumeIdentifier; |
Daichi Hirono | 0910956 | 2015-07-28 20:57:05 +0900 | [diff] [blame] | 44 | } |
| 45 | |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 46 | MtpRoot(int deviceId, MtpStorageInfo storageInfo) { |
Daichi Hirono | 8b9024f | 2015-08-12 12:59:09 +0900 | [diff] [blame] | 47 | mDeviceId = deviceId; |
Daichi Hirono | 50d17aa | 2015-07-28 15:49:01 +0900 | [diff] [blame] | 48 | mStorageId = storageInfo.getStorageId(); |
| 49 | mDescription = storageInfo.getDescription(); |
| 50 | mFreeSpace = storageInfo.getFreeSpace(); |
| 51 | mMaxCapacity = storageInfo.getMaxCapacity(); |
Daichi Hirono | 8b9024f | 2015-08-12 12:59:09 +0900 | [diff] [blame] | 52 | mVolumeIdentifier = storageInfo.getVolumeIdentifier(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object object) { |
| 57 | if (!(object instanceof MtpRoot)) |
| 58 | return false; |
| 59 | final MtpRoot other = (MtpRoot) object; |
| 60 | return mDeviceId == other.mDeviceId && |
| 61 | mStorageId == other.mStorageId && |
| 62 | mDescription.equals(other.mDescription) && |
| 63 | mFreeSpace == other.mFreeSpace && |
| 64 | mMaxCapacity == other.mMaxCapacity && |
| 65 | mVolumeIdentifier.equals(other.mVolumeIdentifier); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 70 | return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^ |
Daichi Hirono | 17c8d8b | 2015-10-12 11:28:46 -0700 | [diff] [blame] | 71 | ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode(); |
| 72 | } |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 73 | |
Daichi Hirono | 17c8d8b | 2015-10-12 11:28:46 -0700 | [diff] [blame] | 74 | @Override |
| 75 | public String toString() { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 76 | return "MtpRoot{Name: " + mDescription + "}"; |
Daichi Hirono | 50d17aa | 2015-07-28 15:49:01 +0900 | [diff] [blame] | 77 | } |
| 78 | } |