aboutsummaryrefslogtreecommitdiffstats
path: root/sdkstats
diff options
context:
space:
mode:
Diffstat (limited to 'sdkstats')
-rw-r--r--sdkstats/.classpath13
-rw-r--r--sdkstats/.gitignore2
-rw-r--r--sdkstats/.project17
-rw-r--r--sdkstats/.settings/README.txt2
-rw-r--r--sdkstats/.settings/org.eclipse.jdt.core.prefs98
-rw-r--r--sdkstats/Android.mk4
-rw-r--r--sdkstats/NOTICE190
-rw-r--r--sdkstats/README11
-rw-r--r--sdkstats/src/Android.mk15
-rwxr-xr-xsdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java332
-rw-r--r--sdkstats/src/com/android/sdkstats/SdkStatsPermissionDialog.java196
-rw-r--r--sdkstats/src/com/android/sdkstats/SdkStatsService.java558
-rwxr-xr-xsdkstats/tests/com/android/sdkstats/SdkStatsServiceTest.java544
13 files changed, 0 insertions, 1982 deletions
diff --git a/sdkstats/.classpath b/sdkstats/.classpath
deleted file mode 100644
index 023d106..0000000
--- a/sdkstats/.classpath
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="tests"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="ANDROID_OUT_FRAMEWORK/swt.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.core.commands_3.6.0.I20100512-1500.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.equinox.common_3.6.0.v20100503.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.jface_3.6.2.M20110210-1200.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry combineaccessrules="false" kind="src" path="/common"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/sdkstats/.gitignore b/sdkstats/.gitignore
deleted file mode 100644
index fe99505..0000000
--- a/sdkstats/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-bin
-
diff --git a/sdkstats/.project b/sdkstats/.project
deleted file mode 100644
index 4dbfa87..0000000
--- a/sdkstats/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>SdkStatsService</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/sdkstats/.settings/README.txt b/sdkstats/.settings/README.txt
deleted file mode 100644
index 9120b20..0000000
--- a/sdkstats/.settings/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Copy this in eclipse project as a .settings folder at the root.
-This ensure proper compilation compliance and warning/error levels. \ No newline at end of file
diff --git a/sdkstats/.settings/org.eclipse.jdt.core.prefs b/sdkstats/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 9dbff07..0000000
--- a/sdkstats/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,98 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
-org.eclipse.jdt.core.compiler.annotation.nonnull=com.android.annotations.NonNull
-org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=com.android.annotations.NonNullByDefault
-org.eclipse.jdt.core.compiler.annotation.nonnullisdefault=disabled
-org.eclipse.jdt.core.compiler.annotation.nullable=com.android.annotations.Nullable
-org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
-org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
-org.eclipse.jdt.core.compiler.problem.deadCode=warning
-org.eclipse.jdt.core.compiler.problem.deprecation=warning
-org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
-org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
-org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
-org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
-org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
-org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
-org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
-org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
-org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
-org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
-org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
-org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
-org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
-org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
-org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
-org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
-org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
-org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
-org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
-org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
-org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
-org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
-org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
-org.eclipse.jdt.core.compiler.problem.nullReference=error
-org.eclipse.jdt.core.compiler.problem.nullSpecInsufficientInfo=warning
-org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
-org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
-org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
-org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
-org.eclipse.jdt.core.compiler.problem.potentialNullSpecViolation=error
-org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
-org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
-org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
-org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
-org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=enabled
-org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
-org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
-org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
-org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
-org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
-org.eclipse.jdt.core.compiler.problem.unclosedCloseable=error
-org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
-org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
-org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
-org.eclipse.jdt.core.compiler.problem.unusedImport=warning
-org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
-org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
-org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
-org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
-org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
-org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
-org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/sdkstats/Android.mk b/sdkstats/Android.mk
deleted file mode 100644
index f4cabdc..0000000
--- a/sdkstats/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright 2007 The Android Open Source Project
-#
-SDKSTATS_LOCAL_DIR := $(call my-dir)
-include $(SDKSTATS_LOCAL_DIR)/src/Android.mk
diff --git a/sdkstats/NOTICE b/sdkstats/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/sdkstats/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
- Copyright (c) 2005-2008, 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.
-
- 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.
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
diff --git a/sdkstats/README b/sdkstats/README
deleted file mode 100644
index 8ed0880..0000000
--- a/sdkstats/README
+++ /dev/null
@@ -1,11 +0,0 @@
-How to use the Eclipse projects for SdkStats.
-
-SdkStats requires SWT to compile.
-
-SWT is available in the depot under //device/prebuild/<platform>/swt
-
-Because the build path cannot contain relative path that are not inside the project directory,
-the .classpath file references a user library called ANDROID_SWT.
-
-In order to compile the project, make a user library called ANDROID_SWT containing the jar
-available at //device/prebuild/<platform>/swt.
diff --git a/sdkstats/src/Android.mk b/sdkstats/src/Android.mk
deleted file mode 100644
index 897fed8..0000000
--- a/sdkstats/src/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright 2007 The Android Open Source Project
-#
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-LOCAL_JAVA_LIBRARIES := \
- common \
- swt \
- org.eclipse.jface_3.6.2.M20110210-1200 \
- org.eclipse.equinox.common_3.6.0.v20100503 \
- org.eclipse.core.commands_3.6.0.I20100512-1500
-LOCAL_MODULE := sdkstats
-
-include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java b/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java
deleted file mode 100755
index 890eae7..0000000
--- a/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * Copyright (C) 2007 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.android.sdkstats;
-
-import com.android.prefs.AndroidLocation;
-import com.android.prefs.AndroidLocation.AndroidLocationException;
-
-import org.eclipse.jface.preference.PreferenceStore;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Random;
-
-/**
- * Manages persistence settings for DDMS.
- *
- * For convenience, this also stores persistence settings related to the "server stats" ping
- * as well as some ADT settings that are SDK specific but not workspace specific.
- */
-public class DdmsPreferenceStore {
-
- public final static String PING_OPT_IN = "pingOptIn"; //$NON-NLS-1$
- private final static String PING_TIME = "pingTime"; //$NON-NLS-1$
- private final static String PING_ID = "pingId"; //$NON-NLS-1$
-
- private final static String ADT_USED = "adtUsed"; //$NON-NLS-1$
- private final static String LAST_SDK_PATH = "lastSdkPath"; //$NON-NLS-1$
-
- /**
- * PreferenceStore for DDMS.
- * Creation and usage must be synchronized on {@code DdmsPreferenceStore.class}.
- * Don't use it directly, instead retrieve it via {@link #getPreferenceStore()}.
- */
- private static volatile PreferenceStore sPrefStore;
-
- public DdmsPreferenceStore() {
- }
-
- /**
- * Returns the DDMS {@link PreferenceStore}.
- * This keeps a static reference on the store, so consequent calls will
- * return always the same store.
- */
- public PreferenceStore getPreferenceStore() {
- synchronized (DdmsPreferenceStore.class) {
- if (sPrefStore == null) {
- // get the location of the preferences
- String homeDir = null;
- try {
- homeDir = AndroidLocation.getFolder();
- } catch (AndroidLocationException e1) {
- // pass, we'll do a dummy store since homeDir is null
- }
-
- if (homeDir == null) {
- sPrefStore = new PreferenceStore();
- return sPrefStore;
- }
-
- assert homeDir != null;
-
- String rcFileName = homeDir + "ddms.cfg"; //$NON-NLS-1$
-
- // also look for an old pref file in the previous location
- String oldPrefPath = System.getProperty("user.home") //$NON-NLS-1$
- + File.separator + ".ddmsrc"; //$NON-NLS-1$
- File oldPrefFile = new File(oldPrefPath);
- if (oldPrefFile.isFile()) {
- FileOutputStream fileOutputStream = null;
- try {
- PreferenceStore oldStore = new PreferenceStore(oldPrefPath);
- oldStore.load();
-
- fileOutputStream = new FileOutputStream(rcFileName);
- oldStore.save(fileOutputStream, ""); //$NON-NLS-1$
- oldPrefFile.delete();
-
- PreferenceStore newStore = new PreferenceStore(rcFileName);
- newStore.load();
- sPrefStore = newStore;
- } catch (IOException e) {
- // create a new empty store.
- sPrefStore = new PreferenceStore(rcFileName);
- } finally {
- if (fileOutputStream != null) {
- try {
- fileOutputStream.close();
- } catch (IOException e) {
- // pass
- }
- }
- }
- } else {
- sPrefStore = new PreferenceStore(rcFileName);
-
- try {
- sPrefStore.load();
- } catch (IOException e) {
- System.err.println("Error Loading DDMS Preferences");
- }
- }
- }
-
- assert sPrefStore != null;
- return sPrefStore;
- }
- }
-
- /**
- * Save the prefs to the config file.
- */
- public void save() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- try {
- prefs.save();
- }
- catch (IOException ioe) {
- // FIXME com.android.dmmlib.Log.w("ddms", "Failed saving prefs file: " + ioe.getMessage());
- }
- }
- }
-
- // ---- Utility methods to access some specific prefs ----
-
- /**
- * Indicates whether the ping ID is set.
- * This should be true when {@link #isPingOptIn()} is true.
- *
- * @return true if a ping ID is set, which means the user gave permission
- * to use the ping service.
- */
- public boolean hasPingId() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- return prefs != null && prefs.contains(PING_ID);
- }
- }
-
- /**
- * Retrieves the current ping ID, if set.
- * To know if the ping ID is set, use {@link #hasPingId()}.
- * <p/>
- * There is no magic value reserved for "missing ping id or invalid store".
- * The only proper way to know if the ping id is missing is to use {@link #hasPingId()}.
- */
- public long getPingId() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- // Note: getLong() returns 0L if the ID is missing so we do that too when
- // there's no store.
- return prefs == null ? 0L : prefs.getLong(PING_ID);
- }
- }
-
- /**
- * Generates a new random ping ID and saves it in the preference store.
- *
- * @return The new ping ID.
- */
- public long generateNewPingId() {
- PreferenceStore prefs = getPreferenceStore();
-
- Random rnd = new Random();
- long id = rnd.nextLong();
-
- synchronized (DdmsPreferenceStore.class) {
- prefs.setValue(PING_ID, id);
- try {
- prefs.save();
- } catch (IOException e) {
- /* ignore exceptions while saving preferences */
- }
- }
-
- return id;
- }
-
- /**
- * Returns the "ping opt in" value from the preference store.
- * This would be true if there's a valid preference store and
- * the user opted for sending ping statistics.
- */
- public boolean isPingOptIn() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- return prefs != null && prefs.contains(PING_OPT_IN);
- }
- }
-
- /**
- * Saves the "ping opt in" value in the preference store.
- *
- * @param optIn The new user opt-in value.
- */
- public void setPingOptIn(boolean optIn) {
- PreferenceStore prefs = getPreferenceStore();
-
- synchronized (DdmsPreferenceStore.class) {
- prefs.setValue(PING_OPT_IN, optIn);
- try {
- prefs.save();
- } catch (IOException e) {
- /* ignore exceptions while saving preferences */
- }
- }
- }
-
- /**
- * Retrieves the ping time for the given app from the preference store.
- * Callers should use {@link System#currentTimeMillis()} for time stamps.
- *
- * @param app The app name identifier.
- * @return 0L if we don't have a preference store or there was no time
- * recorded in the store for the requested app. Otherwise the time stamp
- * from the store.
- */
- public long getPingTime(String app) {
- PreferenceStore prefs = getPreferenceStore();
- String timePref = PING_TIME + "." + app; //$NON-NLS-1$
- synchronized (DdmsPreferenceStore.class) {
- return prefs == null ? 0 : prefs.getLong(timePref);
- }
- }
-
- /**
- * Sets the ping time for the given app from the preference store.
- * Callers should use {@link System#currentTimeMillis()} for time stamps.
- *
- * @param app The app name identifier.
- * @param timeStamp The time stamp from the store.
- * 0L is a special value that should not be used.
- */
- public void setPingTime(String app, long timeStamp) {
- PreferenceStore prefs = getPreferenceStore();
- String timePref = PING_TIME + "." + app; //$NON-NLS-1$
- synchronized (DdmsPreferenceStore.class) {
- prefs.setValue(timePref, timeStamp);
- try {
- prefs.save();
- } catch (IOException ioe) {
- /* ignore exceptions while saving preferences */
- }
- }
- }
-
- /**
- * True if this is the first time the users runs ADT, which is detected by
- * the lack of the setting set using {@link #setAdtUsed(boolean)}
- * or this value being set to true.
- *
- * @return true if ADT has been used before
- *
- * @see #setAdtUsed(boolean)
- */
- public boolean isAdtUsed() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- if (prefs == null || !prefs.contains(ADT_USED)) {
- return false;
- }
- return prefs.getBoolean(ADT_USED);
- }
- }
-
- /**
- * Sets whether the ADT startup wizard has been shown.
- * ADT sets first to false once the welcome wizard has been shown once.
- *
- * @param used true if ADT has been used
- */
- public void setAdtUsed(boolean used) {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- prefs.setValue(ADT_USED, used);
- try {
- prefs.save();
- } catch (IOException ioe) {
- /* ignore exceptions while saving preferences */
- }
- }
- }
-
- /**
- * Retrieves the last SDK OS path.
- * <p/>
- * This is just an information value, the path may not exist, may not
- * even be on an existing file system and/or may not point to an SDK
- * anymore.
- *
- * @return The last SDK OS path from the preference store, or null if
- * there is no store or an empty string if it is not defined.
- */
- public String getLastSdkPath() {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- return prefs == null ? null : prefs.getString(LAST_SDK_PATH);
- }
- }
-
- /**
- * Sets the last SDK OS path.
- *
- * @param osSdkPath The SDK OS Path. Can be null or empty.
- */
- public void setLastSdkPath(String osSdkPath) {
- PreferenceStore prefs = getPreferenceStore();
- synchronized (DdmsPreferenceStore.class) {
- prefs.setValue(LAST_SDK_PATH, osSdkPath);
- try {
- prefs.save();
- } catch (IOException ioe) {
- /* ignore exceptions while saving preferences */
- }
- }
- }
-}
diff --git a/sdkstats/src/com/android/sdkstats/SdkStatsPermissionDialog.java b/sdkstats/src/com/android/sdkstats/SdkStatsPermissionDialog.java
deleted file mode 100644
index f9856cc..0000000
--- a/sdkstats/src/com/android/sdkstats/SdkStatsPermissionDialog.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2011 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.android.sdkstats;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.program.Program;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Shell;
-
-import java.io.IOException;
-
-/**
- * Dialog to get user permission for ping service.
- */
-public class SdkStatsPermissionDialog extends Dialog {
- /* Text strings displayed in the opt-out dialog. */
- private static final String HEADER_TEXT =
- "Thanks for using the Android SDK!";
-
- /** Used in the ADT welcome wizard as well. */
- public static final String NOTICE_TEXT =
- "We know you just want to get started but please read this first.";
-
- /** Used in the preference pane (PrefsDialog) as well. */
- public static final String BODY_TEXT =
- "By choosing to send certain usage statistics to Google, you can " +
- "help us improve the Android SDK. These usage statistics lets us " +
- "measure things like active usage of the SDK, and let us know things " +
- "like which versions of the SDK are in use and which tools are the " +
- "most popular with developers. This limited data is not associated " +
- "with personal information about you, and is examined on an aggregate " +
- "basis, and is maintained in accordance with the Google Privacy Policy.";
-
- /** Used in the ADT welcome wizard as well. */
- public static final String PRIVACY_POLICY_LINK_TEXT =
- "<a href=\"http://www.google.com/intl/en/privacy.html\">Google " +
- "Privacy Policy</a>";
-
- /** Used in the preference pane (PrefsDialog) as well. */
- public static final String CHECKBOX_TEXT =
- "Send usage statistics to Google.";
-
- /** Used in the ADT welcome wizard as well. */
- public static final String FOOTER_TEXT =
- "If you later decide to change this setting, you can do so in the" +
- "\"ddms\" tool under \"File\" > \"Preferences\" > \"Usage Stats\".";
-
- private static final String BUTTON_TEXT = "Proceed";
-
- /** List of Linux browser commands to try, in order (see openUrl). */
- private static final String[] LINUX_BROWSERS = new String[] {
- "firefox -remote openurl(%URL%,new-window)", //$NON-NLS-1$ running FF
- "mozilla -remote openurl(%URL%,new-window)", //$NON-NLS-1$ running Moz
- "firefox %URL%", //$NON-NLS-1$ new FF
- "mozilla %URL%", //$NON-NLS-1$ new Moz
- "kfmclient openURL %URL%", //$NON-NLS-1$ Konqueror
- "opera -newwindow %URL%", //$NON-NLS-1$ Opera
- };
-
- private static final boolean ALLOW_PING_DEFAULT = true;
- private boolean mAllowPing = ALLOW_PING_DEFAULT;
-
- public SdkStatsPermissionDialog(Shell parentShell) {
- super(parentShell);
- setBlockOnOpen(true);
- }
-
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- createButton(parent, Window.OK, BUTTON_TEXT, true);
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
- composite.setLayout(new GridLayout(1, false));
-
- final Label title = new Label(composite, SWT.CENTER | SWT.WRAP);
- final FontData[] fontdata = title.getFont().getFontData();
- for (int i = 0; i < fontdata.length; i++) {
- fontdata[i].setHeight(fontdata[i].getHeight() * 4 / 3);
- }
- title.setFont(new Font(getShell().getDisplay(), fontdata));
- title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- title.setText(HEADER_TEXT);
-
- final Label notice = new Label(composite, SWT.WRAP);
- notice.setFont(title.getFont());
- notice.setForeground(new Color(getShell().getDisplay(), 255, 0, 0));
- notice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- notice.setText(NOTICE_TEXT);
- notice.pack();
-
- final Label bodyText = new Label(composite, SWT.WRAP);
- GridData gd = new GridData();
- gd.widthHint = notice.getSize().x; // do not extend beyond the NOTICE text's width
- gd.grabExcessHorizontalSpace = true;
- bodyText.setLayoutData(gd);
- bodyText.setText(BODY_TEXT);
-
- final Link privacyLink = new Link(composite, SWT.NO_FOCUS);
- privacyLink.setText(PRIVACY_POLICY_LINK_TEXT);
- privacyLink.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- openUrl(event.text);
- }
- });
-
- final Button checkbox = new Button(composite, SWT.CHECK);
- checkbox.setSelection(ALLOW_PING_DEFAULT);
- checkbox.setText(CHECKBOX_TEXT);
- checkbox.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- mAllowPing = checkbox.getSelection();
- }
- });
- checkbox.setFocus();
-
- final Label footer = new Label(composite, SWT.WRAP);
- gd = new GridData();
- gd.widthHint = notice.getSize().x;
- gd.grabExcessHorizontalSpace = true;
- footer.setLayoutData(gd);
- footer.setText(FOOTER_TEXT);
-
- return composite;
- }
-
- /**
- * Open a URL in an external browser.
- * @param url to open - MUST be sanitized and properly formed!
- */
- public static void openUrl(final String url) {
- // TODO: consider using something like BrowserLauncher2
- // (http://browserlaunch2.sourceforge.net/) instead of these hacks.
-
- // SWT's Program.launch() should work on Mac, Windows, and GNOME
- // (because the OS shell knows how to launch a default browser).
- if (!Program.launch(url)) {
- // Must be Linux non-GNOME (or something else broke).
- // Try a few Linux browser commands in the background.
- new Thread() {
- @Override
- public void run() {
- for (String cmd : LINUX_BROWSERS) {
- cmd = cmd.replaceAll("%URL%", url); //$NON-NLS-1$
- try {
- Process proc = Runtime.getRuntime().exec(cmd);
- if (proc.waitFor() == 0) break; // Success!
- } catch (InterruptedException e) {
- // Should never happen!
- throw new RuntimeException(e);
- } catch (IOException e) {
- // Swallow the exception and try the next browser.
- }
- }
-
- // TODO: Pop up some sort of error here?
- // (We're in a new thread; can't use the existing Display.)
- }
- }.start();
- }
- }
-
- public boolean getPingUserPreference() {
- return mAllowPing;
- }
-}
diff --git a/sdkstats/src/com/android/sdkstats/SdkStatsService.java b/sdkstats/src/com/android/sdkstats/SdkStatsService.java
deleted file mode 100644
index 79c2ef5..0000000
--- a/sdkstats/src/com/android/sdkstats/SdkStatsService.java
+++ /dev/null
@@ -1,558 +0,0 @@
-/*
- * Copyright (C) 2007 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.android.sdkstats;
-
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/** Utility class to send "ping" usage reports to the server. */
-public class SdkStatsService {
-
- protected static final String SYS_PROP_OS_ARCH = "os.arch"; //$NON-NLS-1$
- protected static final String SYS_PROP_JAVA_VERSION = "java.version"; //$NON-NLS-1$
- protected static final String SYS_PROP_OS_VERSION = "os.version"; //$NON-NLS-1$
- protected static final String SYS_PROP_OS_NAME = "os.name"; //$NON-NLS-1$
-
- /** Minimum interval between ping, in milliseconds. */
- private static final long PING_INTERVAL_MSEC = 86400 * 1000; // 1 day
-
- private static final boolean DEBUG = System.getenv("ANDROID_DEBUG_PING") != null; //$NON-NLS-1$
-
- private DdmsPreferenceStore mStore = new DdmsPreferenceStore();
-
- public SdkStatsService() {
- }
-
- /**
- * Send a "ping" to the Google toolbar server, if enough time has
- * elapsed since the last ping, and if the user has not opted out.
- * <p/>
- * This is a simplified version of {@link #ping(String[])} that only
- * sends an "application" name and a "version" string. See the explanation
- * there for details.
- *
- * @param app The application name that reports the ping (e.g. "emulator" or "ddms".)
- * Valid characters are a-zA-Z0-9 only.
- * @param version The version string (e.g. "12" or "1.2.3.4", 4 groups max.)
- * @see #ping(String[])
- */
- public void ping(String app, String version) {
- doPing(app, version, null);
- }
-
- /**
- * Send a "ping" to the Google toolbar server, if enough time has
- * elapsed since the last ping, and if the user has not opted out.
- * <p/>
- * The ping will not be sent if the user opt out dialog has not been shown yet.
- * Use {@link #checkUserPermissionForPing(Shell)} to display the dialog requesting
- * user permissions.
- * <p/>
- * Note: The actual ping (if any) is sent in a <i>non-daemon</i> background thread.
- * <p/>
- * The arguments are defined as follow:
- * <ul>
- * <li>Argument 0 is the "ping" command and is ignored.</li>
- * <li>Argument 1 is the application name that reports the ping (e.g. "emulator" or "ddms".)
- * Valid characters are a-zA-Z0-9 only.</li>
- * <li>Argument 2 is the version string (e.g. "12" or "1.2.3.4", 4 groups max.)</li>
- * <li>Arguments 3+ are optional and depend on the application name.</li>
- * <li>"emulator" application currently has 3 optional arguments:
- * <ul>
- * <li>Arugment 3: android_gl_vendor</li>
- * <li>Arugment 4: android_gl_renderer</li>
- * <li>Arugment 5: android_gl_version</li>
- * </ul>
- * </li>
- * </ul>
- *
- * @param arguments A non-empty non-null array of arguments to the ping as described above.
- */
- public void ping(String[] arguments) {
- if (arguments == null || arguments.length < 3) {
- throw new IllegalArgumentException(
- "Invalid ping arguments: expected ['ping', app, version] but got " +
- (arguments == null ? "null" : Arrays.toString(arguments)));
- }
- int len = arguments.length;
- String app = arguments[1];
- String version = arguments[2];
-
- Map<String, String> extras = new HashMap<String, String>();
-
- if ("emulator".equals(app)) { //$NON-NLS-1$
- if (len > 3) {
- extras.put("glm", sanitizeGlArg(arguments[3])); //$NON-NLS-1$ vendor
- }
- if (len > 4) {
- extras.put("glr", sanitizeGlArg(arguments[4])); //$NON-NLS-1$ renderer
- }
- if (len > 5) {
- extras.put("glv", sanitizeGlArg(arguments[5])); //$NON-NLS-1$ version
- }
- }
-
- doPing(app, version, extras);
- }
-
- private String sanitizeGlArg(String arg) {
- if (arg == null) {
- arg = ""; //$NON-NLS-1$
- } else {
- try {
- arg = arg.trim();
- arg = arg.replaceAll("[^A-Za-z0-9\\s_()./-]", " "); //$NON-NLS-1$ //$NON-NLS-2$
- arg = arg.replaceAll("\\s\\s+", " "); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Guard from arbitrarily long parameters
- if (arg.length() > 128) {
- arg = arg.substring(0, 128);
- }
-
- arg = URLEncoder.encode(arg, "UTF-8"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
- arg = ""; //$NON-NLS-1$
- }
- }
-
- return arg;
- }
-
- /**
- * Display a dialog to the user providing information about the ping service,
- * and whether they'd like to opt-out of it.
- *
- * Once the dialog has been shown, it sets a preference internally indicating
- * that the user has viewed this dialog.
- */
- public void checkUserPermissionForPing(Shell parent) {
- if (!mStore.hasPingId()) {
- askUserPermissionForPing(parent);
- mStore.generateNewPingId();
- }
- }
-
- /**
- * Prompt the user for whether they want to opt out of reporting, and save the user
- * input in preferences.
- */
- private void askUserPermissionForPing(final Shell parent) {
- final Display display = parent.getDisplay();
- display.syncExec(new Runnable() {
- @Override
- public void run() {
- SdkStatsPermissionDialog dialog = new SdkStatsPermissionDialog(parent);
- dialog.open();
- mStore.setPingOptIn(dialog.getPingUserPreference());
- }
- });
- }
-
- // -------
-
- /**
- * Pings the usage stats server, as long as the prefs contain the opt-in boolean
- *
- * @param app The application name that reports the ping (e.g. "emulator" or "ddms".)
- * Will be normalized. Valid characters are a-zA-Z0-9 only.
- * @param version The version string (e.g. "12" or "1.2.3.4", 4 groups max.)
- * @param extras Extra key/value parameters to send. They are send as-is and must
- * already be well suited and escaped using {@link URLEncoder#encode(String, String)}.
- */
- protected void doPing(String app, String version, final Map<String, String> extras) {
- // Note: if you change the implementation here, you also need to change
- // the overloaded SdkStatsServiceTest.doPing() used for testing.
-
- // Validate the application and version input.
- final String nApp = normalizeAppName(app);
- final String nVersion = normalizeVersion(version);
-
- // If the user has not opted in, do nothing and quietly return.
- if (!mStore.isPingOptIn()) {
- // user opted out.
- return;
- }
-
- // If the last ping *for this app* was too recent, do nothing.
- long now = System.currentTimeMillis();
- long then = mStore.getPingTime(app);
- if (now - then < PING_INTERVAL_MSEC) {
- // too soon after a ping.
- return;
- }
-
- // Record the time of the attempt, whether or not it succeeds.
- mStore.setPingTime(app, now);
-
- // Send the ping itself in the background (don't block if the
- // network is down or slow or confused).
- final long id = mStore.getPingId();
- new Thread() {
- @Override
- public void run() {
- try {
- URL url = createPingUrl(nApp, nVersion, id, extras);
- actuallySendPing(url);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }.start();
- }
-
-
- /**
- * Unconditionally send a "ping" request to the server.
- *
- * @param url The URL to send to the server.
- * * @throws IOException if the ping failed
- */
- private void actuallySendPing(URL url) throws IOException {
- assert url != null;
-
- if (DEBUG) {
- System.err.println("Ping: " + url.toString()); //$NON-NLS-1$
- }
-
- // Discard the actual response, but make sure it reads OK
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
-
- // Believe it or not, a 404 response indicates success:
- // the ping was logged, but no update is configured.
- if (conn.getResponseCode() != HttpURLConnection.HTTP_OK &&
- conn.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
- throw new IOException(
- conn.getResponseMessage() + ": " + url); //$NON-NLS-1$
- }
- }
-
- /**
- * Compute the ping URL to send the data to the server.
- *
- * @param app The application name that reports the ping (e.g. "emulator" or "ddms".)
- * Valid characters are a-zA-Z0-9 only.
- * @param version The version string already formatted as a 4 dotted group (e.g. "1.2.3.4".)
- * @param id of the local installation
- * @param extras Extra key/value parameters to send. They are send as-is and must
- * already be well suited and escaped using {@link URLEncoder#encode(String, String)}.
- */
- protected URL createPingUrl(String app, String version, long id, Map<String, String> extras)
- throws UnsupportedEncodingException, MalformedURLException {
-
- String osName = URLEncoder.encode(getOsName(), "UTF-8"); //$NON-NLS-1$
- String osArch = URLEncoder.encode(getOsArch(), "UTF-8"); //$NON-NLS-1$
- String jvmArch = URLEncoder.encode(getJvmInfo(), "UTF-8"); //$NON-NLS-1$
-
- // Include the application's name as part of the as= value.
- // Share the user ID for all apps, to allow unified activity reports.
-
- String extraStr = ""; //$NON-NLS-1$
- if (extras != null && !extras.isEmpty()) {
- StringBuilder sb = new StringBuilder();
- for (Map.Entry<String, String> entry : extras.entrySet()) {
- sb.append('&').append(entry.getKey()).append('=').append(entry.getValue());
- }
- extraStr = sb.toString();
- }
-
- URL url = new URL(
- "http", //$NON-NLS-1$
- "tools.google.com", //$NON-NLS-1$
- "/service/update?as=androidsdk_" + app + //$NON-NLS-1$
- "&id=" + Long.toHexString(id) + //$NON-NLS-1$
- "&version=" + version + //$NON-NLS-1$
- "&os=" + osName + //$NON-NLS-1$
- "&osa=" + osArch + //$NON-NLS-1$
- "&vma=" + jvmArch + //$NON-NLS-1$
- extraStr);
- return url;
- }
-
- /**
- * Detects and reports the host OS: "linux", "win" or "mac".
- * For Windows and Mac also append the version, so for example
- * Win XP will return win-5.1.
- */
- protected String getOsName() { // made protected for testing
- String os = getSystemProperty(SYS_PROP_OS_NAME);
-
- if (os == null || os.length() == 0) {
- return "unknown"; //$NON-NLS-1$
- }
-
- String os2 = os.toLowerCase(Locale.US);
-
- if (os2.startsWith("mac")) { //$NON-NLS-1$
- os = "mac"; //$NON-NLS-1$
- String osVers = getOsVersion();
- if (osVers != null) {
- os = os + '-' + osVers;
- }
- } else if (os2.startsWith("win")) { //$NON-NLS-1$
- os = "win"; //$NON-NLS-1$
- String osVers = getOsVersion();
- if (osVers != null) {
- os = os + '-' + osVers;
- }
- } else if (os2.startsWith("linux")) { //$NON-NLS-1$
- os = "linux"; //$NON-NLS-1$
-
- } else if (os.length() > 32) {
- // Unknown -- send it verbatim so we can see it
- // but protect against arbitrarily long values
- os = os.substring(0, 32);
- }
- return os;
- }
-
- /**
- * Detects and returns the OS architecture: x86, x86_64, ppc.
- * This may differ or be equal to the JVM architecture in the sense that
- * a 64-bit OS can run a 32-bit JVM.
- */
- protected String getOsArch() { // made protected for testing
- String arch = getJvmArch();
-
- if ("x86_64".equals(arch)) { //$NON-NLS-1$
- // This is a simple case: the JVM runs in 64-bit so the
- // OS must be a 64-bit one.
- return arch;
-
- } else if ("x86".equals(arch)) { //$NON-NLS-1$
- // This is the misleading case: the JVM is 32-bit but the OS
- // might be either 32 or 64. We can't tell just from this
- // property.
- // Macs are always on 64-bit, so we just need to figure it
- // out for Windows and Linux.
-
- String os = getOsName();
- if (os.startsWith("win")) { //$NON-NLS-1$
- // When WOW64 emulates a 32-bit environment under a 64-bit OS,
- // it sets PROCESSOR_ARCHITEW6432 to AMD64 or IA64 accordingly.
- // Ref: http://msdn.microsoft.com/en-us/library/aa384274(v=vs.85).aspx
-
- String w6432 = getSystemEnv("PROCESSOR_ARCHITEW6432"); //$NON-NLS-1$
- if (w6432 != null && w6432.indexOf("64") != -1) { //$NON-NLS-1$
- return "x86_64"; //$NON-NLS-1$
- }
- } else if (os.startsWith("linux")) { //$NON-NLS-1$
- // Let's try the obvious. This works in Ubuntu and Debian
- String s = getSystemEnv("HOSTTYPE"); //$NON-NLS-1$
-
- s = sanitizeOsArch(s);
- if (s.indexOf("86") != -1) { //$NON-NLS-1$
- arch = s;
- }
- }
- }
-
- return arch;
- }
-
- /**
- * Returns the version of the OS version if it is defined as X.Y, or null otherwise.
- * <p/>
- * Example of returned versions can be found at http://lopica.sourceforge.net/os.html
- * <p/>
- * This method removes any exiting micro versions.
- * Returns null if the version doesn't match X.Y.Z.
- */
- protected String getOsVersion() { // made protected for testing
- Pattern p = Pattern.compile("(\\d+)\\.(\\d+).*"); //$NON-NLS-1$
- String osVers = getSystemProperty(SYS_PROP_OS_VERSION);
- if (osVers != null && osVers.length() > 0) {
- Matcher m = p.matcher(osVers);
- if (m.matches()) {
- return m.group(1) + '.' + m.group(2);
- }
- }
- return null;
- }
-
- /**
- * Detects and returns the JVM info: version + architecture.
- * Examples: 1.4-ppc, 1.6-x86, 1.7-x86_64
- */
- protected String getJvmInfo() { // made protected for testing
- return getJvmVersion() + '-' + getJvmArch();
- }
-
- /**
- * Returns the major.minor Java version.
- * <p/>
- * The "java.version" property returns something like "1.6.0_20"
- * of which we want to return "1.6".
- */
- protected String getJvmVersion() { // made protected for testing
- String version = getSystemProperty(SYS_PROP_JAVA_VERSION);
-
- if (version == null || version.length() == 0) {
- return "unknown"; //$NON-NLS-1$
- }
-
- Pattern p = Pattern.compile("(\\d+)\\.(\\d+).*"); //$NON-NLS-1$
- Matcher m = p.matcher(version);
- if (m.matches()) {
- return m.group(1) + '.' + m.group(2);
- }
-
- // Unknown version. Send it as-is within a reasonable size limit.
- if (version.length() > 8) {
- version = version.substring(0, 8);
- }
- return version;
- }
-
- /**
- * Detects and returns the JVM architecture.
- * <p/>
- * The HotSpot JVM has a private property for this, "sun.arch.data.model",
- * which returns either "32" or "64". However it's not in any kind of spec.
- * <p/>
- * What we want is to know whether the JVM is running in 32-bit or 64-bit and
- * the best indicator is to use the "os.arch" property.
- * - On a 32-bit system, only a 32-bit JVM can run so it will be x86 or ppc.<br/>
- * - On a 64-bit system, a 32-bit JVM will also return x86 since the OS needs
- * to masquerade as a 32-bit OS for backward compatibility.<br/>
- * - On a 64-bit system, a 64-bit JVM will properly return x86_64.
- * <pre>
- * JVM: Java 32-bit Java 64-bit
- * Windows: x86 x86_64
- * Linux: x86 x86_64
- * Mac untested x86_64
- * </pre>
- */
- protected String getJvmArch() { // made protected for testing
- String arch = getSystemProperty(SYS_PROP_OS_ARCH);
- return sanitizeOsArch(arch);
- }
-
- private String sanitizeOsArch(String arch) {
- if (arch == null || arch.length() == 0) {
- return "unknown"; //$NON-NLS-1$
- }
-
- if (arch.equalsIgnoreCase("x86_64") || //$NON-NLS-1$
- arch.equalsIgnoreCase("ia64") || //$NON-NLS-1$
- arch.equalsIgnoreCase("amd64")) { //$NON-NLS-1$
- return "x86_64"; //$NON-NLS-1$
- }
-
- if (arch.length() >= 4 && arch.charAt(0) == 'i' && arch.indexOf("86") == 2) { //$NON-NLS-1$
- // Any variation of iX86 counts as x86 (i386, i486, i686).
- return "x86"; //$NON-NLS-1$
- }
-
- if (arch.equalsIgnoreCase("PowerPC")) { //$NON-NLS-1$
- return "ppc"; //$NON-NLS-1$
- }
-
- // Unknown arch. Send it as-is but protect against arbitrarily long values.
- if (arch.length() > 32) {
- arch = arch.substring(0, 32);
- }
- return arch;
- }
-
- /**
- * Normalize the supplied application name.
- *
- * @param app to report
- */
- protected String normalizeAppName(String app) {
- // Filter out \W , non-word character: [^a-zA-Z_0-9]
- String app2 = app.replaceAll("\\W", ""); //$NON-NLS-1$ //$NON-NLS-2$
-
- if (app.length() == 0) {
- throw new IllegalArgumentException("Bad app name: " + app); //$NON-NLS-1$
- }
-
- return app2;
- }
-
- /**
- * Validate the supplied application version, and normalize the version.
- *
- * @param version supplied by caller
- * @return normalized dotted quad version
- */
- protected String normalizeVersion(String version) {
-
- Pattern regex = Pattern.compile(
- //1=major 2=minor 3=micro 4=build | 5=rc
- "^(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\.(\\d+)| +rc(\\d+))?"); //$NON-NLS-1$
-
- Matcher m = regex.matcher(version);
- if (m != null && m.lookingAt()) {
- StringBuilder normal = new StringBuilder();
- for (int i = 1; i <= 4; i++) {
- int v = 0;
- // If build is null but we have an rc, take that number instead as the 4th part.
- if (i == 4 &&
- i < m.groupCount() &&
- m.group(i) == null &&
- m.group(i+1) != null) {
- i++;
- }
- if (m.group(i) != null) {
- try {
- v = Integer.parseInt(m.group(i));
- } catch (Exception ignore) {
- }
- }
- if (i > 1) {
- normal.append('.');
- }
- normal.append(v);
- }
- return normal.toString();
- }
-
- throw new IllegalArgumentException("Bad version: " + version); //$NON-NLS-1$
- }
-
- /**
- * Calls {@link System#getProperty(String)}.
- * Allows unit-test to override the return value.
- * @see System#getProperty(String)
- */
- protected String getSystemProperty(String name) {
- return System.getProperty(name);
- }
-
- /**
- * Calls {@link System#getenv(String)}.
- * Allows unit-test to override the return value.
- * @see System#getenv(String)
- */
- protected String getSystemEnv(String name) {
- return System.getenv(name);
- }
-}
diff --git a/sdkstats/tests/com/android/sdkstats/SdkStatsServiceTest.java b/sdkstats/tests/com/android/sdkstats/SdkStatsServiceTest.java
deleted file mode 100755
index 9982bb7..0000000
--- a/sdkstats/tests/com/android/sdkstats/SdkStatsServiceTest.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Copyright (C) 2012 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.android.sdkstats;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-public class SdkStatsServiceTest extends TestCase {
-
- private static class MockSdkStatsService extends SdkStatsService {
-
- private final String mOsName;
- private final String mOsVersion;
- private final String mOsArch;
- private final String mJavaVersion;
- private final Map<String, String> mEnvVars = new HashMap<String, String>();
- private URL mPingUrlResult;
-
- public MockSdkStatsService(String osName,
- String osVersion,
- String osArch,
- String javaVersion) {
- mOsName = osName;
- mOsVersion = osVersion;
- mOsArch = osArch;
- mJavaVersion = javaVersion;
- }
-
- public URL getPingUrlResult() {
- return mPingUrlResult;
- }
-
- public void setSystemEnv(String varName, String value) {
- mEnvVars.put(varName, value);
- }
-
- @Override
- protected String getSystemProperty(String name) {
- if (SdkStatsService.SYS_PROP_OS_NAME.equals(name)) {
- return mOsName;
- } else if (SdkStatsService.SYS_PROP_OS_VERSION.equals(name)) {
- return mOsVersion;
- } else if (SdkStatsService.SYS_PROP_OS_ARCH.equals(name)) {
- return mOsArch;
- } else if (SdkStatsService.SYS_PROP_JAVA_VERSION.equals(name)) {
- return mJavaVersion;
- }
- // Don't use current properties values, we don't want the tests to be flaky
- fail("SdkStatsServiceTest doesn't define a system.property for " + name);
- return null;
- }
-
- @Override
- protected String getSystemEnv(String name) {
- if (mEnvVars.containsKey(name)) {
- return mEnvVars.get(name);
- }
- // Don't use current env vars, we don't want the tests to be flaky
- fail("SdkStatsServiceTest doesn't define a system.getenv for " + name);
- return null;
- }
-
- @Override
- protected void doPing(String app, String version,
- Map<String, String> extras) {
- // The super.doPing() does:
- // 1- normalize input,
- // 2- check the ping time,
- // 3- check/create the pind id,
- // 4- create the ping URL
- // 5- and send the network ping in a thread.
- // In this mock version we just do steps 1 and 4 and record the URL;
- // obvious we don't check the ping time in the prefs nor send the actual ping.
-
- // Validate the application and version input.
- final String nApp = normalizeAppName(app);
- final String nVersion = normalizeVersion(version);
-
- long id = 0x42;
- try {
- mPingUrlResult = createPingUrl(nApp, nVersion, id, extras);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testSdkStatsService_getJvmArch() {
- MockSdkStatsService m;
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", "1.7");
- assertEquals("x86", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "i386", "1.7");
- assertEquals("x86", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "i486", "1.7");
- assertEquals("x86", m.getJvmArch());
- m = new MockSdkStatsService("Linux", "4.0", "i486-linux", "1.7");
- assertEquals("x86", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "i586", "1.7");
- assertEquals("x86", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "i686", "1.7");
- assertEquals("x86", m.getJvmArch());
-
- m = new MockSdkStatsService("Mac OS", "10.0", "x86_64", "1.7");
- assertEquals("x86_64", m.getJvmArch());
- m = new MockSdkStatsService("Mac OS", "8.0", "PowerPC", "1.7");
- assertEquals("ppc", m.getJvmArch());
-
- m = new MockSdkStatsService("Mac OS", "4.0", "x86_64", "1.7");
- assertEquals("x86_64", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "ia64", "1.7");
- assertEquals("x86_64", m.getJvmArch());
- m = new MockSdkStatsService("Windows", "4.0", "amd64", "1.7");
- assertEquals("x86_64", m.getJvmArch());
-
- m = new MockSdkStatsService("Windows", "4.0", "atom", "1.7");
- assertEquals("atom", m.getJvmArch());
-
- // 32 chars max
- m = new MockSdkStatsService("Windows", "4.0",
- "one3456789ten3456789twenty6789thirty6789", "1.7");
- assertEquals("one3456789ten3456789twenty6789th", m.getJvmArch());
-
- m = new MockSdkStatsService("Windows", "4.0", "", "1.7");
- assertEquals("unknown", m.getJvmArch());
-
- m = new MockSdkStatsService("Windows", "4.0", null, "1.7");
- assertEquals("unknown", m.getJvmArch());
- }
-
- public void testSdkStatsService_getJvmVersion() {
- MockSdkStatsService m;
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", "1.7.8_09");
- assertEquals("1.7", m.getJvmVersion());
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", "");
- assertEquals("unknown", m.getJvmVersion());
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", null);
- assertEquals("unknown", m.getJvmVersion());
-
- // 8 chars max
- m = new MockSdkStatsService("Windows", "4.0", "x86",
- "one3456789ten3456789twenty6789thirty6789");
- assertEquals("one34567", m.getJvmVersion());
- }
-
- public void testSdkStatsService_getJvmInfo() {
- MockSdkStatsService m;
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", "1.7.8_09");
- assertEquals("1.7-x86", m.getJvmInfo());
-
- m = new MockSdkStatsService("Windows", "4.0", "amd64", "1.7.8_09");
- assertEquals("1.7-x86_64", m.getJvmInfo());
-
- m = new MockSdkStatsService("Windows", "4.0", "", "");
- assertEquals("unknown-unknown", m.getJvmInfo());
-
- m = new MockSdkStatsService("Windows", "4.0", null, null);
- assertEquals("unknown-unknown", m.getJvmInfo());
-
- // 8+32 chars max
- m = new MockSdkStatsService("Windows", "4.0",
- "one3456789ten3456789twenty6789thirty6789",
- "one3456789ten3456789twenty6789thirty6789");
- assertEquals("one34567-one3456789ten3456789twenty6789th", m.getJvmInfo());
- }
-
- public void testSdkStatsService_getOsVersion() {
- MockSdkStatsService m;
-
- m = new MockSdkStatsService("Windows", "4.0.32", "x86", "1.7.8_09");
- assertEquals("4.0", m.getOsVersion());
-
- m = new MockSdkStatsService("Windows", "4.0", "x86", "1.7.8_09");
- assertEquals("4.0", m.getOsVersion());
-
- m = new MockSdkStatsService("Windows", "4", "x86", "1.7.8_09");
- assertEquals(null, m.getOsVersion());
-
- m = new MockSdkStatsService("Windows", "4.0;extrainfo", "x86", "1.7.8_09");
- assertEquals("4.0", m.getOsVersion());
-
- m = new MockSdkStatsService("Mac OS", "10.8.32", "x86_64", "1.7.8_09");
- assertEquals("10.8", m.getOsVersion());
-
- m = new MockSdkStatsService("Mac OS", "10.8", "x86_64", "1.7.8_09");
- assertEquals("10.8", m.getOsVersion());
-
- m = new MockSdkStatsService("Other", "", "x86_64", "1.7.8_09");
- assertEquals(null, m.getOsVersion());
-
- m = new MockSdkStatsService("Other", null, "x86_64", "1.7.8_09");
- assertEquals(null, m.getOsVersion());
- }
-
- public void testSdkStatsService_getOsArch() {
- MockSdkStatsService m;
-
- // 64 bit jvm
- m = new MockSdkStatsService("Mac OS", "10.8.32", "x86_64", "1.7.8_09");
- assertEquals("x86_64", m.getOsArch());
-
- m = new MockSdkStatsService("Windows", "8.32", "x86_64", "1.7.8_09");
- assertEquals("x86_64", m.getOsArch());
-
- m = new MockSdkStatsService("Linux", "8.32", "x86_64", "1.7.8_09");
- assertEquals("x86_64", m.getOsArch());
-
- // 32 bit jvm with 32 vs 64 bit os
- m = new MockSdkStatsService("Windows", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("PROCESSOR_ARCHITEW6432", null);
- assertEquals("x86", m.getOsArch());
-
- m = new MockSdkStatsService("Windows", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("PROCESSOR_ARCHITEW6432", "AMD64");
- assertEquals("x86_64", m.getOsArch());
-
- m = new MockSdkStatsService("Windows", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("PROCESSOR_ARCHITEW6432", "IA64");
- assertEquals("x86_64", m.getOsArch());
-
- // 32 bit jvm with 32 vs 64 bit os
- m = new MockSdkStatsService("Linux", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("HOSTTYPE", null);
- assertEquals("x86", m.getOsArch());
-
- m = new MockSdkStatsService("Linux", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("HOSTTYPE", "i686-linux");
- assertEquals("x86", m.getOsArch());
-
- m = new MockSdkStatsService("Linux", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("HOSTTYPE", "AMD64");
- assertEquals("x86_64", m.getOsArch());
-
- m = new MockSdkStatsService("Linux", "8.32", "x86", "1.7.8_09");
- m.setSystemEnv("HOSTTYPE", "x86_64");
- assertEquals("x86_64", m.getOsArch());
- }
-
- public void testSdkStatsService_getOsName() {
- MockSdkStatsService m;
-
- m = new MockSdkStatsService("Mac OS", "10.8.32", "x86_64", "1.7.8_09");
- assertEquals("mac-10.8", m.getOsName());
-
- m = new MockSdkStatsService("mac", "10", "x86", "1.7.8_09");
- assertEquals("mac", m.getOsName());
-
- m = new MockSdkStatsService("Windows", "6.2", "x86_64", "1.7.8_09");
- assertEquals("win-6.2", m.getOsName());
-
- m = new MockSdkStatsService("win", "6.2", "x86", "1.7.8_09");
- assertEquals("win-6.2", m.getOsName());
-
- m = new MockSdkStatsService("win", "6", "x86_64", "1.7.8_09");
- assertEquals("win", m.getOsName());
-
- m = new MockSdkStatsService("Linux", "foobuntu-32", "x86", "1.7.8_09");
- assertEquals("linux", m.getOsName());
-
- m = new MockSdkStatsService("linux", "1", "x86_64", "1.7.8_09");
- assertEquals("linux", m.getOsName());
-
- m = new MockSdkStatsService("PowerPC", "32", "ppc", "1.7.8_09");
- assertEquals("PowerPC", m.getOsName());
-
- m = new MockSdkStatsService("freebsd", "42", "x86_64", "1.7.8_09");
- assertEquals("freebsd", m.getOsName());
-
- m = new MockSdkStatsService("openbsd", "43", "x86_64", "1.7.8_09");
- assertEquals("openbsd", m.getOsName());
-
- // 32 chars max
- m = new MockSdkStatsService("one3456789ten3456789twenty6789thirty6789",
- "42", "x86_64", "1.7.8_09");
- assertEquals("one3456789ten3456789twenty6789th", m.getOsName());
- }
-
- public void testSdkStatsService_parseVersion() {
- // Tests that the version parses supports the new "major.minor.micro rcPreview" format
- // as well as "x.y.z.t" formats as well as Eclipse's "x.y.z.v2012somedate" formats.
-
- MockSdkStatsService m;
- m = new MockSdkStatsService("Windows", "6.2", "x86_64", "1.7.8_09");
-
- m.ping("monitor", "21");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.1");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.1.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.2.03");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.2.3.4");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.4&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // More than 4 parts or extra stuff that is not an "rc" preview are ignored.
- m.ping("monitor", "21.2.3.4.5.6.7.8");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.4&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.2.3.4.v20120101 the rest is ignored");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.4&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // If the "rc" preview integer is present, it's equivalent to a 4th number.
- m.ping("monitor", "21 rc4");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.0.0.4&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.01 rc5");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.1.0.5&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- m.ping("monitor", "21.02.03 rc6");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.6&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // If there's a 4-part version number, the rc preview number isn't used.
- m.ping("monitor", "21.2.3.4 rc7");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_monitor&" +
- "id=42&" +
- "version=21.2.3.4&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // For Eclipse plugins, the 4th part might be a date. It is ignored.
- m.ping("eclipse", "21.2.3.v20120102235958");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_eclipse&" +
- "id=42&" +
- "version=21.2.3.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
- }
-
- public void testSdkStatsService_glPing() {
- MockSdkStatsService m;
- m = new MockSdkStatsService("Windows", "6.2", "x86_64", "1.7.8_09");
-
- // Send emulator ping with just emulator version, no GL stuff
- m.ping("emulator", "12");
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // Send emulator ping with just emulator version, no GL stuff.
- // This is the same request but using the variable string list API, arg 0 is the "ping" app.
- m.ping(new String[] { "ping", "emulator", "12" });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // Send a ping for a non-emulator app with extra parameters, no GL stuff
- m.ping(new String[] { "ping", "not-emulator", "12", "arg1", "arg2", "arg3" });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_notemulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64",
- m.getPingUrlResult().toString());
-
- // Send a ping for the emulator app with extra parameters, GL stuff is added, 3 parameters
- m.ping(new String[] { "ping", "emulator", "12", "Vendor Inc.", "Some cool_GPU!!! (fast one!)", "1.2.3.4_preview" });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64&" +
- "glm=Vendor+Inc.&" +
- "glr=Some+cool_GPU+%28fast+one+%29&" +
- "glv=1.2.3.4_preview",
- m.getPingUrlResult().toString());
-
- // Send a ping for the emulator app with extra parameters, GL stuff is added, 2 parameters
- m.ping(new String[] { "ping", "emulator", "12", "Vendor Inc.", "Some cool_GPU!!! (fast one!)" });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64&" +
- "glm=Vendor+Inc.&" +
- "glr=Some+cool_GPU+%28fast+one+%29",
- m.getPingUrlResult().toString());
-
- // Send a ping for the emulator app with extra parameters, GL stuff is added, 1 parameter
- m.ping(new String[] { "ping", "emulator", "12", "Vendor Inc." });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64&" +
- "glm=Vendor+Inc.",
- m.getPingUrlResult().toString());
-
- // Parameters that are more than 128 chars are cut short.
- m.ping(new String[] { "ping", "emulator", "12",
- // 130 chars each
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" });
- assertEquals(
- "http://tools.google.com/service/update?" +
- "as=androidsdk_emulator&" +
- "id=42&" +
- "version=12.0.0.0&" +
- "os=win-6.2&" +
- "osa=x86_64&" +
- "vma=1.7-x86_64&" +
- "glm=01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567&" +
- "glr=01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567&" +
- "glv=01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567",
- m.getPingUrlResult().toString());
- }
-}