android.os.FileUtils Java Examples

The following examples show how to use android.os.FileUtils. 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 File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 7 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 #4
Source File: LoadedApk.java    From android_9.0.0_r45 with 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 #5
Source File: UserDataPreparer.java    From android_9.0.0_r45 with 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 #6
Source File: RescueParty.java    From android_9.0.0_r45 with 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 #7
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #8
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #9
Source File: TaskPersister.java    From android_9.0.0_r45 with 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 #10
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #11
Source File: UserManagerService.java    From android_9.0.0_r45 with 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 #12
Source File: AtomicFile.java    From android_9.0.0_r45 with 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 #13
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 #15
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 #18
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 File: ContextImpl.java    From AndroidComponentPlugin with 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 #20
Source File: PackageManagerServiceUtils.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 #21
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #22
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #23
Source File: LoadedApk.java    From AndroidComponentPlugin with 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 #24
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #25
Source File: ContextImpl.java    From AndroidComponentPlugin with 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 #26
Source File: PackageManagerServiceUtils.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 #27
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void writeBitmapLP(UserInfo info, Bitmap bitmap) {
    try {
        File dir = new File(mUsersDir, Integer.toString(info.id));
        File file = new File(dir, USER_PHOTO_FILENAME);
        File tmp = new File(dir, USER_PHOTO_FILENAME_TMP);
        if (!dir.exists()) {
            dir.mkdir();
            FileUtils.setPermissions(
                    dir.getPath(),
                    FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
                    -1, -1);
        }
        FileOutputStream os;
        if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(tmp))
                && tmp.renameTo(file) && SELinux.restorecon(file)) {
            info.iconPath = file.getAbsolutePath();
        }
        try {
            os.close();
        } catch (IOException ioe) {
            // What the ... !
        }
        tmp.delete();
    } catch (FileNotFoundException e) {
        Slog.w(LOG_TAG, "Error setting photo for user ", e);
    }
}
 
Example #28
Source File: PackageTracker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Creates the {@link PackageTracker} for normal use. */
static PackageTracker create(Context context) {
    Clock elapsedRealtimeClock = SystemClock.elapsedRealtimeClock();
    PackageTrackerHelperImpl helperImpl = new PackageTrackerHelperImpl(context);
    File storageDir = FileUtils.createDir(Environment.getDataSystemDirectory(), "timezone");
    return new PackageTracker(
            elapsedRealtimeClock /* elapsedRealtimeClock */,
            helperImpl /* configHelper */,
            helperImpl /* packageManagerHelper */,
            new PackageStatusStorage(storageDir),
            new PackageTrackerIntentHelperImpl(context));
}
 
Example #29
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public File getDir(String name, int mode) {
    name = "app_" + name;
    File file = makeFilename(getDataDirFile(), name);
    if (!file.exists()) {
        file.mkdir();
        setFilePermissionsFromMode(file.getPath(), mode,
                FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH);
    }
    return file;
}
 
Example #30
Source File: XposedApp.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint({"WorldReadableFiles", "WorldWriteableFiles"})
public static void setFilePermissionsFromMode(String name, int mode) {
    int perms = FileUtils.S_IRUSR | FileUtils.S_IWUSR
            | FileUtils.S_IRGRP | FileUtils.S_IWGRP;
    if ((mode & Context.MODE_WORLD_READABLE) != 0) {
        perms |= FileUtils.S_IROTH;
    }
    if ((mode & Context.MODE_WORLD_WRITEABLE) != 0) {
        perms |= FileUtils.S_IWOTH;
    }
    FileUtils.setPermissions(name, perms, -1, -1);
}