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

Commit 51008633 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Catch IllegalArgumentException when checking enable state of a package

Bug: 389354153
Test: Manually checked fix
Flag: NONE Minor edge-case fix
Change-Id: Ia13df7bb66fbe498f27d6d863203e2edbdd17bc7
parent 4d71ef00
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,9 +27,10 @@ public interface PluginEnabler {
    int DISABLED_INVALID_VERSION = 2;
    int DISABLED_FROM_EXPLICIT_CRASH = 3;
    int DISABLED_FROM_SYSTEM_CRASH = 4;
    int DISABLED_UNKNOWN = 100;

    @IntDef({ENABLED, DISABLED_MANUALLY, DISABLED_INVALID_VERSION, DISABLED_FROM_EXPLICIT_CRASH,
            DISABLED_FROM_SYSTEM_CRASH})
            DISABLED_FROM_SYSTEM_CRASH, DISABLED_UNKNOWN})
    @interface DisableReason {
    }

+10 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.shared.plugins.PluginEnabler;
@@ -28,6 +29,7 @@ import javax.inject.Singleton;
/** */
@Singleton
public class PluginEnablerImpl implements PluginEnabler {
    private static final String TAG = "PluginEnablerImpl";
    private static final String CRASH_DISABLED_PLUGINS_PREF_FILE = "auto_disabled_plugins_prefs";

    private final PackageManager mPm;
@@ -64,8 +66,13 @@ public class PluginEnablerImpl implements PluginEnabler {

    @Override
    public boolean isEnabled(ComponentName component) {
        try {
            return mPm.getComponentEnabledSetting(component)
                    != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        } catch (IllegalArgumentException ex) {
            Log.e(TAG, "Package Manager Exception", ex);
            return false;
        }
    }

    @Override
@@ -73,6 +80,6 @@ public class PluginEnablerImpl implements PluginEnabler {
        if (isEnabled(componentName)) {
            return ENABLED;
        }
        return mAutoDisabledPrefs.getInt(componentName.flattenToString(), DISABLED_MANUALLY);
        return mAutoDisabledPrefs.getInt(componentName.flattenToString(), DISABLED_UNKNOWN);
    }
}