Complete Initialization of ClockRegistry in singleton provider
This ensures we've set the flag right when the registry is created. It also allows us to disable plugin loading when the flag is flipped off. This ensures we won't cause syshealth isues for T. Bug: 229771520 Bug: 254235245 Test: Manually verified clocks work in both flag states Change-Id: I64c0f226db11f46922c44f2cc68be1efb26b06bb
This commit is contained in:
@@ -18,7 +18,6 @@ import android.database.ContentObserver
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.UserHandle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import com.android.internal.annotations.Keep
|
||||
@@ -39,15 +38,15 @@ open class ClockRegistry(
|
||||
val context: Context,
|
||||
val pluginManager: PluginManager,
|
||||
val handler: Handler,
|
||||
defaultClockProvider: ClockProvider
|
||||
val isEnabled: Boolean,
|
||||
userHandle: Int,
|
||||
defaultClockProvider: ClockProvider,
|
||||
) {
|
||||
// Usually this would be a typealias, but a SAM provides better java interop
|
||||
fun interface ClockChangeListener {
|
||||
fun onClockChanged()
|
||||
}
|
||||
|
||||
var isEnabled: Boolean = false
|
||||
|
||||
private val gson = Gson()
|
||||
private val availableClocks = mutableMapOf<ClockId, ClockInfo>()
|
||||
private val clockChangeListeners = mutableListOf<ClockChangeListener>()
|
||||
@@ -97,14 +96,19 @@ open class ClockRegistry(
|
||||
)
|
||||
}
|
||||
|
||||
pluginManager.addPluginListener(pluginListener, ClockProviderPlugin::class.java,
|
||||
true /* allowMultiple */)
|
||||
context.contentResolver.registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE),
|
||||
false,
|
||||
settingObserver,
|
||||
UserHandle.USER_ALL
|
||||
)
|
||||
if (isEnabled) {
|
||||
pluginManager.addPluginListener(
|
||||
pluginListener,
|
||||
ClockProviderPlugin::class.java,
|
||||
/*allowMultiple=*/ true
|
||||
)
|
||||
context.contentResolver.registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE),
|
||||
/*notifyForDescendants=*/ false,
|
||||
settingObserver,
|
||||
userHandle
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun connectClocks(provider: ClockProvider) {
|
||||
|
||||
@@ -37,8 +37,6 @@ import com.android.systemui.Dumpable;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.flags.FeatureFlags;
|
||||
import com.android.systemui.flags.Flags;
|
||||
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
|
||||
import com.android.systemui.plugins.ClockAnimations;
|
||||
import com.android.systemui.plugins.ClockController;
|
||||
@@ -120,8 +118,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
SecureSettings secureSettings,
|
||||
@Main Executor uiExecutor,
|
||||
DumpManager dumpManager,
|
||||
ClockEventController clockEventController,
|
||||
FeatureFlags featureFlags) {
|
||||
ClockEventController clockEventController) {
|
||||
super(keyguardClockSwitch);
|
||||
mStatusBarStateController = statusBarStateController;
|
||||
mClockRegistry = clockRegistry;
|
||||
@@ -134,7 +131,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
mDumpManager = dumpManager;
|
||||
mClockEventController = clockEventController;
|
||||
|
||||
mClockRegistry.setEnabled(featureFlags.isEnabled(Flags.LOCKSCREEN_CUSTOM_CLOCKS));
|
||||
mClockChangedListener = () -> {
|
||||
setClock(mClockRegistry.createCurrentClock());
|
||||
};
|
||||
|
||||
@@ -18,10 +18,13 @@ package com.android.keyguard.dagger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Application;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.flags.FeatureFlags;
|
||||
import com.android.systemui.flags.Flags;
|
||||
import com.android.systemui.shared.clocks.ClockRegistry;
|
||||
import com.android.systemui.shared.clocks.DefaultClockProvider;
|
||||
import com.android.systemui.shared.plugins.PluginManager;
|
||||
@@ -39,7 +42,14 @@ public abstract class ClockRegistryModule {
|
||||
@Application Context context,
|
||||
PluginManager pluginManager,
|
||||
@Main Handler handler,
|
||||
DefaultClockProvider defaultClockProvider) {
|
||||
return new ClockRegistry(context, pluginManager, handler, defaultClockProvider);
|
||||
DefaultClockProvider defaultClockProvider,
|
||||
FeatureFlags featureFlags) {
|
||||
return new ClockRegistry(
|
||||
context,
|
||||
pluginManager,
|
||||
handler,
|
||||
featureFlags.isEnabled(Flags.LOCKSCREEN_CUSTOM_CLOCKS),
|
||||
UserHandle.USER_ALL,
|
||||
defaultClockProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.flags.FeatureFlags;
|
||||
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
|
||||
import com.android.systemui.plugins.ClockAnimations;
|
||||
import com.android.systemui.plugins.ClockController;
|
||||
@@ -105,8 +104,6 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
|
||||
private FrameLayout mLargeClockFrame;
|
||||
@Mock
|
||||
private SecureSettings mSecureSettings;
|
||||
@Mock
|
||||
private FeatureFlags mFeatureFlags;
|
||||
|
||||
private final View mFakeSmartspaceView = new View(mContext);
|
||||
|
||||
@@ -143,8 +140,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
|
||||
mSecureSettings,
|
||||
mExecutor,
|
||||
mDumpManager,
|
||||
mClockEventController,
|
||||
mFeatureFlags
|
||||
mClockEventController
|
||||
);
|
||||
|
||||
when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Handler
|
||||
import android.os.UserHandle
|
||||
import android.testing.AndroidTestingRunner
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
@@ -104,13 +105,14 @@ class ClockRegistryTest : SysuiTestCase() {
|
||||
mockContext,
|
||||
mockPluginManager,
|
||||
mockHandler,
|
||||
fakeDefaultProvider
|
||||
isEnabled = true,
|
||||
userHandle = UserHandle.USER_ALL,
|
||||
defaultClockProvider = fakeDefaultProvider
|
||||
) {
|
||||
override var currentClockId: ClockId
|
||||
get() = settingValue
|
||||
set(value) { settingValue = value }
|
||||
}
|
||||
registry.isEnabled = true
|
||||
|
||||
verify(mockPluginManager)
|
||||
.addPluginListener(captor.capture(), eq(ClockProviderPlugin::class.java), eq(true))
|
||||
|
||||
Reference in New Issue
Block a user