Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 61fd853

Browse files
committed
Enable dynamic auto-discovery for APK modifier plugins
Replace hardcoded module imports in ApkModifierRegistry.auto_discover with dynamic package scanning via pkgutil/importlib. This removes the need to manually update __init__ import lists whenever a new APK plugin module is added. Behavior: - Scan src.core.modifiers.plugins.apk modules at runtime - Skip base and __init__ modules - Import discovered modules to trigger decorator-based registry - Register discovered plugin classes into the plugin manager Also improves discovery logging to report both module and plugin counts.
1 parent 9d20580 commit 61fd853

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

  • src/core/modifiers/plugins/apk

src/core/modifiers/plugins/apk/base.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
Uses PortingContext's built-in tools and shell runner.
55
"""
66

7-
from abc import abstractmethod
8-
from pathlib import Path
9-
from typing import Optional, List, Dict, Any, Callable
10-
import logging
7+
import importlib
8+
import pkgutil
9+
import re
1110
import shutil
1211
import sys
13-
import re
12+
from abc import abstractmethod
13+
from pathlib import Path
14+
from typing import Any, Dict, List, Optional
1415

1516
from src.core.modifiers.plugin_system import ModifierPlugin
16-
from src.utils.smalikit import SmaliKit, SmaliArgs
17+
from src.utils.smalikit import SmaliArgs, SmaliKit
1718
from src.utils.xml_utils import XmlUtils
1819

1920

@@ -441,21 +442,34 @@ def list_all(cls) -> Dict[str, type]:
441442

442443
@classmethod
443444
def auto_discover(cls, manager):
444-
"""Auto-discover and register all APK modifiers."""
445-
# Import all APK modifiers to ensure they register
446-
from src.core.modifiers.plugins.apk import installer
447-
from src.core.modifiers.plugins.apk import securitycenter
448-
from src.core.modifiers.plugins.apk import settings
449-
from src.core.modifiers.plugins.apk import joyose
450-
from src.core.modifiers.plugins.apk import powerkeeper
451-
from src.core.modifiers.plugins.apk import devices_overlay
445+
"""Auto-discover and register all APK modifier modules dynamically."""
446+
package_name = "src.core.modifiers.plugins.apk"
447+
package = importlib.import_module(package_name)
448+
package_paths = getattr(package, "__path__", None)
449+
450+
if package_paths is None:
451+
cls.logger().warning("APK plugin package path not found, skipping auto-discovery")
452+
return
453+
454+
discovered_modules = 0
455+
for _, module_name, _ in pkgutil.iter_modules(package_paths, prefix=package_name + "."):
456+
short_name = module_name.rsplit(".", 1)[-1]
457+
if short_name in {"__init__", "base"}:
458+
continue
459+
try:
460+
importlib.import_module(module_name)
461+
discovered_modules += 1
462+
except Exception as exc:
463+
cls.logger().warning(f"Could not import APK plugin module {module_name}: {exc}")
452464

453465
# Plugins auto-register via @ApkModifierRegistry.register decorator
454466
# Now register them with the plugin manager
455-
for name, plugin_class in cls._registry.items():
467+
for _, plugin_class in cls._registry.items():
456468
manager.register(plugin_class)
457469

458-
cls.logger().info(f"Auto-discovered {len(cls._registry)} APK modifiers")
470+
cls.logger().info(
471+
f"Auto-discovered {len(cls._registry)} APK modifiers from {discovered_modules} module(s)"
472+
)
459473

460474
@classmethod
461475
def logger(cls):

0 commit comments

Comments
 (0)