Java Code Examples for android.os.FileUtils

The following examples show how to use android.os.FileUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 2
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 3
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static File createFilesDirLocked(File file) {
    if (!file.exists()) {
        if (!file.mkdirs()) {
            if (file.exists()) {
                // spurious failure; probably racing with another process for this app
                return file;
            }
            Log.w(TAG, "Unable to create files subdir " + file.getPath());
            return null;
        }
        FileUtils.setPermissions(
                file.getPath(),
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
                -1, -1);
    }
    return file;
}
 
Example 4
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 5
Source Project: android_9.0.0_r45   Source File: AtomicFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Call when you have successfully finished writing to the stream
 * returned by {@link #startWrite()}.  This will close, sync, and
 * commit the new data.  The next attempt to read the atomic file
 * will return the new file stream.
 */
public void finishWrite(FileOutputStream str) {
    if (str != null) {
        FileUtils.sync(str);
        try {
            str.close();
            mBackupName.delete();
        } catch (IOException e) {
            Log.w("AtomicFile", "finishWrite: Got exception:", e);
        }
        if (mCommitTag != null) {
            com.android.internal.logging.EventLogTags.writeCommitSysConfigFile(
                    mCommitTag, SystemClock.uptimeMillis() - mStartTime);
        }
    }
}
 
Example 6
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 7
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 8
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 9
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static File createFilesDirLocked(File file) {
    if (!file.exists()) {
        if (!file.mkdirs()) {
            if (file.exists()) {
                // spurious failure; probably racing with another process for this app
                return file;
            }
            Log.w(TAG, "Unable to create files subdir " + file.getPath());
            return null;
        }
        FileUtils.setPermissions(
                file.getPath(),
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
                -1, -1);
    }
    return file;
}
 
Example 10
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 11
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 12
Source Project: AndroidComponentPlugin   Source File: LoadedApk.java    License: Apache License 2.0 6 votes vote down vote up
private void setApplicationInfo(ApplicationInfo aInfo) {
    final int myUid = Process.myUid();
    aInfo = adjustNativeLibraryPaths(aInfo);
    mApplicationInfo = aInfo;
    mAppDir = aInfo.sourceDir;
    mResDir = aInfo.uid == myUid ? aInfo.sourceDir : aInfo.publicSourceDir;
    mOverlayDirs = aInfo.resourceDirs;
    mDataDir = aInfo.dataDir;
    mLibDir = aInfo.nativeLibraryDir;
    mDataDirFile = FileUtils.newFileOrNull(aInfo.dataDir);
    mDeviceProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.deviceProtectedDataDir);
    mCredentialProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.credentialProtectedDataDir);

    mSplitNames = aInfo.splitNames;
    mSplitAppDirs = aInfo.splitSourceDirs;
    mSplitResDirs = aInfo.uid == myUid ? aInfo.splitSourceDirs : aInfo.splitPublicSourceDirs;
    mSplitClassLoaderNames = aInfo.splitClassLoaderNames;

    if (aInfo.requestsIsolatedSplitLoading() && !ArrayUtils.isEmpty(mSplitNames)) {
        mSplitLoader = new SplitDependencyLoaderImpl(aInfo.splitDependencies);
    }
}
 
Example 13
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 14
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static File createFilesDirLocked(File file) {
    if (!file.exists()) {
        if (!file.mkdirs()) {
            if (file.exists()) {
                // spurious failure; probably racing with another process for this app
                return file;
            }
            Log.w(TAG, "Unable to create files subdir " + file.getPath());
            return null;
        }
        FileUtils.setPermissions(
                file.getPath(),
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
                -1, -1);
    }
    return file;
}
 
Example 15
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 16
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 17
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 18
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 19
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
static void setFilePermissionsFromMode(String name, int mode,
        int extraPermissions) {
    int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
        |FileUtils.S_IRGRP|FileUtils.S_IWGRP
        |extraPermissions;
    if ((mode&MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode&MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    if (DEBUG) {
        Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
              + ", perms=0x" + Integer.toHexString(perms));
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}
 
Example 20
Source Project: android_9.0.0_r45   Source File: RescueParty.java    License: Apache License 2.0 6 votes vote down vote up
private static int[] getAllUserIds() {
    int[] userIds = { UserHandle.USER_SYSTEM };
    try {
        for (File file : FileUtils.listFilesOrEmpty(Environment.getDataSystemDeDirectory())) {
            try {
                final int userId = Integer.parseInt(file.getName());
                if (userId != UserHandle.USER_SYSTEM) {
                    userIds = ArrayUtils.appendInt(userIds, userId);
                }
            } catch (NumberFormatException ignored) {
            }
        }
    } catch (Throwable t) {
        Slog.w(TAG, "Trouble discovering users", t);
    }
    return userIds;
}
 
Example 21
Source Project: android_9.0.0_r45   Source File: UserDataPreparer.java    License: Apache License 2.0 6 votes vote down vote up
void destroyUserDataLI(String volumeUuid, int userId, int flags) {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    try {
        // Clean up app data, profile data, and media data
        mInstaller.destroyUserData(volumeUuid, userId, flags);

        // Clean up system data
        if (Objects.equals(volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL)) {
            if ((flags & StorageManager.FLAG_STORAGE_DE) != 0) {
                FileUtils.deleteContentsAndDir(getUserSystemDirectory(userId));
                FileUtils.deleteContentsAndDir(getDataSystemDeDirectory(userId));
            }
            if ((flags & StorageManager.FLAG_STORAGE_CE) != 0) {
                FileUtils.deleteContentsAndDir(getDataSystemCeDirectory(userId));
            }
        }

        // Data with special labels is now gone, so finish the job
        storage.destroyUserStorage(volumeUuid, userId, flags);

    } catch (Exception e) {
        logCriticalInfo(Log.WARN,
                "Failed to destroy user " + userId + " on volume " + volumeUuid + ": " + e);
    }
}
 
Example 22
Source Project: android_9.0.0_r45   Source File: UserManagerService.java    License: Apache License 2.0 6 votes vote down vote up
private UserManagerService(Context context, PackageManagerService pm,
        UserDataPreparer userDataPreparer, Object packagesLock, File dataDir) {
    mContext = context;
    mPm = pm;
    mPackagesLock = packagesLock;
    mHandler = new MainHandler();
    mUserDataPreparer = userDataPreparer;
    synchronized (mPackagesLock) {
        mUsersDir = new File(dataDir, USER_INFO_DIR);
        mUsersDir.mkdirs();
        // Make zeroth user directory, for services to migrate their files to that location
        File userZeroDir = new File(mUsersDir, String.valueOf(UserHandle.USER_SYSTEM));
        userZeroDir.mkdirs();
        FileUtils.setPermissions(mUsersDir.toString(),
                FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH,
                -1, -1);
        mUserListFile = new File(mUsersDir, USER_LIST_FILENAME);
        initDefaultGuestRestrictions();
        readUserListLP();
        sInstance = this;
    }
    mLocalService = new LocalService();
    LocalServices.addService(UserManagerInternal.class, mLocalService);
    mLockPatternUtils = new LockPatternUtils(mContext);
    mUserStates.put(UserHandle.USER_SYSTEM, UserState.STATE_BOOTING);
}
 
Example 23
public static void logCriticalInfo(int priority, String msg) {
    Slog.println(priority, TAG, msg);
    EventLogTags.writePmCriticalInfo(msg);
    try {
        File fname = getSettingsProblemFile();
        FileOutputStream out = new FileOutputStream(fname, true);
        PrintWriter pw = new FastPrintWriter(out);
        SimpleDateFormat formatter = new SimpleDateFormat();
        String dateString = formatter.format(new Date(System.currentTimeMillis()));
        pw.println(dateString + ": " + msg);
        pw.close();
        FileUtils.setPermissions(
                fname.toString(),
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH,
                -1, -1);
    } catch (java.io.IOException e) {
    }
}
 
Example 24
public static int decompressFile(File srcFile, File dstFile) throws ErrnoException {
    if (DEBUG_COMPRESSION) {
        Slog.i(TAG, "Decompress file"
                + "; src: " + srcFile.getAbsolutePath()
                + ", dst: " + dstFile.getAbsolutePath());
    }
    try (
            InputStream fileIn = new GZIPInputStream(new FileInputStream(srcFile));
            OutputStream fileOut = new FileOutputStream(dstFile, false /*append*/);
    ) {
        FileUtils.copy(fileIn, fileOut);
        Os.chmod(dstFile.getAbsolutePath(), 0644);
        return PackageManager.INSTALL_SUCCEEDED;
    } catch (IOException e) {
        logCriticalInfo(Log.ERROR, "Failed to decompress file"
                + "; src: " + srcFile.getAbsolutePath()
                + ", dst: " + dstFile.getAbsolutePath());
    }
    return PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
}
 
Example 25
Source Project: android_9.0.0_r45   Source File: TaskPersister.java    License: Apache License 2.0 6 votes vote down vote up
TaskPersister(File systemDir, ActivityStackSupervisor stackSupervisor,
        ActivityManagerService service, RecentTasks recentTasks) {

    final File legacyImagesDir = new File(systemDir, IMAGES_DIRNAME);
    if (legacyImagesDir.exists()) {
        if (!FileUtils.deleteContents(legacyImagesDir) || !legacyImagesDir.delete()) {
            Slog.i(TAG, "Failure deleting legacy images directory: " + legacyImagesDir);
        }
    }

    final File legacyTasksDir = new File(systemDir, TASKS_DIRNAME);
    if (legacyTasksDir.exists()) {
        if (!FileUtils.deleteContents(legacyTasksDir) || !legacyTasksDir.delete()) {
            Slog.i(TAG, "Failure deleting legacy tasks directory: " + legacyTasksDir);
        }
    }

    mTaskIdsDir = new File(Environment.getDataDirectory(), "system_de");
    mStackSupervisor = stackSupervisor;
    mService = service;
    mRecentTasks = recentTasks;
    mLazyTaskWriterThread = new LazyTaskWriterThread("LazyTaskWriterThread");
}
 
Example 26
Source Project: android_9.0.0_r45   Source File: LoadedApk.java    License: Apache License 2.0 6 votes vote down vote up
private void setApplicationInfo(ApplicationInfo aInfo) {
    final int myUid = Process.myUid();
    aInfo = adjustNativeLibraryPaths(aInfo);
    mApplicationInfo = aInfo;
    mAppDir = aInfo.sourceDir;
    mResDir = aInfo.uid == myUid ? aInfo.sourceDir : aInfo.publicSourceDir;
    mOverlayDirs = aInfo.resourceDirs;
    mDataDir = aInfo.dataDir;
    mLibDir = aInfo.nativeLibraryDir;
    mDataDirFile = FileUtils.newFileOrNull(aInfo.dataDir);
    mDeviceProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.deviceProtectedDataDir);
    mCredentialProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.credentialProtectedDataDir);

    mSplitNames = aInfo.splitNames;
    mSplitAppDirs = aInfo.splitSourceDirs;
    mSplitResDirs = aInfo.uid == myUid ? aInfo.splitSourceDirs : aInfo.splitPublicSourceDirs;
    mSplitClassLoaderNames = aInfo.splitClassLoaderNames;

    if (aInfo.requestsIsolatedSplitLoading() && !ArrayUtils.isEmpty(mSplitNames)) {
        mSplitLoader = new SplitDependencyLoaderImpl(aInfo.splitDependencies);
    }
}
 
Example 27
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 28
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public File getDir(String name, int mode) {
    checkMode(mode);
    name = "app_" + name;
    File file = makeFilename(getDataDir(), name);
    if (!file.exists()) {
        file.mkdir();
        setFilePermissionsFromMode(file.getPath(), mode,
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH);
    }
    return file;
}
 
Example 29
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 30
Source Project: AndroidComponentPlugin   Source File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public File getDir(String name, int mode) {
    checkMode(mode);
    name = "app_" + name;
    File file = makeFilename(getDataDir(), name);
    if (!file.exists()) {
        file.mkdir();
        setFilePermissionsFromMode(file.getPath(), mode,
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH);
    }
    return file;
}