diff options
author | Stas Negara <snegara@google.com> | 2015-07-28 14:06:07 -0700 |
---|---|---|
committer | Stas Negara <snegara@google.com> | 2015-07-28 14:06:07 -0700 |
commit | 9cc831cd73596f2244d2a85a2b15988baafe5998 (patch) | |
tree | 796877b04aff5e341a205fdd098ef48f40c3a251 | |
parent | 95e24bc963882eaf92a2c6c375efdbdc33555b92 (diff) | |
download | testing-9cc831cd73596f2244d2a85a2b15988baafe5998.tar.gz |
Add blank VNC window for launching cloud devices.
Change-Id: I6d3daf4b709d7916c2cf16252b40cf14241be6da
-rw-r--r-- | src/com/google/gct/testing/CloudConfigurationProviderImpl.java | 3 | ||||
-rw-r--r-- | src/com/google/gct/testing/vnc/BlankVncViewer.java | 72 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java index 734f2bf..87614b2 100644 --- a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java +++ b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java @@ -48,6 +48,7 @@ import com.google.gct.testing.results.GoogleCloudTestListener; import com.google.gct.testing.results.GoogleCloudTestResultsConnectionUtil; import com.google.gct.testing.results.GoogleCloudTestingResultParser; import com.google.gct.testing.util.CloudTestingTracking; +import com.google.gct.testing.vnc.BlankVncViewer; import com.intellij.execution.DefaultExecutionResult; import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionResult; @@ -342,6 +343,7 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { } String configurationName = ConfigurationInstance.parseFromEncodedString(ghostCloudDevice.getEncodedConfigurationInstance()).getResultsViewerDisplayString(); + BlankVncViewer blankVncViewer = BlankVncViewer.showBlankVncViewer(configurationName); final long POLLING_INTERVAL = 10 * 1000; // 10 seconds final long INITIAL_TIMEOUT = 10 * 60 * 1000; // 10 minutes long stopTime = System.currentTimeMillis() + INITIAL_TIMEOUT; @@ -377,6 +379,7 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { synchronized (ghostCloudDevices) { ghostCloudDevices.remove(ghostCloudDevice); } + blankVncViewer.closeWindow(); // Make sure the device is unlocked. Process unlock = rt.exec("./adb -s " + deviceAddress + " wait-for-device shell input keyevent 82" , null, dir); unlock.waitFor(); diff --git a/src/com/google/gct/testing/vnc/BlankVncViewer.java b/src/com/google/gct/testing/vnc/BlankVncViewer.java new file mode 100644 index 0000000..49f9d82 --- /dev/null +++ b/src/com/google/gct/testing/vnc/BlankVncViewer.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.gct.testing.vnc; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; + +public class BlankVncViewer extends JApplet implements Runnable { + private final String myConfigurationName; + private JFrame blankFrame; + private WindowListener exitListener; + + public BlankVncViewer(String configurationName) { + myConfigurationName = configurationName; + exitListener = new WindowAdapter() { + + @Override + public void windowClosing(WindowEvent e) { + int confirm = JOptionPane.showOptionDialog(blankFrame, + "Are you sure you want to close the window? Closing the window will delete the Google Cloud instance.", + "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, + null, null); + if (confirm == 0) { + System.out.println("Exiting blank VNC Viewer"); + blankFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + } + } + }; + } + + @Override + public void run() { + blankFrame = new JFrame("Launching Cloud Device"); + blankFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + blankFrame.addWindowListener(exitListener); + JLabel infoLabel = new JLabel("Launching " + myConfigurationName, SwingConstants.CENTER); + infoLabel.setPreferredSize(new Dimension(600, 100)); + + blankFrame.getContentPane().add(infoLabel, BorderLayout.CENTER); + + blankFrame.pack(); + blankFrame.setVisible(true); + } + + public void closeWindow() { + blankFrame.removeWindowListener(exitListener); + blankFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + blankFrame.dispatchEvent(new WindowEvent(blankFrame, WindowEvent.WINDOW_CLOSING)); + } + + public static BlankVncViewer showBlankVncViewer(String configurationName) { + BlankVncViewer blankViewer = new BlankVncViewer(configurationName); + SwingUtilities.invokeLater(blankViewer); + return blankViewer; + } +} |