Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 541da82c authored by Leif Martensson's avatar Leif Martensson Committed by Mattias Nilsson
Browse files

Change file permissions for shutdown files

Make the shutdown-checkpoints files readable for platform apps.

Test: Check that shutdown-checkpoint file is created with correct
      permission
    1 Generate a new shutdown-checkpoint file
      This can be done by a reboot from the device power menu
      PS "adb reboot" does not generate a shutdown-checkpoint file
    2 Check the permissions with adb
      $ adb shell ls -laZ /data/system/shutdown-checkpoints | grep shutdown_checkpoints
      drwxr-xr-x  2 system system u:object_r:shutdown_checkpoints_system_data_file:s0  3452 2023-10-19 10:21 .
      -rw-r--r--  1 system system u:object_r:shutdown_checkpoints_system_data_file:s0  1307 2023-10-19 10:21 checkpoints-1697703667771
    3 Check that  the shutdown-checkpoint dir permission is "drwxr-xr-x"
    4 Check that a new shutdown-checkpoint file has been created with
      the permission "-rw-r--r--"
Bug: 306198106
Change-Id: I1639d59f1eb41063c5ac4898738a9f8f5c882028
parent c9c97bec
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -350,17 +350,23 @@ public final class ShutdownCheckPoints {

        private final ShutdownCheckPoints mInstance;
        private final File mBaseFile;
        private final File mBaseDir;
        private final int mFileCountLimit;

        FileDumperThread(ShutdownCheckPoints instance, File baseFile, int fileCountLimit) {
            mInstance = instance;
            mBaseFile = baseFile;
            mBaseDir = baseFile.getParentFile();
            mFileCountLimit = fileCountLimit;
        }

        @Override
        public void run() {
            mBaseFile.getParentFile().mkdirs();
            if (!mBaseDir.exists()) {
                mBaseDir.mkdirs();
                mBaseDir.setExecutable(true, false);
                mBaseDir.setReadable(true, false);
            }
            File[] checkPointFiles = listCheckPointsFiles();

            int filesToDelete = checkPointFiles.length - mFileCountLimit + 1;
@@ -375,7 +381,7 @@ public final class ShutdownCheckPoints {

        private File[] listCheckPointsFiles() {
            String filePrefix = mBaseFile.getName() + "-";
            File[] files = mBaseFile.getParentFile().listFiles(new FilenameFilter() {
            File[] files = mBaseDir.listFiles(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    if (!name.startsWith(filePrefix)) {
@@ -412,6 +418,7 @@ public final class ShutdownCheckPoints {
                }
            }
            mBaseFile.renameTo(file);
            file.setReadable(true, false);
        }
    }
}