Jeff Sharkey 4887789e44 Progress towards dynamic storage support.
Storage devices are no longer hard-coded, and instead bubble up from
whatever Disk and VolumeBase that vold uncovered, turning into
sibling Java objects in MountService.  We now treat vold events as
the source-of-truth for state, and synchronize our state by asking
vold to "reset" whenever we reconnect.

We've now moved to a model where all storage devices are mounted in
the root mount namespace (user boundaries protected with GIDs), so
we no longer need app-to-vold path translation.  This also means that
zygote only needs to bind mount the user-specific /mnt/user/n/ path
onto /storage/self/ to make legacy paths like /sdcard work.  This
grealy simplifies a lot of system code.

Many parts of the platform depend on a primary storage device always
being present, so we hack together a stub StorageVolume when vold
doesn't have a volume ready yet.

StorageVolume isn't really a volume anymore; it's the user-specific
view onto a volume, so MountService now filters and builds them
based on the calling user.  StorageVolume is now immutable, making
it easier to reason about.

Environment now builds all of its paths dynamically based on active
volumes.  Adds utility methods to turn int types and flags into
user-readable strings for debugging purposes.

Remove UMS sharing support for now, since no current devices support
it; MTP is the recommended solution going forward because it offers
better multi-user support.

Simplify unmount logic, since vold will now gladly trigger EJECTING
broadcast and kill stubborn processes.

Bug: 19993667
Change-Id: I9842280e61974c91bae15d764e386969aedcd338
2015-03-30 19:46:23 -07:00

114 lines
3.1 KiB
Java

/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.mtp;
import android.content.Context;
import android.os.storage.StorageVolume;
/**
* This class represents a storage unit on an MTP device.
* Used only for MTP support in USB responder mode.
* MtpStorageInfo is used in MTP host mode
*
* @hide
*/
public class MtpStorage {
private final int mStorageId;
private final String mPath;
private final String mDescription;
private final long mReserveSpace;
private final boolean mRemovable;
private final long mMaxFileSize;
public MtpStorage(StorageVolume volume, Context context) {
mStorageId = volume.getStorageId();
mPath = volume.getPath();
mDescription = context.getResources().getString(volume.getDescriptionId());
mReserveSpace = volume.getMtpReserveSpace() * 1024L * 1024L;
mRemovable = volume.isRemovable();
mMaxFileSize = volume.getMaxFileSize();
}
/**
* Returns the storage ID for the storage unit
*
* @return the storage ID
*/
public final int getStorageId() {
return mStorageId;
}
/**
* Generates a storage ID for storage of given index.
* Index 0 is for primary external storage
*
* @return the storage ID
*/
public static int getStorageIdForIndex(int index) {
// storage ID is 0x00010001 for primary storage,
// then 0x00020001, 0x00030001, etc. for secondary storages
return ((index + 1) << 16) + 1;
}
/**
* Returns the file path for the storage unit's storage in the file system
*
* @return the storage file path
*/
public final String getPath() {
return mPath;
}
/**
* Returns the description string for the storage unit
*
* @return the storage unit description
*/
public final String getDescription() {
return mDescription;
}
/**
* Returns the amount of space to reserve on the storage file system.
* This can be set to a non-zero value to prevent MTP from filling up the entire storage.
*
* @return reserved space in bytes.
*/
public final long getReserveSpace() {
return mReserveSpace;
}
/**
* Returns true if the storage is removable.
*
* @return is removable
*/
public final boolean isRemovable() {
return mRemovable;
}
/**
* Returns maximum file size for the storage, or zero if it is unbounded.
*
* @return maximum file size
*/
public long getMaxFileSize() {
return mMaxFileSize;
}
}