MuntashirAkon/AppManager · error · java.lang.IllegalStateException

You are adding too many system settings. You should stop…

Error message

You are adding too many system settings. You should stop using system settings for app specific data package: ${packageName}

What it means

IllegalStateException thrown by SettingsStateV26 (AOSP-derived settings XML state manager) when the accumulated byte size of settings written for a single package would exceed mMaxBytesPerAppPackage. This guard prevents one package from bloating the shared settings_ssaid.xml storage, mirroring the Android framework's own limit on per-package settings.

Solutions

  1. Remove obsolete settings entries for the package before adding new ones to reduce currentSize
  2. Raise the max-bytes-per-package limit if legitimate data requires it
  3. Audit the write loop to avoid redundant set calls for the same package/key
  4. Catch IllegalStateException around the settings write and skip/report the offending package

Example fix

// before
ssaidSettings.setSsaid(packageName, uid, newSsaid); // may throw if package over quota
// after
try {
    ssaidSettings.setSsaid(packageName, uid, newSsaid);
} catch (IllegalStateException e) {
    Log.w(TAG, "Package " + packageName + " exceeded settings quota; skipping write", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// estimate before writing
long existingBytes = getSettingsBytesForPackage(packageName);
if (existingBytes + newEntryBytes > MAX_BYTES_PER_PACKAGE) {
    pruneOldestSettings(packageName);
}

Try / catch

try {
    settingsState.putSettingsLocked(...);
} catch (IllegalStateException e) {
    Log.w(TAG, "Per-package settings quota exceeded for " + packageName, e);
}

Prevention

When it happens

Trigger: Repeatedly calling setSsaid/put settings for the same packageName so that the tracked per-package memory usage (mPackageToMemoryUsage plus deltaSize) crosses the configured max-bytes-per-package threshold during the next write/update.

Common situations: Automated tooling writing many SSAID-like settings entries per package in a loop; repeated app-clone/user profile operations accumulating settings without cleanup; an abnormally small mMaxBytesPerAppPackage configuration.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/ssaid/SettingsStateV26.java:579

        }

        if (SYSTEM_PACKAGE_NAME.equals(packageName)) {
            return;
        }

        final int oldValueSize = (oldValue != null) ? oldValue.length() : 0;
        final int newValueSize = (newValue != null) ? newValue.length() : 0;
        final int oldDefaultValueSize = (oldDefaultValue != null) ? oldDefaultValue.length() : 0;
        final int newDefaultValueSize = (newDefaultValue != null) ? newDefaultValue.length() : 0;
        final int deltaSize = newValueSize + newDefaultValueSize
                - oldValueSize - oldDefaultValueSize;

        Integer currentSize = mPackageToMemoryUsage.get(packageName);
        final int newSize = Math.max((currentSize != null)
                ? currentSize + deltaSize : deltaSize, 0);

        if (newSize > mMaxBytesPerAppPackage) {
            throw new IllegalStateException("You are adding too many system settings. "
                    + "You should stop using system settings for app specific data"
                    + " package: " + packageName);
        }

        if (DEBUG) {
            Log.i(LOG_TAG, "Settings for package: %s size: %s bytes.", packageName, newSize);
        }

        mPackageToMemoryUsage.put(packageName, newSize);
    }

    @GuardedBy("mLock")
    private boolean hasSettingLocked(String name) {
        return mSettings.indexOfKey(name) >= 0;
    }

    @GuardedBy("mLock")
    private void scheduleWriteIfNeededLocked() {

View on GitHub (pinned to 0152f468fc)