Acquire DockManager via dagger

Bug: 123606744
Test: atest ClockManagerTest DozeDockHandlerTest DozeTriggersTest
Change-Id: I9439103c26797efe67cc0bf45b9cdfc9caccc479
Merged-In: I9439103c26797efe67cc0bf45b9cdfc9caccc479
This commit is contained in:
Lucas Dupin
2019-05-01 00:49:35 +00:00
parent 8bf9743b59
commit d93e95f8e2
5 changed files with 9 additions and 16 deletions

View File

@@ -32,7 +32,6 @@ import android.view.LayoutInflater;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Observer;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.dock.DockManager;
import com.android.systemui.dock.DockManager.DockEventListener;
@@ -89,6 +88,7 @@ public final class ClockManager {
private final Observer<Integer> mCurrentUserObserver = (newUserId) -> reload();
private final PluginManager mPluginManager;
@Nullable private final DockManager mDockManager;
/**
* Observe changes to dock state to know when to switch the clock face.
@@ -102,7 +102,6 @@ public final class ClockManager {
reload();
}
};
@Nullable private DockManager mDockManager;
/**
* When docked, the DOCKED_CLOCK_FACE setting will be checked for the custom clock face
@@ -125,21 +124,24 @@ public final class ClockManager {
@Inject
public ClockManager(Context context, InjectionInflationController injectionInflater,
PluginManager pluginManager, SysuiColorExtractor colorExtractor) {
PluginManager pluginManager, SysuiColorExtractor colorExtractor,
@Nullable DockManager dockManager) {
this(context, injectionInflater, pluginManager, colorExtractor,
context.getContentResolver(), new CurrentUserObservable(context),
new SettingsWrapper(context.getContentResolver()));
new SettingsWrapper(context.getContentResolver()), dockManager);
}
@VisibleForTesting
ClockManager(Context context, InjectionInflationController injectionInflater,
PluginManager pluginManager, SysuiColorExtractor colorExtractor,
ContentResolver contentResolver, CurrentUserObservable currentUserObservable,
SettingsWrapper settingsWrapper) {
SettingsWrapper settingsWrapper, DockManager dockManager) {
mContext = context;
mPluginManager = pluginManager;
mContentResolver = contentResolver;
mSettingsWrapper = settingsWrapper;
mCurrentUserObservable = currentUserObservable;
mDockManager = dockManager;
mPreviewClocks = new AvailableClocks();
Resources res = context.getResources();
@@ -223,9 +225,6 @@ public final class ClockManager {
Settings.Secure.getUriFor(Settings.Secure.DOCKED_CLOCK_FACE),
false, mContentObserver, UserHandle.USER_ALL);
mCurrentUserObservable.getCurrentUser().observeForever(mCurrentUserObserver);
if (mDockManager == null) {
mDockManager = SysUiServiceProvider.getComponent(mContext, DockManager.class);
}
if (mDockManager != null) {
mDockManager.addListener(mDockEventListener);
}

View File

@@ -40,7 +40,6 @@ import com.android.keyguard.ViewMediatorCallback;
import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.systemui.DejankUtils;
import com.android.systemui.Dependency;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.dock.DockManager;
import com.android.systemui.keyguard.DismissCallbackRegistry;
@@ -194,7 +193,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
Dependency.get(ConfigurationController.class).addCallback(this);
mLastGesturalNav = QuickStepContract.isGesturalMode(
Dependency.get(NavigationModeController.class).addListener(this));
mDockManager = SysUiServiceProvider.getComponent(context, DockManager.class);
mDockManager = Dependency.get(DockManager.class);
if (mDockManager != null) {
mDockManager.addListener(mDockEventListener);
mIsDocked = mDockManager.isDocked();

View File

@@ -84,7 +84,6 @@ public final class ClockManagerTest extends SysuiTestCase {
when(mMockInjectionInflationController.injectable(any())).thenReturn(inflater);
mFakeDockManager = new DockManagerFake();
getContext().putComponent(DockManager.class, mFakeDockManager);
mCurrentUser = new MutableLiveData<>();
mCurrentUser.setValue(MAIN_USER_ID);
@@ -92,7 +91,7 @@ public final class ClockManagerTest extends SysuiTestCase {
mClockManager = new ClockManager(getContext(), mMockInjectionInflationController,
mMockPluginManager, mMockColorExtractor, mMockContentResolver,
mMockCurrentUserObserable, mMockSettingsWrapper);
mMockCurrentUserObserable, mMockSettingsWrapper, mFakeDockManager);
mClockManager.addOnClockChangedListener(mMockListener1);
mClockManager.addOnClockChangedListener(mMockListener2);

View File

@@ -73,8 +73,6 @@ public class DozeDockHandlerTest extends SysuiTestCase {
doReturn(false).when(mConfig).alwaysOnEnabled(anyInt());
mDockManagerFake = spy(new DockManagerFake());
mContext.putComponent(DockManager.class, mDockManagerFake);
mDockHandler = new DozeDockHandler(mContext, mMachine, mHost, mConfig,
Handler.createAsync(Looper.myLooper()), mDockManagerFake);
}

View File

@@ -38,7 +38,6 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dock.DockManager;
import com.android.systemui.dock.DockManagerFake;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.wakelock.WakeLock;
@@ -84,7 +83,6 @@ public class DozeTriggersTest extends SysuiTestCase {
mSensors = new FakeSensorManager(mContext);
mWakeLock = new WakeLockFake();
mDockManagerFake = spy(new DockManagerFake());
mContext.putComponent(DockManager.class, mDockManagerFake);
mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager, mConfig, mParameters,
mSensors, Handler.createAsync(Looper.myLooper()), mWakeLock, true,