Merge change 609 into donut

* changes:
  Fix the opt-in window for usage stat so that it works when running from ADT.
This commit is contained in:
Android (Google) Code Review
2009-04-27 16:08:01 -07:00
5 changed files with 104 additions and 116 deletions

View File

@@ -78,7 +78,7 @@ public class Main {
// the "ping" argument means to check in with the server and exit // the "ping" argument means to check in with the server and exit
// the application name and version number must also be supplied // the application name and version number must also be supplied
if (args.length >= 3 && args[0].equals("ping")) { if (args.length >= 3 && args[0].equals("ping")) {
SdkStatsService.ping(args[1], args[2]); SdkStatsService.ping(args[1], args[2], null);
return; return;
} else if (args.length > 0) { } else if (args.length > 0) {
Log.e("ddms", "Unknown argument: " + args[0]); Log.e("ddms", "Unknown argument: " + args[0]);
@@ -86,7 +86,7 @@ public class Main {
} }
// ddms itself is wanted: send a ping for ourselves // ddms itself is wanted: send a ping for ourselves
SdkStatsService.ping("ddms", VERSION); //$NON-NLS-1$ SdkStatsService.ping("ddms", VERSION, null); //$NON-NLS-1$
DebugPortManager.setProvider(DebugPortProvider.getInstance()); DebugPortManager.setProvider(DebugPortProvider.getInstance());

View File

@@ -5,7 +5,7 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="lib" path="jarutils.jar"/> <classpathentry kind="lib" path="jarutils.jar"/>
<classpathentry kind="lib" path="androidprefs.jar"/> <classpathentry kind="lib" path="androidprefs.jar"/>
<classpathentry kind="lib" path="sdkstats.jar"/> <classpathentry kind="lib" path="sdkstats.jar" sourcepath="/SdkStatsService"/>
<classpathentry kind="lib" path="kxml2-2.3.0.jar"/> <classpathentry kind="lib" path="kxml2-2.3.0.jar"/>
<classpathentry kind="lib" path="layoutlib_api.jar"/> <classpathentry kind="lib" path="layoutlib_api.jar"/>
<classpathentry kind="lib" path="layoutlib_utils.jar"/> <classpathentry kind="lib" path="layoutlib_utils.jar"/>

View File

@@ -31,7 +31,6 @@ import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener; import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.adt.ui.EclipseUiHelper; import com.android.ide.eclipse.adt.ui.EclipseUiHelper;
import com.android.ide.eclipse.common.AndroidConstants; import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.SdkStatsHelper;
import com.android.ide.eclipse.common.StreamHelper; import com.android.ide.eclipse.common.StreamHelper;
import com.android.ide.eclipse.common.project.BaseProjectHelper; import com.android.ide.eclipse.common.project.BaseProjectHelper;
import com.android.ide.eclipse.common.project.ExportHelper; import com.android.ide.eclipse.common.project.ExportHelper;
@@ -51,6 +50,7 @@ import com.android.ide.eclipse.editors.resources.manager.ResourceMonitor.IFileLi
import com.android.ide.eclipse.editors.xml.XmlEditor; import com.android.ide.eclipse.editors.xml.XmlEditor;
import com.android.sdklib.IAndroidTarget; import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants; import com.android.sdklib.SdkConstants;
import com.android.sdkstats.SdkStatsService;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@@ -983,13 +983,7 @@ public class AdtPlugin extends AbstractUIPlugin {
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
pingUsageServer(); //$NON-NLS-1$
// get the version of the plugin
String versionString = (String) getBundle().getHeaders().get(
Constants.BUNDLE_VERSION);
Version version = new Version(versionString);
SdkStatsHelper.pingUsageServer("adt", version); //$NON-NLS-1$
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (Throwable t) { } catch (Throwable t) {
@@ -1389,4 +1383,22 @@ public class AdtPlugin extends AbstractUIPlugin {
public static synchronized OutputStream getErrorStream() { public static synchronized OutputStream getErrorStream() {
return sPlugin.mAndroidConsoleErrorStream; return sPlugin.mAndroidConsoleErrorStream;
} }
/**
* Pings the usage start server.
* @param pluginName the name of the plugin to appear in the stats
* @param pluginVersion the {@link Version} of the plugin.
*/
private void pingUsageServer() {
// get the version of the plugin
String versionString = (String) getBundle().getHeaders().get(
Constants.BUNDLE_VERSION);
Version version = new Version(versionString);
versionString = String.format("%1$d.%2$d.%3$d", version.getMajor(), //$NON-NLS-1$
version.getMinor(), version.getMicro());
SdkStatsService.ping("adt", versionString, getDisplay()); //$NON-NLS-1$
}
} }

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
*
* 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.android.ide.eclipse.common;
import com.android.sdkstats.SdkStatsService;
import org.osgi.framework.Version;
/**
* Helper class to access the ping usage stat server.
*/
public class SdkStatsHelper {
/**
* Pings the usage start server.
* @param pluginName the name of the plugin to appear in the stats
* @param pluginVersion the {@link Version} of the plugin.
*/
public static void pingUsageServer(String pluginName, Version pluginVersion) {
String versionString = String.format("%1$d.%2$d.%3$d", pluginVersion.getMajor(),
pluginVersion.getMinor(), pluginVersion.getMicro());
SdkStatsService.ping(pluginName, versionString);
}
}

View File

@@ -110,8 +110,10 @@ public class SdkStatsService {
* *
* @param app name to report in the ping * @param app name to report in the ping
* @param version to report in the ping * @param version to report in the ping
* @param display an optional {@link Display} object to use, or null, if a new one should be
* created.
*/ */
public static void ping(final String app, final String version) { public static void ping(final String app, final String version, final Display display) {
// Validate the application and version input. // Validate the application and version input.
final String normalVersion = normalizeVersion(app, version); final String normalVersion = normalizeVersion(app, version);
@@ -123,7 +125,7 @@ public class SdkStatsService {
prefs.setValue(PING_ID, new Random().nextLong()); prefs.setValue(PING_ID, new Random().nextLong());
// Also give them a chance to opt out. // Also give them a chance to opt out.
prefs.setValue(PING_OPT_IN, getUserPermission()); prefs.setValue(PING_OPT_IN, getUserPermission(display));
try { try {
prefs.save(); prefs.save();
} }
@@ -273,10 +275,23 @@ public class SdkStatsService {
* Prompt the user for whether they want to opt out of reporting. * Prompt the user for whether they want to opt out of reporting.
* @return whether the user allows reporting (they do not opt out). * @return whether the user allows reporting (they do not opt out).
*/ */
private static boolean getUserPermission() { private static boolean getUserPermission(Display display) {
// Use dialog trim for the shell, but without a close button. // Whether the user gave permission (size-1 array for writing to).
final Display display = new Display(); // Initialize to false, set when the user clicks the button.
final Shell shell = new Shell(display, SWT.TITLE | SWT.BORDER); final boolean[] permission = new boolean[] { false };
boolean dispose = false;
if (display == null) {
display = new Display();
dispose = true;
}
final Display currentDisplay = display;
final boolean disposeDisplay = dispose;
display.syncExec(new Runnable() {
public void run() {
final Shell shell = new Shell(currentDisplay, SWT.TITLE | SWT.BORDER);
shell.setText(WINDOW_TITLE_TEXT); shell.setText(WINDOW_TITLE_TEXT);
shell.setLayout(new GridLayout(1, false)); // 1 column shell.setLayout(new GridLayout(1, false)); // 1 column
@@ -286,13 +301,13 @@ public class SdkStatsService {
for (int i = 0; i < fontdata.length; i++) { for (int i = 0; i < fontdata.length; i++) {
fontdata[i].setHeight(fontdata[i].getHeight() * 4 / 3); fontdata[i].setHeight(fontdata[i].getHeight() * 4 / 3);
} }
title.setFont(new Font(display, fontdata)); title.setFont(new Font(currentDisplay, fontdata));
title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
title.setText(HEADER_TEXT); title.setText(HEADER_TEXT);
final Label notice = new Label(shell, SWT.WRAP); final Label notice = new Label(shell, SWT.WRAP);
notice.setFont(title.getFont()); notice.setFont(title.getFont());
notice.setForeground(new Color(display, 255, 0, 0)); notice.setForeground(new Color(currentDisplay, 255, 0, 0));
notice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); notice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
notice.setText(NOTICE_TEXT); notice.setText(NOTICE_TEXT);
@@ -314,10 +329,6 @@ public class SdkStatsService {
footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
footer.setText(FOOTER_TEXT); footer.setText(FOOTER_TEXT);
// Whether the user gave permission (size-1 array for writing to).
// Initialize to false, set when the user clicks the button.
final boolean[] permission = new boolean[] { false };
final Button button = new Button(shell, SWT.PUSH); final Button button = new Button(shell, SWT.PUSH);
button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
button.setText(BUTTON_TEXT); button.setText(BUTTON_TEXT);
@@ -329,21 +340,25 @@ public class SdkStatsService {
} }
}); });
// Size the window to a fixed width, as high as necessary, centered. // Size the window to a fixed width, as high as necessary,
// centered.
final Point size = shell.computeSize(450, SWT.DEFAULT, true); final Point size = shell.computeSize(450, SWT.DEFAULT, true);
final Rectangle screen = display.getClientArea(); final Rectangle screen = currentDisplay.getClientArea();
shell.setBounds( shell.setBounds(screen.x + screen.width / 2 - size.x / 2, screen.y + screen.height
screen.x + screen.width / 2 - size.x / 2, / 2 - size.y / 2, size.x, size.y);
screen.y + screen.height / 2 - size.y / 2,
size.x, size.y);
shell.open(); shell.open();
while (!shell.isDisposed()) { while (!shell.isDisposed()) {
if (!display.readAndDispatch()) if (!currentDisplay.readAndDispatch())
display.sleep(); currentDisplay.sleep();
} }
display.dispose(); // Otherwise ddms' own Display can't be created if (disposeDisplay) {
currentDisplay.dispose();
}
}
});
return permission[0]; return permission[0];
} }