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

Commit 5b576d00 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan
Browse files

DefaultContainerService: implement additional methods

For usage in Settings->Storage

Change-Id: I2d45198cc6ea3b84af1547873380eae2c04c0b93
parent c90b2343
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -33,8 +33,10 @@ interface IMediaContainerService {
    boolean checkExternalFreeStorage(in Uri fileUri, boolean isForwardLocked);
    boolean checkExternalFreeStorage(in Uri fileUri, boolean isForwardLocked);
    ObbInfo getObbInfo(in String filename);
    ObbInfo getObbInfo(in String filename);
    long calculateDirectorySize(in String directory);
    long calculateDirectorySize(in String directory);
    byte[] listDirectory(in String directory);
    /** Return file system stats: [0] is total bytes, [1] is available bytes */
    /** Return file system stats: [0] is total bytes, [1] is available bytes */
    long[] getFileSystemStats(in String path);
    long[] getFileSystemStats(in String path);
    void clearDirectory(in String directory);
    void clearDirectory(in String directory);
    void deleteFile(in String file);
    long calculateInstalledSize(in String packagePath, boolean isForwardLocked);
    long calculateInstalledSize(in String packagePath, boolean isForwardLocked);
}
}
+46 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.Environment;
import android.os.Environment.UserEnvironment;
import android.os.Environment.UserEnvironment;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
@@ -236,6 +237,40 @@ public class DefaultContainerService extends IntentService {
            }
            }
        }
        }


        /**
         * List content of the directory and return as marshalled Parcel.
         * Used for calculating misc size in Settings -> Storage
         */
        @Override
        public byte[] listDirectory(String path) throws RemoteException {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            final File directory = new File(path);
            final File[] files = directory.listFiles();
            final Parcel out = Parcel.obtain();

            if (files == null) {
                out.writeInt(0);
            }
            else {
                out.writeInt(files.length);
                for (final File file : files) {
                    out.writeString(file.getAbsolutePath());
                    out.writeString(file.getName());
                    out.writeInt(file.isDirectory() ? 1 : 0);
                    if (file.isFile()) {
                        out.writeInt(1);
                        out.writeLong(file.length());
                    }
                    else {
                        out.writeInt(0);
                    }
                }
            }

            return out.marshall();
        }

        @Override
        @Override
        public long[] getFileSystemStats(String path) {
        public long[] getFileSystemStats(String path) {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
@@ -260,6 +295,17 @@ public class DefaultContainerService extends IntentService {
            }
            }
        }
        }


        // Same as clearDirectory, but also work for files
        @Override
        public void deleteFile(String path) throws RemoteException {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            final File file = new File(path);
            if (file.exists()) {
                eraseFiles(file);
            }
        }

        @Override
        @Override
        public long calculateInstalledSize(String packagePath, boolean isForwardLocked)
        public long calculateInstalledSize(String packagePath, boolean isForwardLocked)
                throws RemoteException {
                throws RemoteException {