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:
@@ -78,7 +78,7 @@ public class Main {
|
||||
// the "ping" argument means to check in with the server and exit
|
||||
// the application name and version number must also be supplied
|
||||
if (args.length >= 3 && args[0].equals("ping")) {
|
||||
SdkStatsService.ping(args[1], args[2]);
|
||||
SdkStatsService.ping(args[1], args[2], null);
|
||||
return;
|
||||
} else if (args.length > 0) {
|
||||
Log.e("ddms", "Unknown argument: " + args[0]);
|
||||
@@ -86,7 +86,7 @@ public class Main {
|
||||
}
|
||||
|
||||
// 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());
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="lib" path="jarutils.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="layoutlib_api.jar"/>
|
||||
<classpathentry kind="lib" path="layoutlib_utils.jar"/>
|
||||
|
||||
@@ -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.ui.EclipseUiHelper;
|
||||
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.project.BaseProjectHelper;
|
||||
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.sdklib.IAndroidTarget;
|
||||
import com.android.sdklib.SdkConstants;
|
||||
import com.android.sdkstats.SdkStatsService;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
@@ -983,13 +983,7 @@ public class AdtPlugin extends AbstractUIPlugin {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
|
||||
// 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$
|
||||
pingUsageServer(); //$NON-NLS-1$
|
||||
|
||||
return Status.OK_STATUS;
|
||||
} catch (Throwable t) {
|
||||
@@ -1389,4 +1383,22 @@ public class AdtPlugin extends AbstractUIPlugin {
|
||||
public static synchronized OutputStream getErrorStream() {
|
||||
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$
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -110,8 +110,10 @@ public class SdkStatsService {
|
||||
*
|
||||
* @param app name 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.
|
||||
final String normalVersion = normalizeVersion(app, version);
|
||||
|
||||
@@ -123,7 +125,7 @@ public class SdkStatsService {
|
||||
prefs.setValue(PING_ID, new Random().nextLong());
|
||||
|
||||
// Also give them a chance to opt out.
|
||||
prefs.setValue(PING_OPT_IN, getUserPermission());
|
||||
prefs.setValue(PING_OPT_IN, getUserPermission(display));
|
||||
try {
|
||||
prefs.save();
|
||||
}
|
||||
@@ -273,10 +275,23 @@ public class SdkStatsService {
|
||||
* Prompt the user for whether they want to opt out of reporting.
|
||||
* @return whether the user allows reporting (they do not opt out).
|
||||
*/
|
||||
private static boolean getUserPermission() {
|
||||
// Use dialog trim for the shell, but without a close button.
|
||||
final Display display = new Display();
|
||||
final Shell shell = new Shell(display, SWT.TITLE | SWT.BORDER);
|
||||
private static boolean getUserPermission(Display display) {
|
||||
// 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 };
|
||||
|
||||
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.setLayout(new GridLayout(1, false)); // 1 column
|
||||
|
||||
@@ -286,13 +301,13 @@ public class SdkStatsService {
|
||||
for (int i = 0; i < fontdata.length; i++) {
|
||||
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.setText(HEADER_TEXT);
|
||||
|
||||
final Label notice = new Label(shell, SWT.WRAP);
|
||||
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.setText(NOTICE_TEXT);
|
||||
|
||||
@@ -314,10 +329,6 @@ public class SdkStatsService {
|
||||
footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
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);
|
||||
button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
|
||||
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 Rectangle screen = display.getClientArea();
|
||||
shell.setBounds(
|
||||
screen.x + screen.width / 2 - size.x / 2,
|
||||
screen.y + screen.height / 2 - size.y / 2,
|
||||
size.x, size.y);
|
||||
final Rectangle screen = currentDisplay.getClientArea();
|
||||
shell.setBounds(screen.x + screen.width / 2 - size.x / 2, screen.y + screen.height
|
||||
/ 2 - size.y / 2, size.x, size.y);
|
||||
|
||||
shell.open();
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch())
|
||||
display.sleep();
|
||||
if (!currentDisplay.readAndDispatch())
|
||||
currentDisplay.sleep();
|
||||
}
|
||||
|
||||
display.dispose(); // Otherwise ddms' own Display can't be created
|
||||
if (disposeDisplay) {
|
||||
currentDisplay.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return permission[0];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user