Reduce usages of Dependency.get in TunablePadding
Test: atest SystemUITests Change-Id: I8c99e71852d1dc572e262cf7bf722df316251f80
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user