blob: 8530aaff7f958793d66f5252813be01249e3a17e [file] [log] [blame]
Daichi Hirono50d17aa2015-07-28 15:49:01 +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
19import android.mtp.MtpStorageInfo;
20
Daichi Hirono09109562015-07-28 20:57:05 +090021import com.android.internal.annotations.VisibleForTesting;
22
Daichi Hirono50d17aa2015-07-28 15:49:01 +090023class MtpRoot {
Daichi Hirono8b9024f2015-08-12 12:59:09 +090024 final int mDeviceId;
Daichi Hironoe5323b72015-07-29 16:10:47 +090025 final int mStorageId;
Daichi Hirono50d17aa2015-07-28 15:49:01 +090026 final String mDescription;
27 final long mFreeSpace;
28 final long mMaxCapacity;
29 final String mVolumeIdentifier;
30
Daichi Hirono09109562015-07-28 20:57:05 +090031 @VisibleForTesting
Daichi Hirono8b9024f2015-08-12 12:59:09 +090032 MtpRoot(int deviceId,
33 int storageId,
Daichi Hirono09109562015-07-28 20:57:05 +090034 String description,
35 long freeSpace,
36 long maxCapacity,
37 String volumeIdentifier) {
Daichi Hirono8b9024f2015-08-12 12:59:09 +090038 mDeviceId = deviceId;
39 mStorageId = storageId;
40 mDescription = description;
41 mFreeSpace = freeSpace;
42 mMaxCapacity = maxCapacity;
43 mVolumeIdentifier = volumeIdentifier;
Daichi Hirono09109562015-07-28 20:57:05 +090044 }
45
Daichi Hironof83ccbd2016-02-04 16:58:55 +090046 MtpRoot(int deviceId, MtpStorageInfo storageInfo) {
Daichi Hirono8b9024f2015-08-12 12:59:09 +090047 mDeviceId = deviceId;
Daichi Hirono50d17aa2015-07-28 15:49:01 +090048 mStorageId = storageInfo.getStorageId();
49 mDescription = storageInfo.getDescription();
50 mFreeSpace = storageInfo.getFreeSpace();
51 mMaxCapacity = storageInfo.getMaxCapacity();
Daichi Hirono8b9024f2015-08-12 12:59:09 +090052 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 Hironof83ccbd2016-02-04 16:58:55 +090070 return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^
Daichi Hirono17c8d8b2015-10-12 11:28:46 -070071 ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode();
72 }
Daichi Hironof83ccbd2016-02-04 16:58:55 +090073
Daichi Hirono17c8d8b2015-10-12 11:28:46 -070074 @Override
75 public String toString() {
Daichi Hironof83ccbd2016-02-04 16:58:55 +090076 return "MtpRoot{Name: " + mDescription + "}";
Daichi Hirono50d17aa2015-07-28 15:49:01 +090077 }
78}