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

Commit b2b90207 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "plugin"

* changes:
  Remove view from existing clock plugin when new plugin connects.
  Update script to consider code moved to plugin_core.
parents 2e96a44f 33ce6d97
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ rm -rf /tmp/plugin_classes/
mkdir /tmp/plugin_classes

# Compile the jar
javac -cp $ANDROID_BUILD_TOP/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar:$ANDROID_BUILD_TOP/out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/classes.jar `find src -name *.java` -d /tmp/plugin_classes/
javac -cp $ANDROID_BUILD_TOP/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar:$ANDROID_BUILD_TOP/out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/classes.jar `find ../plugin*/src -name *.java` -d /tmp/plugin_classes/
echo "" >> /tmp/plugin_classes/manifest.txt
jar cvfm SystemUIPluginLib.jar /tmp/plugin_classes/manifest.txt -C /tmp/plugin_classes .

+18 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.shared.plugins.PluginManager;

import java.util.Objects;

/**
 * Switch to show plugin clock when plugin is connected, otherwise it will show default clock.
 */
@@ -35,6 +37,10 @@ public class KeyguardClockSwitch extends FrameLayout {
                public void onPluginConnected(ClockPlugin plugin, Context pluginContext) {
                    View view = plugin.getView();
                    if (view != null) {
                        disconnectPlugin();
                        // For now, assume that the most recently connected plugin is the
                        // selected clock face. In the future, the user should be able to
                        // pick a clock face from the available plugins.
                        mClockPlugin = plugin;
                        addView(view, -1,
                                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
@@ -46,10 +52,8 @@ public class KeyguardClockSwitch extends FrameLayout {

                @Override
                public void onPluginDisconnected(ClockPlugin plugin) {
                    View view = plugin.getView();
                    if (view != null) {
                        mClockPlugin = null;
                        removeView(view);
                    if (Objects.equals(plugin, mClockPlugin)) {
                        disconnectPlugin();
                        mClockView.setVisibility(View.VISIBLE);
                    }
                }
@@ -148,6 +152,16 @@ public class KeyguardClockSwitch extends FrameLayout {
        }
    }

    private void disconnectPlugin() {
        if (mClockPlugin != null) {
            View view = mClockPlugin.getView();
            if (view != null) {
                removeView(view);
            }
            mClockPlugin = null;
        }
    }

    @VisibleForTesting (otherwise = VisibleForTesting.NONE)
    PluginListener getClockPluginListener() {
        return mClockPluginListener;
+72 −11
Original line number Diff line number Diff line
@@ -21,10 +21,11 @@ import static android.view.View.VISIBLE;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import android.graphics.Color;
@@ -34,7 +35,6 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextClock;

import com.android.systemui.SysuiTestCase;
@@ -68,6 +68,7 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        mKeyguardClockSwitch =
                (KeyguardClockSwitch) layoutInflater.inflate(R.layout.keyguard_clock_switch, null);
        MockitoAnnotations.initMocks(this);
        when(mClockView.getPaint()).thenReturn(mock(TextPaint.class));
    }

    @Test
@@ -91,8 +92,6 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        ClockPlugin plugin = mock(ClockPlugin.class);
        TextClock pluginView = new TextClock(getContext());
        when(plugin.getView()).thenReturn(pluginView);
        TextPaint paint = mock(TextPaint.class);
        doReturn(paint).when(mClockView).getPaint();
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();

        listener.onPluginConnected(plugin, null);
@@ -101,23 +100,89 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        assertThat(plugin.getView().getParent()).isEqualTo(mKeyguardClockSwitch);
    }

    @Test
    public void onPluginConnected_nullView() {
        ClockPlugin plugin = mock(ClockPlugin.class);
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin, null);
        verify(mClockView, never()).setVisibility(GONE);
    }

    @Test
    public void onPluginConnected_showSecondPluginClock() {
        // GIVEN a plugin has already connected
        ClockPlugin plugin1 = mock(ClockPlugin.class);
        when(plugin1.getView()).thenReturn(new TextClock(getContext()));
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin1, null);
        // WHEN a second plugin is connected
        ClockPlugin plugin2 = mock(ClockPlugin.class);
        when(plugin2.getView()).thenReturn(new TextClock(getContext()));
        listener.onPluginConnected(plugin2, null);
        // THEN only the view from the second plugin should be a child of KeyguardClockSwitch.
        assertThat(plugin2.getView().getParent()).isEqualTo(mKeyguardClockSwitch);
        assertThat(plugin1.getView().getParent()).isNull();
    }

    @Test
    public void onPluginDisconnected_showDefaultClock() {
        ClockPlugin plugin = mock(ClockPlugin.class);
        TextClock pluginView = new TextClock(getContext());
        when(plugin.getView()).thenReturn(pluginView);
        mClockView.setVisibility(GONE);
        mKeyguardClockSwitch.addView(plugin.getView(), -1,
                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();

        listener.onPluginConnected(plugin, null);
        listener.onPluginDisconnected(plugin);

        verify(mClockView).setVisibility(VISIBLE);
        assertThat(plugin.getView().getParent()).isNull();
    }

    @Test
    public void onPluginDisconnected_nullView() {
        ClockPlugin plugin = mock(ClockPlugin.class);
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin, null);
        listener.onPluginDisconnected(plugin);
        verify(mClockView, never()).setVisibility(GONE);
    }

    @Test
    public void onPluginDisconnected_firstOfTwoDisconnected() {
        // GIVEN two plugins are connected
        ClockPlugin plugin1 = mock(ClockPlugin.class);
        when(plugin1.getView()).thenReturn(new TextClock(getContext()));
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin1, null);
        ClockPlugin plugin2 = mock(ClockPlugin.class);
        when(plugin2.getView()).thenReturn(new TextClock(getContext()));
        listener.onPluginConnected(plugin2, null);
        // WHEN the first plugin is disconnected
        listener.onPluginDisconnected(plugin1);
        // THEN the view from the second plugin is still a child of KeyguardClockSwitch.
        assertThat(plugin2.getView().getParent()).isEqualTo(mKeyguardClockSwitch);
        assertThat(plugin1.getView().getParent()).isNull();
    }

    @Test
    public void onPluginDisconnected_secondOfTwoDisconnected() {
        // GIVEN two plugins are connected
        ClockPlugin plugin1 = mock(ClockPlugin.class);
        when(plugin1.getView()).thenReturn(new TextClock(getContext()));
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin1, null);
        ClockPlugin plugin2 = mock(ClockPlugin.class);
        when(plugin2.getView()).thenReturn(new TextClock(getContext()));
        listener.onPluginConnected(plugin2, null);
        // WHEN the second plugin is disconnected
        listener.onPluginDisconnected(plugin2);
        // THEN the default clock should be shown.
        verify(mClockView).setVisibility(VISIBLE);
        assertThat(plugin1.getView().getParent()).isNull();
        assertThat(plugin2.getView().getParent()).isNull();
    }

    @Test
    public void setTextColor_defaultClockSetTextColor() {
        mKeyguardClockSwitch.setTextColor(Color.YELLOW);
@@ -130,8 +195,6 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        ClockPlugin plugin = mock(ClockPlugin.class);
        TextClock pluginView = new TextClock(getContext());
        when(plugin.getView()).thenReturn(pluginView);
        TextPaint paint = mock(TextPaint.class);
        doReturn(paint).when(mClockView).getPaint();
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin, null);

@@ -156,8 +219,6 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        ClockPlugin plugin = mock(ClockPlugin.class);
        TextClock pluginView = new TextClock(getContext());
        when(plugin.getView()).thenReturn(pluginView);
        TextPaint paint = mock(TextPaint.class);
        doReturn(paint).when(mClockView).getPaint();
        Style style = mock(Style.class);
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin, null);