Merge "Fix MetadataReporter tests" into nougat-cts-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 9064ff8..9c57f6f 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -71,6 +71,8 @@
android:debuggable="true"
android:largeHeap="true">
+ <meta-data android:name="SuiteName" android:value="CTS_VERIFIER" />
+
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIbK6ldcOzoeRtQ1u1dFVJ1A7KetRhit-a1Xa82Q" />
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/ReportExporter.java b/apps/CtsVerifier/src/com/android/cts/verifier/ReportExporter.java
index a572af6..b6908a9 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/ReportExporter.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/ReportExporter.java
@@ -49,17 +49,17 @@
*/
class ReportExporter extends AsyncTask<Void, Void, String> {
- private static final String COMMAND_LINE_ARGS = "CtsVerifier";
+ private static final String COMMAND_LINE_ARGS = "";
private static final String LOG_URL = null;
private static final String REFERENCE_URL = null;
- private static final String SUITE_NAME = "CTS_VERIFIER";
- private static final String SUITE_PLAN = "CTSVERIFIER";
+ private static final String SUITE_NAME_METADATA_KEY = "SuiteName";
+ private static final String SUITE_PLAN = "verifier";
private static final String SUITE_BUILD = "0";
private static final long START_MS = System.currentTimeMillis();
private static final long END_MS = START_MS;
- private static final String REPORT_DIRECTORY = "ctsVerifierReports";
+ private static final String REPORT_DIRECTORY = "verifierReports";
private static final String ZIP_EXTENSION = ".zip";
protected static final Logger LOG = Logger.getLogger(ReportExporter.class.getName());
@@ -90,17 +90,20 @@
File externalStorageDirectory = Environment.getExternalStorageDirectory();
File verifierReportsDir = new File(externalStorageDirectory, REPORT_DIRECTORY);
verifierReportsDir.mkdirs();
+
+ String suiteName = Version.getMetadata(mContext, SUITE_NAME_METADATA_KEY);
// create a temporary directory for this particular report
- File tempDir = new File(verifierReportsDir, getReportName());
+ File tempDir = new File(verifierReportsDir, getReportName(suiteName));
tempDir.mkdirs();
// create a File object for a report ZIP file
- File reportZipFile = new File(verifierReportsDir, getReportName() + ZIP_EXTENSION);
+ File reportZipFile = new File(
+ verifierReportsDir, getReportName(suiteName) + ZIP_EXTENSION);
try {
// Serialize the report
String versionName = Version.getVersionName(mContext);
- ResultHandler.writeResults(SUITE_NAME, versionName, SUITE_PLAN, SUITE_BUILD,
+ ResultHandler.writeResults(suiteName, versionName, SUITE_PLAN, SUITE_BUILD,
result, tempDir, START_MS, END_MS, REFERENCE_URL, LOG_URL,
COMMAND_LINE_ARGS);
@@ -144,11 +147,11 @@
}
}
- private String getReportName() {
+ private String getReportName(String suiteName) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.ENGLISH);
String date = dateFormat.format(new Date());
- return String.format( "%s-%s-%s-%s-%s",
- date, Build.MANUFACTURER, Build.PRODUCT, Build.DEVICE, Build.ID);
+ return String.format( "%s-%s-%s-%s-%s-%s",
+ date, suiteName, Build.MANUFACTURER, Build.PRODUCT, Build.DEVICE, Build.ID);
}
@Override
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/Version.java b/apps/CtsVerifier/src/com/android/cts/verifier/Version.java
index e7b6121..272fbcd 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/Version.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/Version.java
@@ -17,12 +17,18 @@
package com.android.cts.verifier;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.util.Log;
class Version {
+ private static final String TAG = Version.class.getSimpleName();
+
+ private static final String UNKNOWN = "unknown";
+
static String getVersionName(Context context) {
return getPackageInfo(context).versionName;
}
@@ -40,4 +46,19 @@
+ context.getPackageName());
}
}
+
+ static String getMetadata(Context context, String name) {
+ try {
+ PackageManager packageManager = context.getPackageManager();
+ ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
+ context.getPackageName(), PackageManager.GET_META_DATA);
+ String value = applicationInfo.metaData.getString(name);
+ if (value != null) {
+ return value;
+ }
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Version.getMetadata: " + name, e);
+ }
+ return UNKNOWN;
+ }
}
diff --git a/common/host-side/tradefed/res/config/metadata-config.xml b/common/host-side/tradefed/res/config/metadata-config.xml
new file mode 100644
index 0000000..37f1a3e
--- /dev/null
+++ b/common/host-side/tradefed/res/config/metadata-config.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<configuration description="Metadata result reporter for Compatibility suites">
+ <result_reporter class="com.android.compatibility.common.tradefed.result.MetadataReporter" />
+</configuration>