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

Commit 421a9410 authored by Jason Monk's avatar Jason Monk
Browse files

SysUI: Add method for plugins to keep status bar full screen

Lots of things detect overlays these days (installing apps) and the
only way to avoid the problems associated with this is to live in
the status bar window. So allow plugins to hold the window open
when they want to so they can have overlays be in that.

Move StatusBarWindowManager to Dependency to make things easier
as well.

Test: Install the example plugin, test can access QS and interact
      with apps

Change-Id: Ib2288bf56704960847217bad01a480ab407e0ffe
parent f4872e41
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -27,3 +27,13 @@ LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_JAR_EXCLUDE_FILES := none

include $(BUILD_STATIC_JAVA_LIBRARY)

include $(CLEAR_VARS)

# Dummy to generate .toc files.
LOCAL_PACKAGE_NAME := PluginDummyLib
LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_JAVA_LIBRARIES := SystemUIPluginLib

include $(BUILD_PACKAGE)
+37 −0
Original line number Diff line number Diff line
@@ -15,11 +15,14 @@
package com.android.systemui.plugin.testoverlayplugin;

import android.content.Context;
import android.graphics.Rect;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.view.ViewTreeObserver.InternalInsetsInfo;
import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
import com.android.systemui.plugins.OverlayPlugin;

public class SampleOverlayPlugin implements OverlayPlugin {
@@ -28,6 +31,9 @@ public class SampleOverlayPlugin implements OverlayPlugin {

    private View mStatusBarView;
    private View mNavBarView;
    private boolean mInputSetup;
    private boolean mCollapseDesired;
    private float mStatusBarHeight;

    @Override
    public int getVersion() {
@@ -43,6 +49,10 @@ public class SampleOverlayPlugin implements OverlayPlugin {

    @Override
    public void onDestroy() {
        if (mInputSetup) {
            mStatusBarView.getViewTreeObserver().removeOnComputeInternalInsetsListener(
                    onComputeInternalInsetsListener);
        }
        Log.d(TAG, "onDestroy");
        if (mStatusBarView != null) {
            mStatusBarView.post(
@@ -57,6 +67,9 @@ public class SampleOverlayPlugin implements OverlayPlugin {
    public void setup(View statusBar, View navBar) {
        Log.d(TAG, "Setup");

        int id = mPluginContext.getResources().getIdentifier("status_bar_height", "dimen",
                "android");
        mStatusBarHeight = mPluginContext.getResources().getDimension(id);
        if (statusBar instanceof ViewGroup) {
            mStatusBarView = LayoutInflater.from(mPluginContext)
                    .inflate(R.layout.colored_overlay, (ViewGroup) statusBar, false);
@@ -68,4 +81,28 @@ public class SampleOverlayPlugin implements OverlayPlugin {
            ((ViewGroup) navBar).addView(mNavBarView);
        }
    }

    @Override
    public void setCollapseDesired(boolean collapseDesired) {
        mCollapseDesired = collapseDesired;
    }

    @Override
    public boolean holdStatusBarOpen() {
        if (!mInputSetup) {
            mInputSetup = true;
            mStatusBarView.getViewTreeObserver().addOnComputeInternalInsetsListener(
                    onComputeInternalInsetsListener);
        }
        return true;
    }

    final OnComputeInternalInsetsListener onComputeInternalInsetsListener = inoutInfo -> {
        inoutInfo.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
        if (mCollapseDesired) {
            inoutInfo.touchableRegion.set(new Rect(0, 0, 50000, (int) mStatusBarHeight));
        } else {
            inoutInfo.touchableRegion.set(new Rect(0, 0, 50000, 50000));
        }
    };
}
+10 −0
Original line number Diff line number Diff line
@@ -21,4 +21,14 @@ public interface OverlayPlugin extends Plugin {
    int VERSION = 1;

    void setup(View statusBar, View navBar);

    default boolean holdStatusBarOpen() {
        return false;
    }

    /**
     * Only called if the plugin has returned true to holdStatusBarOpen().
     */
    default void setCollapseDesired(boolean collapseDesired) {
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ 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.phone.StatusBarWindowManager;
import com.android.systemui.statusbar.policy.AccessibilityController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BatteryControllerImpl;
@@ -183,6 +184,9 @@ public class Dependency extends SystemUI {
        mProviders.put(TunerService.class.getName(), () ->
                new TunerService(mContext));

        mProviders.put(StatusBarWindowManager.class.getName(), () ->
                new StatusBarWindowManager(mContext));

        // Put all dependencies above here so the factory can override them if it wants.
        SystemUIFactory.getInstance().injectDependencies(mProviders, mContext);
    }
+31 −12
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.res.Configuration;
import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Log;

import com.android.systemui.fragments.FragmentService;
@@ -43,6 +44,7 @@ import com.android.systemui.shortcut.ShortcutKeyDispatcher;
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarWindowManager;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.usb.StorageNotification;
import com.android.systemui.util.NotificationChannels;
@@ -149,7 +151,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
     * Makes sure that all the SystemUI services are running. If they are already running, this is a
     * no-op. This is needed to conditinally start all the services, as we only need to have it in
     * the main process.
     *
     * <p>This method must only be called from the main thread.</p>
     */
    public void startServicesIfNeeded() {
@@ -160,7 +161,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
     * Ensures that all the Secondary user SystemUI services are running. If they are already
     * running, this is a no-op. This is needed to conditinally start all the services, as we only
     * need to have it in the main process.
     *
     * <p>This method must only be called from the main thread.</p>
     */
    void startSecondaryUserServicesIfNeeded() {
@@ -207,6 +207,8 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
        }
        Dependency.get(PluginManager.class).addPluginListener(OverlayPlugin.ACTION,
                new PluginListener<OverlayPlugin>() {
                    private ArraySet<OverlayPlugin> mOverlays;

                    @Override
                    public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) {
                        StatusBar statusBar = getComponent(StatusBar.class);
@@ -214,6 +216,23 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
                            plugin.setup(statusBar.getStatusBarWindow(),
                                    statusBar.getNavigationBarView());
                        }
                        // Lazy init.
                        if (mOverlays == null) mOverlays = new ArraySet<>();
                        if (plugin.holdStatusBarOpen()) {
                            mOverlays.add(plugin);
                            Dependency.get(StatusBarWindowManager.class).setStateListener(b ->
                                    mOverlays.forEach(o -> o.setCollapseDesired(b)));
                            Dependency.get(StatusBarWindowManager.class).setForcePluginOpen(
                                    mOverlays.size() != 0);

                        }
                    }

                    @Override
                    public void onPluginDisconnected(OverlayPlugin plugin) {
                        mOverlays.remove(plugin);
                        Dependency.get(StatusBarWindowManager.class).setForcePluginOpen(
                                mOverlays.size() != 0);
                    }
                }, OverlayPlugin.VERSION, true /* Allow multiple plugins */);

Loading