Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1a5f23e authored by Jason Monk's avatar Jason Monk
Browse files

Reduce usages of Dependency.get in TunablePadding

Test: atest SystemUITests
Change-Id: I8c99e71852d1dc572e262cf7bf722df316251f80
parent 1e968b8e
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -38,8 +38,9 @@ public class TunablePadding implements Tunable {
    private final View mView;
    private final View mView;
    private final int mDefaultSize;
    private final int mDefaultSize;
    private final float mDensity;
    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;
        mDefaultSize = def;
        mFlags = flags;
        mFlags = flags;
        mView = view;
        mView = view;
@@ -47,7 +48,8 @@ public class TunablePadding implements Tunable {
        view.getContext().getSystemService(WindowManager.class)
        view.getContext().getSystemService(WindowManager.class)
                .getDefaultDisplay().getMetrics(metrics);
                .getDefaultDisplay().getMetrics(metrics);
        mDensity = metrics.density;
        mDensity = metrics.density;
        Dependency.get(TunerService.class).addTunable(this, key);
        mTunerService = tunerService;
        mTunerService.addTunable(this, key);
    }
    }


    @Override
    @Override
@@ -69,7 +71,7 @@ public class TunablePadding implements Tunable {
    }
    }


    public void destroy() {
    public void destroy() {
        Dependency.get(TunerService.class).removeTunable(this);
        mTunerService.removeTunable(this);
    }
    }


    /**
    /**
@@ -78,17 +80,20 @@ public class TunablePadding implements Tunable {
    @Singleton
    @Singleton
    public static class TunablePaddingService {
    public static class TunablePaddingService {


        private final TunerService mTunerService;

        /**
        /**
         */
         */
        @Inject
        @Inject
        public TunablePaddingService() {
        public TunablePaddingService(TunerService tunerService) {
            mTunerService = tunerService;
        }
        }


        public TunablePadding add(View view, String key, int defaultSize, int flags) {
        public TunablePadding add(View view, String key, int defaultSize, int flags) {
            if (view == null) {
            if (view == null) {
                throw new IllegalArgumentException();
                throw new IllegalArgumentException();
            }
            }
            return new TunablePadding(key, defaultSize, flags, view);
            return new TunablePadding(key, defaultSize, flags, view, mTunerService);
        }
        }
    }
    }


+4 −2
Original line number Original line Diff line number Diff line
@@ -48,7 +48,9 @@ public class TunablePaddingTest extends LeakCheckedTest {
        mView = mock(View.class);
        mView = mock(View.class);
        when(mView.getContext()).thenReturn(mContext);
        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");
        Tracker tracker = mLeakCheck.getTracker("tuner");
        doAnswer(invocation -> {
        doAnswer(invocation -> {
            tracker.getLeakInfo(invocation.getArguments()[0]).addAllocation(new Throwable());
            tracker.getLeakInfo(invocation.getArguments()[0]).addAllocation(new Throwable());