Merge "Only reboot into bootloader if necessary"
diff --git a/prod-tests/src/com/android/app/tests/AppLaunchTest.java b/prod-tests/src/com/android/app/tests/AppLaunchTest.java
index 47207ca..bc4a423 100644
--- a/prod-tests/src/com/android/app/tests/AppLaunchTest.java
+++ b/prod-tests/src/com/android/app/tests/AppLaunchTest.java
@@ -43,6 +43,7 @@
  */
 public class AppLaunchTest implements IDeviceTest, IRemoteTest, IBuildReceiver {
 
+    private static final String RUN_NAME = "AppLaunch";
     private ITestDevice mDevice;
     private IBuildInfo mBuild;
 
@@ -76,7 +77,7 @@
     @Override
     public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
         long startTime = System.currentTimeMillis();
-        listener.testRunStarted("app_launch", 2);
+        listener.testRunStarted(RUN_NAME, 2);
         try {
             Assert.assertTrue(mBuild instanceof IAppBuildInfo);
             IAppBuildInfo appBuild = (IAppBuildInfo)mBuild;
@@ -115,6 +116,7 @@
     private void performLaunchTest(String packageName, ITestInvocationListener listener)
             throws DeviceNotAvailableException {
         InstrumentationTest i = new InstrumentationTest();
+        i.setRunName(RUN_NAME);
         i.setPackageName("com.android.applaunchtest");
         i.setRunnerName("com.android.applaunchtest.AppLaunchRunner");
         i.setDevice(getDevice());
diff --git a/src/com/android/tradefed/util/brillopad/parser/BugreportParser.java b/src/com/android/tradefed/util/brillopad/parser/BugreportParser.java
index d31c870..2fe2d3f 100644
--- a/src/com/android/tradefed/util/brillopad/parser/BugreportParser.java
+++ b/src/com/android/tradefed/util/brillopad/parser/BugreportParser.java
@@ -47,7 +47,8 @@
     private static final String MEM_INFO_SECTION_REGEX = "------ MEMORY INFO .*";
     private static final String PROCRANK_SECTION_REGEX = "------ PROCRANK .*";
     private static final String SYSTEM_PROP_SECTION_REGEX = "------ SYSTEM PROPERTIES .*";
-    private static final String SYSTEM_LOG_SECTION_REGEX = "------ (SYSTEM|MAIN) LOG .*";
+    private static final String SYSTEM_LOG_SECTION_REGEX =
+            "------ (SYSTEM|MAIN|MAIN AND SYSTEM) LOG .*";
     private static final String ANR_TRACES_SECTION_REGEX = "------ VM TRACES AT LAST ANR .*";
     private static final String NOOP_SECTION_REGEX = "------ .*";
 
diff --git a/tests/src/com/android/tradefed/util/brillopad/parser/BugreportParserTest.java b/tests/src/com/android/tradefed/util/brillopad/parser/BugreportParserTest.java
index 8077550..5691595 100644
--- a/tests/src/com/android/tradefed/util/brillopad/parser/BugreportParserTest.java
+++ b/tests/src/com/android/tradefed/util/brillopad/parser/BugreportParserTest.java
@@ -330,5 +330,18 @@
         BugreportItem bugreport = new BugreportParser().parse(lines);
         assertNotNull(bugreport.getSystemLog());
     }
+
+    /**
+     * Some Android devices refer to SYSTEM LOG as MAIN AND SYSTEM LOG. Check that parser
+     * recognizes this alternate syntax.
+     */
+    public void testSystemAndMainLog() {
+        List<String> lines = Arrays.asList(
+                "------ MAIN AND SYSTEM LOG (logcat -b main -b system -v threadtime -d *:v) ------",
+                "--------- beginning of /dev/log/system",
+                "12-17 15:15:12.877  1994  2019 D UiModeManager: updateConfigurationLocked: ");
+        BugreportItem bugreport = new BugreportParser().parse(lines);
+        assertNotNull(bugreport.getSystemLog());
+    }
 }
 
diff --git a/util-apps/DismissKeyguardUtil/Android.mk b/util-apps/DismissKeyguardUtil/Android.mk
new file mode 100644
index 0000000..91b8934
--- /dev/null
+++ b/util-apps/DismissKeyguardUtil/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SDK_VERSION := 8
+LOCAL_PACKAGE_NAME := DismissKeyguardUtil
+
+include $(BUILD_PACKAGE)
+
diff --git a/util-apps/DismissKeyguardUtil/AndroidManifest.xml b/util-apps/DismissKeyguardUtil/AndroidManifest.xml
new file mode 100644
index 0000000..c4d00c6
--- /dev/null
+++ b/util-apps/DismissKeyguardUtil/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.tradefed.utils">
+
+    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+
+    <application>
+        <receiver android:name=".DismissKeyguardIntentReceiver" >
+            <intent-filter>
+                <action android:name="com.android.tradefed.utils.DISMISS_KEYGUARD" />
+            </intent-filter>
+        </receiver>
+
+        <service android:name=".DismissKeyguardService" />
+    </application>
+
+</manifest>
diff --git a/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardIntentReceiver.java b/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardIntentReceiver.java
new file mode 100644
index 0000000..58cf9f4
--- /dev/null
+++ b/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardIntentReceiver.java
@@ -0,0 +1,43 @@
+/*
+ * 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.tradefed.utils;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+/**
+ * A BroadcastReceiver that starts a service to dismiss the keyguard.
+ *
+ * adb shell am broadcast -a com.android.tradefed.actor.DISMISS_KEYGUARD
+ */
+public class DismissKeyguardIntentReceiver extends BroadcastReceiver {
+
+    public static final String
+            DISMISS_KEYGUARD_INTENT = "com.android.tradefed.utils.DISMISS_KEYGUARD";
+    public static final String TAG = "DismissKeyguardUtil";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (DISMISS_KEYGUARD_INTENT.equals(intent.getAction())) {
+            Log.v(TAG, "Starting Service");
+            Intent pushIntent = new Intent(context, DismissKeyguardService.class);
+            context.startService(pushIntent);
+        }
+    }
+}
diff --git a/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardService.java b/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardService.java
new file mode 100644
index 0000000..852b1e5
--- /dev/null
+++ b/util-apps/DismissKeyguardUtil/src/com/android/tradefed/utils/DismissKeyguardService.java
@@ -0,0 +1,46 @@
+/*
+ * 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.tradefed.utils;
+
+import android.app.Activity;
+import android.app.KeyguardManager;
+import android.app.KeyguardManager.KeyguardLock;
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+import android.util.Log;
+
+/**
+ * A service that dismisses the keyguard.
+ */
+public class DismissKeyguardService extends Service {
+
+    @Override
+    public void onCreate() {
+        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(
+                Activity.KEYGUARD_SERVICE);
+        KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
+        lock.disableKeyguard();
+        Log.v(DismissKeyguardIntentReceiver.TAG, "Keyguard disabled");
+        this.stopSelf();
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+}