Search in sources :

Example 6 with UserEnvironment

use of android.os.Environment.UserEnvironment in project android_frameworks_base by AOSPA.

the class MountService method mkdirs.

@Override
public int mkdirs(String callingPkg, String appPath) {
    final int userId = UserHandle.getUserId(Binder.getCallingUid());
    final UserEnvironment userEnv = new UserEnvironment(userId);
    // Validate that reported package name belongs to caller
    final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
    appOps.checkPackage(Binder.getCallingUid(), callingPkg);
    File appFile = null;
    try {
        appFile = new File(appPath).getCanonicalFile();
    } catch (IOException e) {
        Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
        return -1;
    }
    // belong to the calling package.
    if (FileUtils.contains(userEnv.buildExternalStorageAppDataDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppObbDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppMediaDirs(callingPkg), appFile)) {
        appPath = appFile.getAbsolutePath();
        if (!appPath.endsWith("/")) {
            appPath = appPath + "/";
        }
        try {
            mConnector.execute("volume", "mkdirs", appPath);
            return 0;
        } catch (NativeDaemonConnectorException e) {
            return e.getCode();
        }
    }
    throw new SecurityException("Invalid mkdirs path: " + appFile);
}
Also used : AppOpsManager(android.app.AppOpsManager) UserEnvironment(android.os.Environment.UserEnvironment) IOException(java.io.IOException) File(java.io.File) AtomicFile(android.util.AtomicFile)

Example 7 with UserEnvironment

use of android.os.Environment.UserEnvironment in project platform_frameworks_base by android.

the class MountService method mkdirs.

@Override
public int mkdirs(String callingPkg, String appPath) {
    final int userId = UserHandle.getUserId(Binder.getCallingUid());
    final UserEnvironment userEnv = new UserEnvironment(userId);
    // Validate that reported package name belongs to caller
    final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
    appOps.checkPackage(Binder.getCallingUid(), callingPkg);
    File appFile = null;
    try {
        appFile = new File(appPath).getCanonicalFile();
    } catch (IOException e) {
        Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
        return -1;
    }
    // belong to the calling package.
    if (FileUtils.contains(userEnv.buildExternalStorageAppDataDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppObbDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppMediaDirs(callingPkg), appFile)) {
        appPath = appFile.getAbsolutePath();
        if (!appPath.endsWith("/")) {
            appPath = appPath + "/";
        }
        try {
            mConnector.execute("volume", "mkdirs", appPath);
            return 0;
        } catch (NativeDaemonConnectorException e) {
            return e.getCode();
        }
    }
    throw new SecurityException("Invalid mkdirs path: " + appFile);
}
Also used : AppOpsManager(android.app.AppOpsManager) UserEnvironment(android.os.Environment.UserEnvironment) IOException(java.io.IOException) File(java.io.File) AtomicFile(android.util.AtomicFile)

Example 8 with UserEnvironment

use of android.os.Environment.UserEnvironment in project android_frameworks_base by crdroidandroid.

the class DiskStatsLoggingService method onStartJob.

@Override
public boolean onStartJob(JobParameters params) {
    // subsequent runs.
    if (!isCharging(this) || !isDumpsysTaskEnabled(getContentResolver())) {
        jobFinished(params, true);
        return false;
    }
    VolumeInfo volume = getPackageManager().getPrimaryStorageCurrentVolume();
    // volume is null if the primary storage is not yet mounted.
    if (volume == null) {
        return false;
    }
    AppCollector collector = new AppCollector(this, volume);
    final int userId = UserHandle.myUserId();
    UserEnvironment environment = new UserEnvironment(userId);
    LogRunnable task = new LogRunnable();
    task.setRootDirectory(environment.getExternalStorageDirectory());
    task.setDownloadsDirectory(environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    task.setSystemSize(FileCollector.getSystemSize(this));
    task.setLogOutputFile(new File(DUMPSYS_CACHE_PATH));
    task.setAppCollector(collector);
    task.setJobService(this, params);
    AsyncTask.execute(task);
    return true;
}
Also used : VolumeInfo(android.os.storage.VolumeInfo) UserEnvironment(android.os.Environment.UserEnvironment) File(java.io.File)

Example 9 with UserEnvironment

use of android.os.Environment.UserEnvironment in project android_frameworks_base by ParanoidAndroid.

the class DefaultContainerService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE.equals(intent.getAction())) {
        final IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
        PackageCleanItem item = null;
        try {
            while ((item = pm.nextPackageToClean(item)) != null) {
                final UserEnvironment userEnv = new UserEnvironment(item.userId);
                eraseFiles(userEnv.getExternalStorageAppDataDirectory(item.packageName));
                eraseFiles(userEnv.getExternalStorageAppMediaDirectory(item.packageName));
                if (item.andCode) {
                    eraseFiles(userEnv.getExternalStorageAppObbDirectory(item.packageName));
                }
            }
        } catch (RemoteException e) {
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageCleanItem(android.content.pm.PackageCleanItem) UserEnvironment(android.os.Environment.UserEnvironment) RemoteException(android.os.RemoteException)

Example 10 with UserEnvironment

use of android.os.Environment.UserEnvironment in project android_frameworks_base by ParanoidAndroid.

the class MountService method createEmulatedVolumeForUserLocked.

/**
     * Create and add new {@link StorageVolume} for given {@link UserHandle}
     * using {@link #mEmulatedTemplate} as template.
     */
private void createEmulatedVolumeForUserLocked(UserHandle user) {
    if (mEmulatedTemplate == null) {
        throw new IllegalStateException("Missing emulated volume multi-user template");
    }
    final UserEnvironment userEnv = new UserEnvironment(user.getIdentifier());
    final File path = userEnv.getExternalStorageDirectory();
    final StorageVolume volume = StorageVolume.fromTemplate(mEmulatedTemplate, path, user);
    volume.setStorageId(0);
    addVolumeLocked(volume);
    if (mSystemReady) {
        updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
    } else {
        // Place stub status for early callers to find
        mVolumeStates.put(volume.getPath(), Environment.MEDIA_MOUNTED);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) UserEnvironment(android.os.Environment.UserEnvironment) File(java.io.File)

Aggregations

UserEnvironment (android.os.Environment.UserEnvironment)19 File (java.io.File)11 RemoteException (android.os.RemoteException)7 IPackageManager (android.content.pm.IPackageManager)6 PackageCleanItem (android.content.pm.PackageCleanItem)6 AppOpsManager (android.app.AppOpsManager)5 AtomicFile (android.util.AtomicFile)5 IOException (java.io.IOException)5 Intent (android.content.Intent)3 VolumeInfo (android.os.storage.VolumeInfo)3 StorageVolume (android.os.storage.StorageVolume)1 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)1 ZipFile (java.util.zip.ZipFile)1