Merge "Unload the duplicate unused managers when they conflict" into udc-dev

This commit is contained in:
Hawkwood Glazier
2023-04-26 14:47:21 +00:00
committed by Android (Google) Code Review
3 changed files with 18 additions and 12 deletions

View File

@@ -151,6 +151,7 @@ open class ClockRegistry(
{ str1 = id },
{ "Clock Id conflict on load: $str1 is double registered" }
)
manager.unloadPlugin()
continue
}

View File

@@ -109,7 +109,7 @@ public class PluginActionManager<T extends Plugin> {
/** Load all plugins matching this instance's action. */
public void loadAll() {
if (DEBUG) Log.d(TAG, "startListening");
mBgExecutor.execute(this::queryAll);
mBgExecutor.execute(() -> queryAll());
}
/** Unload all plugins managed by this instance. */
@@ -255,17 +255,18 @@ public class PluginActionManager<T extends Plugin> {
intent.setPackage(pkgName);
}
List<ResolveInfo> result = mPm.queryIntentServices(intent, 0);
if (DEBUG) Log.d(TAG, "Found " + result.size() + " plugins");
if (DEBUG) {
Log.d(TAG, "Found " + result.size() + " plugins");
for (ResolveInfo info : result) {
ComponentName name = new ComponentName(info.serviceInfo.packageName,
info.serviceInfo.name);
Log.d(TAG, " " + name);
}
}
if (result.size() > 1 && !mAllowMultiple) {
// TODO: Show warning.
Log.w(TAG, "Multiple plugins found for " + mAction);
if (DEBUG) {
for (ResolveInfo info : result) {
ComponentName name = new ComponentName(info.serviceInfo.packageName,
info.serviceInfo.name);
Log.w(TAG, " " + name);
}
}
return;
}
for (ResolveInfo info : result) {
@@ -307,7 +308,7 @@ public class PluginActionManager<T extends Plugin> {
// TODO: Only create the plugin before version check if we need it for
// legacy version check.
if (DEBUG) {
Log.d(TAG, "createPlugin");
Log.d(TAG, "createPlugin: " + component);
}
try {
return mPluginInstanceFactory.create(
@@ -317,7 +318,7 @@ public class PluginActionManager<T extends Plugin> {
reportInvalidVersion(component, component.getClassName(), e);
}
} catch (Throwable e) {
Log.w(TAG, "Couldn't load plugin: " + packageName, e);
Log.w(TAG, "Couldn't load plugin: " + component, e);
return null;
}

View File

@@ -43,6 +43,8 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.junit.MockitoJUnit
@@ -172,7 +174,7 @@ class ClockRegistryTest : SysuiTestCase() {
}
@Test
fun clockIdConflict_ErrorWithoutCrash() {
fun clockIdConflict_ErrorWithoutCrash_unloadDuplicate() {
val mockPluginLifecycle1 = mock<PluginLifecycleManager<ClockProviderPlugin>>()
val plugin1 = FakeClockPlugin()
.addClock("clock_1", "clock 1", { mockClock }, { mockThumbnail })
@@ -199,6 +201,8 @@ class ClockRegistryTest : SysuiTestCase() {
assertEquals(registry.createExampleClock("clock_2"), mockClock)
assertEquals(registry.getClockThumbnail("clock_1"), mockThumbnail)
assertEquals(registry.getClockThumbnail("clock_2"), mockThumbnail)
verify(mockPluginLifecycle1, never()).unloadPlugin()
verify(mockPluginLifecycle2, times(2)).unloadPlugin()
}
@Test