@ -81,7 +81,9 @@ using android::vold::BindMount;
using android : : vold : : CreateDir ;
using android : : vold : : CreateDir ;
using android : : vold : : DeleteDirContents ;
using android : : vold : : DeleteDirContents ;
using android : : vold : : DeleteDirContentsAndDir ;
using android : : vold : : DeleteDirContentsAndDir ;
using android : : vold : : PrepareDirsFromRoot ;
using android : : vold : : IsFilesystemSupported ;
using android : : vold : : PrepareAndroidDirs ;
using android : : vold : : PrepareAppDirsFromRoot ;
using android : : vold : : PrivateVolume ;
using android : : vold : : PrivateVolume ;
using android : : vold : : Symlink ;
using android : : vold : : Symlink ;
using android : : vold : : Unlink ;
using android : : vold : : Unlink ;
@ -822,6 +824,29 @@ int VolumeManager::unmountAll() {
return 0 ;
return 0 ;
}
}
static gid_t getAppDirGid ( const std : : string & appDir ) {
// Create app-specific dirs with the correct UID/GID
gid_t gid = AID_MEDIA_RW ;
if ( ! IsFilesystemSupported ( " sdcardfs " ) ) {
if ( appDir = = android : : vold : : kAppDataDir ) {
gid = AID_EXT_DATA_RW ;
} else if ( appDir = = android : : vold : : kAppObbDir ) {
gid = AID_EXT_OBB_RW ;
} else if ( appDir = = android : : vold : : kAppMediaDir ) {
gid = AID_MEDIA_RW ;
} else {
gid = AID_MEDIA_RW ;
}
}
return gid ;
}
static bool isValidAppDirRoot ( const std : : string & appDirRoot ) {
return appDirRoot = = android : : vold : : kAppDataDir | | appDirRoot = = android : : vold : : kAppMediaDir | |
appDirRoot = = android : : vold : : kAppObbDir ;
}
int VolumeManager : : setupAppDir ( const std : : string & path , const std : : string & appDirRoot ,
int VolumeManager : : setupAppDir ( const std : : string & path , const std : : string & appDirRoot ,
int32_t appUid ) {
int32_t appUid ) {
// Only offer to create directories for paths managed by vold
// Only offer to create directories for paths managed by vold
@ -868,14 +893,25 @@ int VolumeManager::setupAppDir(const std::string& path, const std::string& appDi
const std : : string lowerAppDirRoot =
const std : : string lowerAppDirRoot =
volume - > getInternalPath ( ) + appDirRoot . substr ( volume - > getPath ( ) . length ( ) ) ;
volume - > getInternalPath ( ) + appDirRoot . substr ( volume - > getPath ( ) . length ( ) ) ;
// First create the root which holds app dirs, if needed.
// Do some sanity checking on the app dir (relative from root)
int ret = PrepareDirsFromRoot ( lowerAppDirRoot , volume - > getInternalPath ( ) , 0771 , AID_MEDIA_RW ,
const std : : string volumeRoot = volume - > getRootPath ( ) ; // eg /data/media/0
AID_MEDIA_RW ) ;
// eg, if lowerAppDirRoot = /data/media/0/Android/data, this is /Android/data
const std : : string relativeAppRoot = lowerAppDirRoot . substr ( volumeRoot . length ( ) ) ;
if ( ! isValidAppDirRoot ( relativeAppRoot ) ) {
LOG ( ERROR ) < < path < < " is not a valid application directory. " ;
return - EINVAL ;
}
// Make sure the Android/ directories exist and are setup correctly
int ret = PrepareAndroidDirs ( volumeRoot ) ;
if ( ret ! = 0 ) {
if ( ret ! = 0 ) {
LOG ( ERROR ) < < " Failed to prepare Android/ directories. " ;
return ret ;
return ret ;
}
}
// Then, create app-specific dirs with the correct UID/GID
return PrepareDirsFromRoot ( lowerPath , lowerAppDirRoot , 0770 , appUid , AID_MEDIA_RW ) ;
gid_t gid = getAppDirGid ( relativeAppRoot ) ;
return PrepareAppDirsFromRoot ( lowerPath , lowerAppDirRoot , 0770 , appUid , gid ) ;
}
}
int VolumeManager : : createObb ( const std : : string & sourcePath , const std : : string & sourceKey ,
int VolumeManager : : createObb ( const std : : string & sourcePath , const std : : string & sourceKey ,