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

Commit 6ea41f31 authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge "Get WindowManager only when needed" into main

parents ee299884 44912ff9
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@ public class ToastPresenter {

    private final WeakReference<Context> mContext;
    private final Resources mResources;
    private final WeakReference<WindowManager> mWindowManager;
    private final IAccessibilityManager mAccessibilityManagerService;
    private final INotificationManager mNotificationManager;
    private final String mPackageName;
@@ -104,7 +103,6 @@ public class ToastPresenter {
            INotificationManager notificationManager, String packageName) {
        mContext = new WeakReference<>(context);
        mResources = context.getResources();
        mWindowManager = new WeakReference<>(context.getSystemService(WindowManager.class));
        mNotificationManager = notificationManager;
        mPackageName = packageName;
        mContextPackageName = context.getPackageName();
@@ -274,7 +272,7 @@ public class ToastPresenter {
    public void hide(@Nullable ITransientNotificationCallback callback) {
        checkState(mView != null, "No toast to hide.");

        final WindowManager windowManager = mWindowManager.get();
        final WindowManager windowManager = getWindowManager(mView);
        if (mView.getParent() != null && windowManager != null) {
            windowManager.removeViewImmediate(mView);
        }
@@ -295,6 +293,17 @@ public class ToastPresenter {
        mToken = null;
    }

    private WindowManager getWindowManager(View view) {
        Context context = mContext.get();
        if (context == null && view != null) {
            context = view.getContext();
        }
        if (context != null) {
            return context.getSystemService(WindowManager.class);
        }
        return null;
    }

    /**
     * Sends {@link AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED} event if accessibility is
     * enabled.
@@ -331,7 +340,7 @@ public class ToastPresenter {
    }

    private void addToastView() {
        final WindowManager windowManager = mWindowManager.get();
        final WindowManager windowManager = getWindowManager(mView);
        if (windowManager == null) {
            return;
        }