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

Commit bcfe19eb authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

Merge "Take a wrench to the pipes" into oc-dr1-dev

am: e1036c93

Change-Id: I1a4606bc6996df2aa4b67645fbb06f0c2b46cd5c
parents d0ee6987 e1036c93
Loading
Loading
Loading
Loading
+44 −26
Original line number Diff line number Diff line
@@ -14,56 +14,74 @@

package com.android.systemui;

import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.IDockedStackListener;
import android.view.WindowManagerGlobal;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.function.Consumer;

/**
 * Utility wrapper to listen for whether or not a docked stack exists, to be
 * used for things like the different overview icon in that mode.
 */
public class DockedStackExistsListener extends IDockedStackListener.Stub {
public class DockedStackExistsListener {

    private static final String TAG = "DockedStackExistsListener";

    private final Consumer<Boolean> mCallback;

    private DockedStackExistsListener(Consumer<Boolean> callback) {
        mCallback = callback;
    }
    private static ArrayList<WeakReference<Consumer<Boolean>>> sCallbacks = new ArrayList<>();

    static {
        try {
            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(
                    new IDockedStackListener.Stub() {
                        @Override
    public void onDividerVisibilityChanged(boolean visible) throws RemoteException {
                        public void onDividerVisibilityChanged(boolean b) throws RemoteException {

                        }

                        @Override
    public void onDockedStackExistsChanged(final boolean exists) throws RemoteException {
        mCallback.accept(exists);
                        public void onDockedStackExistsChanged(boolean exists)
                                throws RemoteException {
                            DockedStackExistsListener.onDockedStackExistsChanged(exists);
                        }

                        @Override
    public void onDockedStackMinimizedChanged(boolean minimized, long animDuration,
                                              boolean isHomeStackResizable) throws RemoteException {
                        public void onDockedStackMinimizedChanged(boolean b, long l, boolean b1)
                                throws RemoteException {

                        }

                        @Override
    public void onAdjustedForImeChanged(boolean adjustedForIme, long animDuration)
                        public void onAdjustedForImeChanged(boolean b, long l)
                                throws RemoteException {

                        }

                        @Override
    public void onDockSideChanged(int newDockSide) throws RemoteException {
    }
                        public void onDockSideChanged(int i) throws RemoteException {

    public static void register(Consumer<Boolean> callback) {
        try {
            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(
                    new DockedStackExistsListener(callback));
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Failed registering docked stack exists listener", e);
        }
    }


    private static void onDockedStackExistsChanged(boolean exists) {
        synchronized (sCallbacks) {
            sCallbacks.removeIf(wf -> wf.get() == null);
            sCallbacks.forEach(wf -> wf.get().accept(exists));
        }
    }

    public static void register(Consumer<Boolean> callback) {
        synchronized (sCallbacks) {
            sCallbacks.add(new WeakReference<>(callback));
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public class ExtensionFragmentListener<T extends FragmentBase> implements Consum
        mFragmentHostManager.getFragmentManager().beginTransaction()
                .replace(id, (Fragment) mExtension.get(), mTag)
                .commit();
        mExtension.clearItem(false);
    }

    @Override
@@ -57,6 +58,7 @@ public class ExtensionFragmentListener<T extends FragmentBase> implements Consum
        } catch (ClassCastException e) {
            Log.e(TAG, extension.getClass().getName() + " must be a Fragment", e);
        }
        mExtension.clearItem(true);
    }

    public static <T> void attachExtensonToFragment(View view, String tag, int id,
+7 −0
Original line number Diff line number Diff line
@@ -38,6 +38,13 @@ public interface ExtensionController {
         * (like configuration) may have changed.
         */
        T reload();

        /**
         * Null out the cached item for the purpose of memory saving, should only be done
         * when any other references are already gotten.
         * @param isDestroyed
         */
        void clearItem(boolean isDestroyed);
    }

    interface ExtensionBuilder<T> {
+13 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.plugins.PluginManager;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.util.leak.LeakDetector;

import java.util.ArrayList;
import java.util.Collections;
@@ -146,7 +147,18 @@ public class ExtensionControllerImpl implements ExtensionController {
            return get();
        }

        @Override
        public void clearItem(boolean isDestroyed) {
            if (isDestroyed && mItem != null) {
                Dependency.get(LeakDetector.class).trackGarbage(mItem);
            }
            mItem = null;
        }

        private void notifyChanged() {
            if (mItem != null) {
                Dependency.get(LeakDetector.class).trackGarbage(mItem);
            }
            mItem = null;
            for (int i = 0; i < mProducers.size(); i++) {
                final T item = mProducers.get(i).get();
@@ -169,7 +181,7 @@ public class ExtensionControllerImpl implements ExtensionController {
        }

        public void addTunerFactory(TunerFactory<T> factory, String[] keys) {
            mProducers.add(new TunerItem(factory, factory.keys()));
            mProducers.add(new TunerItem(factory, keys));
        }

        public void addUiMode(int uiMode, Supplier<T> mode) {
+5 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;

import com.android.systemui.Dependency;
@@ -84,12 +85,15 @@ public class GarbageMonitor {
        // TODO(b/35345376): Turn this back on for debuggable builds after known leak fixed.
        private static final boolean ENABLED = Build.IS_DEBUGGABLE
                && SystemProperties.getBoolean("debug.enable_leak_reporting", false);
        private static final String FORCE_ENABLE = "sysui_force_garbage_monitor";

        private GarbageMonitor mGarbageMonitor;

        @Override
        public void start() {
            if (!ENABLED) {
            boolean forceEnable = Settings.Secure.getInt(mContext.getContentResolver(),
                    FORCE_ENABLE, 0) != 0;
            if (!ENABLED && !forceEnable) {
                return;
            }
            mGarbageMonitor = Dependency.get(GarbageMonitor.class);
Loading