• 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.mtp.MtpStorageInfo;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 
23 class MtpRoot {
24     final int mDeviceId;
25     final int mStorageId;
26     final String mDescription;
27     final long mFreeSpace;
28     final long mMaxCapacity;
29     final String mVolumeIdentifier;
30 
31     @VisibleForTesting
MtpRoot(int deviceId, int storageId, String description, long freeSpace, long maxCapacity, String volumeIdentifier)32     MtpRoot(int deviceId,
33             int storageId,
34             String description,
35             long freeSpace,
36             long maxCapacity,
37             String volumeIdentifier) {
38         mDeviceId = deviceId;
39         mStorageId = storageId;
40         mDescription = description;
41         mFreeSpace = freeSpace;
42         mMaxCapacity = maxCapacity;
43         mVolumeIdentifier = volumeIdentifier;
44     }
45 
MtpRoot(int deviceId, MtpStorageInfo storageInfo)46     MtpRoot(int deviceId, MtpStorageInfo storageInfo) {
47         mDeviceId = deviceId;
48         mStorageId = storageInfo.getStorageId();
49         mDescription = storageInfo.getDescription();
50         mFreeSpace = storageInfo.getFreeSpace();
51         mMaxCapacity = storageInfo.getMaxCapacity();
52         mVolumeIdentifier = storageInfo.getVolumeIdentifier();
53     }
54 
55     @Override
equals(Object object)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
hashCode()69     public int hashCode() {
70         return mDeviceId ^ mStorageId ^ mDescription.hashCode() ^
71                 ((int) mFreeSpace) ^ ((int) mMaxCapacity) ^ mVolumeIdentifier.hashCode();
72     }
73 
74     @Override
toString()75     public String toString() {
76         return "MtpRoot{Name: " + mDescription + "}";
77     }
78 }
79