diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunablePadding.java b/packages/SystemUI/src/com/android/systemui/tuner/TunablePadding.java index 81d77a64c1f07..8f3a8f6ec9608 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunablePadding.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunablePadding.java @@ -38,8 +38,9 @@ public class TunablePadding implements Tunable { private final View mView; private final int mDefaultSize; private final float mDensity; + private final TunerService mTunerService; - private TunablePadding(String key, int def, int flags, View view) { + private TunablePadding(String key, int def, int flags, View view, TunerService tunerService) { mDefaultSize = def; mFlags = flags; mView = view; @@ -47,7 +48,8 @@ public class TunablePadding implements Tunable { view.getContext().getSystemService(WindowManager.class) .getDefaultDisplay().getMetrics(metrics); mDensity = metrics.density; - Dependency.get(TunerService.class).addTunable(this, key); + mTunerService = tunerService; + mTunerService.addTunable(this, key); } @Override @@ -69,7 +71,7 @@ public class TunablePadding implements Tunable { } public void destroy() { - Dependency.get(TunerService.class).removeTunable(this); + mTunerService.removeTunable(this); } /** @@ -78,17 +80,20 @@ public class TunablePadding implements Tunable { @Singleton public static class TunablePaddingService { + private final TunerService mTunerService; + /** */ @Inject - public TunablePaddingService() { + public TunablePaddingService(TunerService tunerService) { + mTunerService = tunerService; } public TunablePadding add(View view, String key, int defaultSize, int flags) { if (view == null) { throw new IllegalArgumentException(); } - return new TunablePadding(key, defaultSize, flags, view); + return new TunablePadding(key, defaultSize, flags, view, mTunerService); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java b/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java index 3bfefe7b4d9bd..1e27915c1bb2d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java @@ -48,7 +48,9 @@ public class TunablePaddingTest extends LeakCheckedTest { mView = mock(View.class); when(mView.getContext()).thenReturn(mContext); - mTunerService = mDependency.injectMockDependency(TunerService.class); + mTunerService = mock(TunerService.class); + mDependency.injectTestDependency(TunablePadding.TunablePaddingService.class, + new TunablePadding.TunablePaddingService(mTunerService)); Tracker tracker = mLeakCheck.getTracker("tuner"); doAnswer(invocation -> { tracker.getLeakInfo(invocation.getArguments()[0]).addAllocation(new Throwable()); @@ -118,4 +120,4 @@ public class TunablePaddingTest extends LeakCheckedTest { mTunablePadding.destroy(); } -} \ No newline at end of file +}