MuntashirAkon/AppManager · error · UnsupportedOperationException

Mode ${mode} is not supported.

Error message

Mode ${mode} is not supported.

What it means

Thrown by StorageManagerCompat.openProxyFileDescriptor when an unsupported mode value is passed to createProxyFileDescriptor. Only MODE_READ_ONLY and MODE_WRITE_ONLY are handled; anything else (e.g. MODE_READ_WRITE) closes both pipe ends and throws UnsupportedOperationException.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/compat/StorageManagerCompat.java:145

                    }
                } catch (IOException | ErrnoException e) {
                    Log.e(TAG, "Failed to write file.", e);
                    try {
                        pipe[0].closeWithError(e.getMessage());
                    } catch (IOException exc) {
                        Log.e(TAG, "Can't even close PFD with error.", exc);
                    }
                } finally {
                    callback.onRelease();
                }
            });
            return pipe[1];
        } else {
            // Should never happen.
            pipe[0].close();
            pipe[1].close();
            Log.e(TAG, "Mode " + mode + " is not supported.");
            throw new UnsupportedOperationException("Mode " + mode + " is not supported.");
        }
    }

    public static abstract class ProxyFileDescriptorCallbackCompat {
        private final Handler mHandler;

        public ProxyFileDescriptorCallbackCompat(@NonNull Handler callbackHandler) {
            mHandler = callbackHandler;
        }

        /**
         * Returns size of bytes provided by the file descriptor.
         *
         * @return Size of bytes.
         * @throws ErrnoException Containing E constants in OsConstants.
         */
        public long onGetSize() throws ErrnoException {
            throw new ErrnoException("onGetSize", OsConstants.EBADF);

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Pass ParcelFileDescriptor.MODE_READ_ONLY or MODE_WRITE_ONLY explicitly
  2. If read-write is needed, open two proxy descriptors (one per direction)
  3. Audit calling code for flags like MODE_CREATE|MODE_TRUNCATE being ORed into the mode argument

Example fix

// before
ParcelFileDescriptor pfd = StorageManagerCompat.openProxyFileDescriptor(
        ParcelFileDescriptor.MODE_READ_WRITE, callback, handler);
// after
ParcelFileDescriptor pfd = StorageManagerCompat.openProxyFileDescriptor(
        ParcelFileDescriptor.MODE_READ_ONLY, callback, handler);
Defensive patterns

Strategy: type-guard

Validate before calling

boolean isSupported(int mode) {
    return mode == ParcelFileDescriptor.MODE_READ_ONLY
        || mode == ParcelFileDescriptor.MODE_WRITE_ONLY;
}

Type guard

static boolean isSupportedProxyMode(int mode) {
    int m = mode & (ParcelFileDescriptor.MODE_READ_ONLY | ParcelFileDescriptor.MODE_WRITE_ONLY);
    return m == ParcelFileDescriptor.MODE_READ_ONLY || m == ParcelFileDescriptor.MODE_WRITE_ONLY;
}

Try / catch

int mode = ParcelFileDescriptor.MODE_READ_WRITE;
if (!isSupportedProxyMode(mode)) {
    mode = ParcelFileDescriptor.MODE_READ_ONLY; // safe default
}
try {
    pfd = StorageManagerCompat.openProxyFileDescriptor(mode, callback, handler);
} catch (UnsupportedOperationException e) {
    Log.e(TAG, "Unsupported mode requested", e);
}

Prevention

When it happens

Trigger: Calling openProxyFileDescriptor with a mode from ParcelFileDescriptor constants other than MODE_READ_ONLY or MODE_WRITE_ONLY — typically MODE_READ_WRITE or MODE_CREATE|MODE_TRUNCATE combinations.

Common situations: Opening a DocumentFile with Intent flags that map to read-write; passing MODE_READ_WRITE because the caller wants both read and write through one proxy; refactoring code that previously used openFileDescriptor defaults.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/dd884c9a62b16598. Report an issue: GitHub.