Add callback to OverlayPlugin - updates forcePluginOpen
Test: manual Bug: 132075794 Change-Id: I341d121711dfefbf9a888b080faafd0110d2b8ed
This commit is contained in:
@@ -13,18 +13,28 @@
|
||||
*/
|
||||
package com.android.systemui.plugins;
|
||||
|
||||
import com.android.systemui.plugins.annotations.ProvidesInterface;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.android.systemui.plugins.annotations.ProvidesInterface;
|
||||
|
||||
@ProvidesInterface(action = OverlayPlugin.ACTION, version = OverlayPlugin.VERSION)
|
||||
public interface OverlayPlugin extends Plugin {
|
||||
|
||||
String ACTION = "com.android.systemui.action.PLUGIN_OVERLAY";
|
||||
int VERSION = 2;
|
||||
int VERSION = 3;
|
||||
|
||||
/**
|
||||
* Setup overlay plugin
|
||||
*/
|
||||
void setup(View statusBar, View navBar);
|
||||
|
||||
/**
|
||||
* Setup overlay plugin with callback
|
||||
*/
|
||||
default void setup(View statusBar, View navBar, Callback callback) {
|
||||
setup(statusBar, navBar);
|
||||
}
|
||||
|
||||
default boolean holdStatusBarOpen() {
|
||||
return false;
|
||||
}
|
||||
@@ -34,4 +44,11 @@ public interface OverlayPlugin extends Plugin {
|
||||
*/
|
||||
default void setCollapseDesired(boolean collapseDesired) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to update system ui whether to hold status bar open
|
||||
*/
|
||||
interface Callback {
|
||||
void onHoldStatusBarOpenChange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Dependency.get(PluginManager.class).addPluginListener(
|
||||
new PluginListener<OverlayPlugin>() {
|
||||
private ArraySet<OverlayPlugin> mOverlays;
|
||||
private ArraySet<OverlayPlugin> mOverlays = new ArraySet<>();
|
||||
|
||||
@Override
|
||||
public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) {
|
||||
@@ -215,18 +215,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
StatusBar statusBar = getComponent(StatusBar.class);
|
||||
if (statusBar != null) {
|
||||
plugin.setup(statusBar.getStatusBarWindow(),
|
||||
statusBar.getNavigationBarView());
|
||||
}
|
||||
// Lazy init.
|
||||
if (mOverlays == null) mOverlays = new ArraySet<>();
|
||||
if (plugin.holdStatusBarOpen()) {
|
||||
mOverlays.add(plugin);
|
||||
Dependency.get(StatusBarWindowController.class)
|
||||
.setStateListener(b -> mOverlays.forEach(
|
||||
o -> o.setCollapseDesired(b)));
|
||||
Dependency.get(StatusBarWindowController.class)
|
||||
.setForcePluginOpen(mOverlays.size() != 0);
|
||||
|
||||
statusBar.getNavigationBarView(), new Callback(plugin));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -243,6 +232,33 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class Callback implements OverlayPlugin.Callback {
|
||||
private final OverlayPlugin mPlugin;
|
||||
|
||||
Callback(OverlayPlugin plugin) {
|
||||
mPlugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHoldStatusBarOpenChange() {
|
||||
if (mPlugin.holdStatusBarOpen()) {
|
||||
mOverlays.add(mPlugin);
|
||||
} else {
|
||||
mOverlays.remove(mPlugin);
|
||||
}
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Dependency.get(StatusBarWindowController.class)
|
||||
.setStateListener(b -> mOverlays.forEach(
|
||||
o -> o.setCollapseDesired(b)));
|
||||
Dependency.get(StatusBarWindowController.class)
|
||||
.setForcePluginOpen(mOverlays.size() != 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, OverlayPlugin.class, true /* Allow multiple plugins */);
|
||||
|
||||
mServicesStarted = true;
|
||||
|
||||
Reference in New Issue
Block a user