From de850bbcaa61c1874b803f2086443febbafd81a4 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Wed, 1 Feb 2017 19:26:30 -0500 Subject: [PATCH] Fix leaks in sysui Add support for testing for PluginManager and TunerService leaks and add tests for the known leaks and fix them. Also port PluginManager and TunerService to Dependency to make them easier to handle in tests. Test: runtest systemui Change-Id: I5642539ee24dd72f802905106decd0c87b41b4eb Fixes: 34846972 --- .../systemui/plugins/PluginManager.java | 9 +--- .../plugins/statusbar/phone/NavGesture.java | 2 + .../android/systemui/BatteryMeterView.java | 4 +- .../src/com/android/systemui/Dependency.java | 21 ++++++++ .../systemui/PluginInflateContainer.java | 4 +- .../android/systemui/SystemUIApplication.java | 3 +- .../android/systemui/doze/DozeService.java | 3 +- .../fragments/PluginFragmentListener.java | 3 +- .../systemui/pip/phone/PipTouchHandler.java | 3 +- .../com/android/systemui/qs/QSAnimator.java | 5 +- .../src/com/android/systemui/qs/QSPanel.java | 9 ++-- .../com/android/systemui/qs/QuickQSPanel.java | 7 +-- .../statusbar/NotificationMenuRow.java | 16 +++++- .../systemui/statusbar/SignalClusterView.java | 4 +- .../phone/KeyguardBottomAreaView.java | 16 +++--- .../phone/NavigationBarGestureHelper.java | 7 ++- .../phone/NavigationBarInflaterView.java | 12 +++-- .../statusbar/phone/NavigationBarView.java | 14 +++-- .../systemui/statusbar/phone/QSTileHost.java | 4 +- .../phone/StatusBarIconController.java | 3 +- .../systemui/statusbar/policy/Clock.java | 4 +- .../systemui/tuner/BatteryPreference.java | 7 +-- .../systemui/tuner/ClockPreference.java | 11 ++-- .../systemui/tuner/LockscreenFragment.java | 3 +- .../android/systemui/tuner/NavBarTuner.java | 9 ++-- .../systemui/tuner/PreviewNavInflater.java | 3 +- .../systemui/tuner/StatusBarSwitch.java | 5 +- .../android/systemui/tuner/TunerActivity.java | 2 + .../android/systemui/tuner/TunerService.java | 37 +++---------- .../android/systemui/tuner/TunerSwitch.java | 5 +- .../android/systemui/volume/VolumeDialog.java | 3 +- .../volume/VolumeDialogComponent.java | 2 +- packages/SystemUI/tests/AndroidManifest.xml | 1 + .../android/systemui/FragmentTestCase.java | 32 ++++++++--- .../com/android/systemui/SysuiTestCase.java | 2 +- .../android/systemui/qs/QSFragmentTest.java | 9 ++-- .../statusbar/NotificationMenuRowTest.java | 36 +++++++++++++ .../phone/NavigationBarFragmentTest.java | 1 + .../com/android/systemui/utils/ViewUtils.java | 46 ++++++++++++++++ .../utils/leaks/FakePluginManager.java | 53 +++++++++++++++++++ .../utils/leaks/FakeTunerService.java | 42 +++++++++++++++ .../systemui/utils/leaks/LeakCheckedTest.java | 25 +++++++++ 42 files changed, 373 insertions(+), 114 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationMenuRowTest.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/utils/ViewUtils.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakePluginManager.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeTunerService.java diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginManager.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginManager.java index 471454749c2fc..f4adc93efd288 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginManager.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginManager.java @@ -70,7 +70,7 @@ public class PluginManager extends BroadcastReceiver { private boolean mListening; private boolean mHasOneShot; - private PluginManager(Context context) { + public PluginManager(Context context) { this(context, new PluginInstanceManagerFactory(), Build.IS_DEBUGGABLE, Thread.getDefaultUncaughtExceptionHandler()); } @@ -252,13 +252,6 @@ public class PluginManager extends BroadcastReceiver { return new PluginContextWrapper(mContext.createApplicationContext(info, 0), classLoader); } - public static PluginManager getInstance(Context context) { - if (sInstance == null) { - sInstance = new PluginManager(context.getApplicationContext()); - } - return sInstance; - } - private class AllPluginClassLoader extends ClassLoader { public AllPluginClassLoader(ClassLoader classLoader) { super(classLoader); diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java index 072848263a9b7..918d6e96784df 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java @@ -32,6 +32,8 @@ public interface NavGesture extends Plugin { public boolean onInterceptTouchEvent(MotionEvent event); public void setBarState(boolean vertical, boolean isRtl); + + public default void destroy() { } } } diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index b30b5968cd108..29a8da0d421c4 100644 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -76,7 +76,7 @@ public class BatteryMeterView extends ImageView implements mDrawable.setBatteryController(mBatteryController); mBatteryController.addCallback(this); mDrawable.startListening(); - TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST); + Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST); } @Override @@ -84,7 +84,7 @@ public class BatteryMeterView extends ImageView implements super.onDetachedFromWindow(); mBatteryController.removeCallback(this); mDrawable.stopListening(); - TunerService.get(getContext()).removeTunable(this); + Dependency.get(TunerService.class).removeTunable(this); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index 135b12902a256..e1f3176d808e6 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -14,6 +14,7 @@ package com.android.systemui; +import android.content.Context; import android.content.res.Configuration; import android.os.Handler; import android.os.HandlerThread; @@ -23,6 +24,7 @@ import android.util.ArrayMap; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.assist.AssistManager; +import com.android.systemui.plugins.PluginManager; import com.android.systemui.statusbar.phone.ManagedProfileController; import com.android.systemui.statusbar.phone.ManagedProfileControllerImpl; import com.android.systemui.statusbar.policy.AccessibilityController; @@ -56,9 +58,11 @@ import com.android.systemui.statusbar.policy.UserInfoControllerImpl; import com.android.systemui.statusbar.policy.UserSwitcherController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.statusbar.policy.ZenModeControllerImpl; +import com.android.systemui.tuner.TunerService; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.HashMap; /** * Class to handle ugly dependencies throughout sysui until we determine the @@ -167,12 +171,18 @@ public class Dependency extends SystemUI { mProviders.put(DeviceProvisionedController.class.getName(), () -> new DeviceProvisionedControllerImpl(mContext)); + mProviders.put(PluginManager.class.getName(), () -> + new PluginManager(mContext)); + mProviders.put(AssistManager.class.getName(), () -> new AssistManager(getDependency(DeviceProvisionedController.class), mContext)); mProviders.put(SecurityController.class.getName(), () -> new SecurityControllerImpl(mContext)); + mProviders.put(TunerService.class.getName(), () -> + new TunerService(mContext)); + // Put all dependencies above here so the factory can override them if it wants. SystemUIFactory.getInstance().injectDependencies(mProviders, mContext); } @@ -220,6 +230,17 @@ public class Dependency extends SystemUI { T createDependency(); } + /** + * Used in separate processes (like tuner settings) to init the dependencies. + */ + public static void initDependencies(Context context) { + if (sDependency != null) return; + Dependency d = new Dependency(); + d.mContext = context.getApplicationContext(); + d.mComponents = new HashMap<>(); + d.start(); + } + public static T get(Class cls) { return sDependency.getDependency(cls.getName()); } diff --git a/packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java b/packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java index efddf206878e8..9cc66138cfb47 100644 --- a/packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java +++ b/packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java @@ -76,7 +76,7 @@ public class PluginInflateContainer extends AutoReinflateContainer protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mAction != null) { - PluginManager.getInstance(getContext()).addPluginListener(mAction, this, mVersion); + Dependency.get(PluginManager.class).addPluginListener(mAction, this, mVersion); } } @@ -84,7 +84,7 @@ public class PluginInflateContainer extends AutoReinflateContainer protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAction != null) { - PluginManager.getInstance(getContext()).removePluginListener(this); + Dependency.get(PluginManager.class).removePluginListener(this); } } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 9515585df84e4..a9ac2d97903b8 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -65,7 +65,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv private final Class[] SERVICES = new Class[] { Dependency.class, FragmentService.class, - TunerService.class, NotificationChannels.class, CommandQueue.CommandQueueStart.class, KeyguardViewMediator.class, @@ -205,7 +204,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv mServices[i].onBootCompleted(); } } - PluginManager.getInstance(this).addPluginListener(OverlayPlugin.ACTION, + Dependency.get(PluginManager.class).addPluginListener(OverlayPlugin.ACTION, new PluginListener() { @Override public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java index 828728f0ae9e7..94dc9a344a34f 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java @@ -19,6 +19,7 @@ package com.android.systemui.doze; import android.service.dreams.DreamService; import android.util.Log; +import com.android.systemui.Dependency; import com.android.systemui.plugins.Plugin; import com.android.systemui.plugins.PluginManager; import com.android.systemui.plugins.doze.DozeProvider; @@ -47,7 +48,7 @@ public class DozeService extends DreamService implements DozeMachine.Service { return; } - DozeProvider provider = PluginManager.getInstance(this) + DozeProvider provider = Dependency.get(PluginManager.class) .getOneShotPlugin(DozeProvider.ACTION, DozeProvider.VERSION); mDozeMachine = new DozeFactory(provider).assembleMachine(this); } diff --git a/packages/SystemUI/src/com/android/systemui/fragments/PluginFragmentListener.java b/packages/SystemUI/src/com/android/systemui/fragments/PluginFragmentListener.java index 2e6de4ac9e352..1eaca6ffd9db3 100644 --- a/packages/SystemUI/src/com/android/systemui/fragments/PluginFragmentListener.java +++ b/packages/SystemUI/src/com/android/systemui/fragments/PluginFragmentListener.java @@ -19,6 +19,7 @@ import android.content.Context; import android.util.Log; import android.view.View; +import com.android.systemui.Dependency; import com.android.systemui.plugins.FragmentBase; import com.android.systemui.plugins.Plugin; import com.android.systemui.plugins.PluginListener; @@ -38,7 +39,7 @@ public class PluginFragmentListener implements PluginListener { Class expectedInterface) { mTag = tag; mFragmentHostManager = FragmentHostManager.get(view); - mPluginManager = PluginManager.getInstance(view.getContext()); + mPluginManager = Dependency.get(PluginManager.class); mExpectedInterface = expectedInterface; mDefaultClass = defaultFragment; } diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java index 30aa03cb2cebb..c7b15efeec9e1 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java @@ -49,6 +49,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.BackgroundThread; import com.android.internal.policy.PipMotionHelper; import com.android.internal.policy.PipSnapAlgorithm; +import com.android.systemui.Dependency; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.systemui.tuner.TunerService; @@ -200,7 +201,7 @@ public class PipTouchHandler implements TunerService.Tunable { setSnapToEdge(true); // Register any tuner settings changes - TunerService.get(context).addTunable(this, TUNER_KEY_DRAG_TO_DISMISS, + Dependency.get(TunerService.class).addTunable(this, TUNER_KEY_DRAG_TO_DISMISS, TUNER_KEY_ALLOW_MINIMIZE); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index 615063ccd0fca..c85f83ba35886 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java @@ -20,6 +20,7 @@ import android.view.View.OnAttachStateChangeListener; import android.view.View.OnLayoutChangeListener; import android.widget.TextView; +import com.android.systemui.Dependency; import com.android.systemui.plugins.qs.QS; import com.android.systemui.qs.PagedTileLayout.PageListener; import com.android.systemui.qs.QSPanel.QSTileLayout; @@ -105,7 +106,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @Override public void onViewAttachedToWindow(View v) { - TunerService.get(mQs.getContext()).addTunable(this, ALLOW_FANCY_ANIMATION, + Dependency.get(TunerService.class).addTunable(this, ALLOW_FANCY_ANIMATION, MOVE_FULL_ROWS, QuickQSPanel.NUM_QUICK_TILES); } @@ -114,7 +115,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha if (mHost != null) { mHost.removeCallback(this); } - TunerService.get(mQs.getContext()).removeTunable(this); + Dependency.get(TunerService.class).removeTunable(this); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index e0048284f6692..504678c7f1c55 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -29,6 +29,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.plugins.qs.QS; import com.android.systemui.plugins.qs.QS.DetailAdapter; @@ -126,7 +127,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - TunerService.get(mContext).addTunable(this, QS_SHOW_BRIGHTNESS); + Dependency.get(TunerService.class).addTunable(this, QS_SHOW_BRIGHTNESS); if (mHost != null) { setTiles(mHost.getTiles()); } @@ -134,8 +135,10 @@ public class QSPanel extends LinearLayout implements Tunable, Callback { @Override protected void onDetachedFromWindow() { - TunerService.get(mContext).removeTunable(this); - mHost.removeCallback(this); + Dependency.get(TunerService.class).removeTunable(this); + if (mHost != null) { + mHost.removeCallback(this); + } for (TileRecord record : mRecords) { record.tile.removeCallbacks(); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index 16b351e5b7011..d789b446c253a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -24,6 +24,7 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.Space; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.qs.QSTile.SignalState; import com.android.systemui.qs.QSTile.State; @@ -62,13 +63,13 @@ public class QuickQSPanel extends QSPanel { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - TunerService.get(mContext).addTunable(mNumTiles, NUM_QUICK_TILES); + Dependency.get(TunerService.class).addTunable(mNumTiles, NUM_QUICK_TILES); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - TunerService.get(mContext).removeTunable(mNumTiles); + Dependency.get(TunerService.class).removeTunable(mNumTiles); } public void setQSPanelAndHeader(QSPanel fullPanel, View header) { @@ -141,7 +142,7 @@ public class QuickQSPanel extends QSPanel { }; public int getNumQuickTiles(Context context) { - return TunerService.get(context).getValue(NUM_QUICK_TILES, 6); + return Dependency.get(TunerService.class).getValue(NUM_QUICK_TILES, 6); } private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java index fad63dd4f7008..355022f9794c1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java @@ -30,6 +30,7 @@ import android.widget.FrameLayout; import java.util.ArrayList; +import com.android.systemui.Dependency; import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.plugins.PluginListener; @@ -82,10 +83,21 @@ public class NotificationMenuRow extends FrameLayout public NotificationMenuRow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs); - PluginManager.getInstance(getContext()).addPluginListener( + mMenuItems.addAll(getDefaultNotificationMenuItems()); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + Dependency.get(PluginManager.class).addPluginListener( NotificationMenuRowProvider.ACTION, this, NotificationMenuRowProvider.VERSION, false /* Allow multiple */); - mMenuItems.addAll(getDefaultNotificationMenuItems()); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + Dependency.get(PluginManager.class).removePluginListener(this); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java index 9a76ad650829f..45eb5df43a06b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java @@ -220,7 +220,7 @@ public class SignalClusterView int endPadding = mMobileSignalGroup.getChildCount() > 0 ? mMobileSignalGroupEndPadding : 0; mMobileSignalGroup.setPaddingRelative(0, 0, endPadding, 0); - TunerService.get(mContext).addTunable(this, StatusBarIconController.ICON_BLACKLIST); + Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST); apply(); applyIconTint(); @@ -231,7 +231,7 @@ public class SignalClusterView @Override protected void onDetachedFromWindow() { mMobileSignalGroup.removeAllViews(); - TunerService.get(mContext).removeTunable(this); + Dependency.get(TunerService.class).removeTunable(this); mSecurityController.removeCallback(this); mNetworkController.removeCallback(this); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java index bfc0a80b31502..55bf34bbb3d9d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -257,11 +257,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL protected void onAttachedToWindow() { super.onAttachedToWindow(); mAccessibilityController.addStateChangedCallback(this); - PluginManager.getInstance(getContext()).addPluginListener(RIGHT_BUTTON_PLUGIN, + Dependency.get(PluginManager.class).addPluginListener(RIGHT_BUTTON_PLUGIN, mRightListener, IntentButtonProvider.VERSION, false /* Only allow one */); - PluginManager.getInstance(getContext()).addPluginListener(LEFT_BUTTON_PLUGIN, + Dependency.get(PluginManager.class).addPluginListener(LEFT_BUTTON_PLUGIN, mLeftListener, IntentButtonProvider.VERSION, false /* Only allow one */); - TunerService.get(getContext()).addTunable(this, LockscreenFragment.LOCKSCREEN_LEFT_BUTTON, + Dependency.get(TunerService.class).addTunable(this, LockscreenFragment.LOCKSCREEN_LEFT_BUTTON, LockscreenFragment.LOCKSCREEN_RIGHT_BUTTON); } @@ -269,9 +269,9 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mAccessibilityController.removeStateChangedCallback(this); - PluginManager.getInstance(getContext()).removePluginListener(mRightListener); - PluginManager.getInstance(getContext()).removePluginListener(mLeftListener); - TunerService.get(getContext()).removeTunable(this); + Dependency.get(PluginManager.class).removePluginListener(mRightListener); + Dependency.get(PluginManager.class).removePluginListener(mLeftListener); + Dependency.get(TunerService.class).removeTunable(this); } private void initAccessibility() { @@ -573,7 +573,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL AsyncTask.execute(runnable); } else { boolean dismissShade = !TextUtils.isEmpty(mRightButtonStr) - && TunerService.get(getContext()).getValue(LOCKSCREEN_RIGHT_UNLOCK, 1) != 0; + && Dependency.get(TunerService.class).getValue(LOCKSCREEN_RIGHT_UNLOCK, 1) != 0; mStatusBar.executeRunnableDismissingKeyguard(runnable, null /* cancelAction */, dismissShade, false /* afterKeyguardGone */, true /* deferred */); } @@ -594,7 +594,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL }); } else { boolean dismissShade = !TextUtils.isEmpty(mLeftButtonStr) - && TunerService.get(getContext()).getValue(LOCKSCREEN_LEFT_UNLOCK, 1) != 0; + && Dependency.get(TunerService.class).getValue(LOCKSCREEN_LEFT_UNLOCK, 1) != 0; mActivityStarter.startActivity(mLeftButton.getIntent(), dismissShade); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java index 228e8ea843b54..ee9a791585c49 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java @@ -29,6 +29,7 @@ import android.view.ViewConfiguration; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.RecentsComponent; import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; @@ -87,7 +88,11 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL mScrollTouchSlop = r.getDimensionPixelSize(R.dimen.navigation_bar_min_swipe_distance); mMinFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mTaskSwitcherDetector = new GestureDetector(context, this); - TunerService.get(context).addTunable(this, KEY_DOCK_WINDOW_GESTURE); + Dependency.get(TunerService.class).addTunable(this, KEY_DOCK_WINDOW_GESTURE); + } + + public void destroy() { + Dependency.get(TunerService.class).removeTunable(this); } public void setComponents(RecentsComponent recentsComponent, Divider divider, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java index 9b4867ec7c9eb..5fb99dabfeab1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java @@ -30,6 +30,7 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.Space; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.PluginManager; @@ -135,15 +136,16 @@ public class NavigationBarInflaterView extends FrameLayout @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - TunerService.get(getContext()).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT, + Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT, NAV_BAR_RIGHT); - PluginManager.getInstance(getContext()).addPluginListener(NavBarButtonProvider.ACTION, this, + Dependency.get(PluginManager.class).addPluginListener(NavBarButtonProvider.ACTION, this, NavBarButtonProvider.VERSION, true /* Allow multiple */); } @Override protected void onDetachedFromWindow() { - TunerService.get(getContext()).removeTunable(this); + Dependency.get(TunerService.class).removeTunable(this); + Dependency.get(PluginManager.class).removePluginListener(this); super.onDetachedFromWindow(); } @@ -278,10 +280,10 @@ public class NavigationBarInflaterView extends FrameLayout View v = null; String button = extractButton(buttonSpec); if (LEFT.equals(button)) { - buttonSpec = TunerService.get(mContext).getValue(NAV_BAR_LEFT, NAVSPACE); + buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE); button = extractButton(buttonSpec); } else if (RIGHT.equals(button)) { - buttonSpec = TunerService.get(mContext).getValue(NAV_BAR_RIGHT, MENU_IME); + buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME); button = extractButton(buttonSpec); } // Let plugins go first so they can override a standard view if they want. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 5e988fcaae745..dced747968aa6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -46,6 +46,7 @@ import android.view.WindowManagerGlobal; import android.view.inputmethod.InputMethodManager; import android.widget.FrameLayout; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.RecentsComponent; import com.android.systemui.plugins.PluginListener; @@ -200,7 +201,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener