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

Commit 2db939bd authored by San Mehat's avatar San Mehat Committed by Android (Google) Code Review
Browse files

Merge "MountService: Add API call for getting a list of pids currently using...

Merge "MountService: Add API call for getting a list of pids currently using the specified mountpoint"
parents 8ff97b58 c1b4ce93
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -71,6 +71,12 @@ interface IMountService
     */
    int formatVolume(String mountPoint);

    /**
     * Returns an array of pids with open files on
     * the specified path.
     */
    int[] getStorageUsers(String path);

    /**
     * Gets the state of an volume via it's mountpoint.
     */
+26 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ class MountService extends IMountService.Stub
         */
        public static final int VolumeListResult               = 110;
        public static final int AsecListResult                 = 111;
        public static final int StorageUsersListResult         = 112;

        /*
         * 200 series - Requestion action has been successfully completed.
@@ -795,6 +796,31 @@ class MountService extends IMountService.Stub
        return doFormatVolume(path);
    }

    public int []getStorageUsers(String path) {
        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
        waitForReady();
        try {
            String[] r = mConnector.doListCommand(
                    String.format("storage users %s", path),
                            VoldResponseCode.StorageUsersListResult);
            // FMT: <pid> <process name>
            int[] data = new int[r.length];
            for (int i = 0; i < r.length; i++) {
                String []tok = r[i].split(" ");
                try {
                    data[i] = Integer.parseInt(tok[0]);
                } catch (NumberFormatException nfe) {
                    Log.e(TAG, String.format("Error parsing pid %s", tok[0]));
                    return new int[0];
                }
            }
            return data;
        } catch (NativeDaemonConnectorException e) {
            Log.e(TAG, "Failed to retrieve storage users list", e);
            return new int[0];
        }
    }

    private void warnOnNotMounted() {
        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            Log.w(TAG, "getSecureContainerList() called when storage not mounted");