From 5d6c77266b67ec9754d6e5a91a56d5075a585539 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 27 Aug 2023 17:55:09 +0200 Subject: [PATCH] Get component state default --- .../main/java/eu/faircode/email/Helper.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 7e81ef5ce3..8a8ad4b386 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -46,6 +46,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.UriPermission; import android.content.pm.ApplicationInfo; +import android.content.pm.ComponentInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -705,6 +706,32 @@ public class Helper { static boolean isComponentEnabled(Context context, Class clazz) { PackageManager pm = context.getPackageManager(); int state = pm.getComponentEnabledSetting(new ComponentName(context, clazz)); + + if (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { + try { + PackageInfo pi = pm.getPackageInfo(context.getPackageName(), + PackageManager.GET_ACTIVITIES | + PackageManager.GET_RECEIVERS | + PackageManager.GET_SERVICES | + PackageManager.GET_PROVIDERS | + PackageManager.GET_DISABLED_COMPONENTS); + + List components = new ArrayList<>(); + if (pi.activities != null) + Collections.addAll(components, pi.activities); + if (pi.services != null) + Collections.addAll(components, pi.services); + if (pi.providers != null) + Collections.addAll(components, pi.providers); + + for (ComponentInfo component : components) + if (component.name.equals(clazz.getName())) + return component.isEnabled(); + } catch (PackageManager.NameNotFoundException ex) { + Log.w(ex); + } + } + return (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); }