merge in mnc-dr-release history after reset to mnc-dr-dev
diff --git a/libraries/power-helper/Android.mk b/libraries/power-helper/Android.mk
new file mode 100644
index 0000000..9ea8816
--- /dev/null
+++ b/libraries/power-helper/Android.mk
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 2014 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_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := PowerTestHelper-src
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_JAVA_LIBRARIES := android.test.runner ub-uiautomator
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/libraries/power-helper/sample/Android.mk b/libraries/power-helper/sample/Android.mk
new file mode 100644
index 0000000..174ce17
--- /dev/null
+++ b/libraries/power-helper/sample/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := DummyPowerTest
+LOCAL_MODULE_TAGS := tests
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_STATIC_JAVA_LIBRARIES := PowerTestHelper-src ub-uiautomator
+
+include $(BUILD_PACKAGE)
diff --git a/libraries/power-helper/sample/AndroidManifest.xml b/libraries/power-helper/sample/AndroidManifest.xml
new file mode 100644
index 0000000..2515fbd
--- /dev/null
+++ b/libraries/power-helper/sample/AndroidManifest.xml
@@ -0,0 +1,38 @@
+<?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. -->
+
+<!-- Declare the contents of this Android application. The namespace attribute
+    brings in the Android platform namespace, and the package supplies a unique
+    name for the application. When writing your own application, the package
+    name must be changed from "com.example.*" to come from a domain that you
+    own or have control over. -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+  package="com.android.dummy">
+
+  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+  <uses-permission android:name="android.permission.DEVICE_POWER" />
+  <uses-permission android:name="android.permission.WAKE_LOCK" />
+  <uses-permission android:name="android.permission.SET_TIME" />
+  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+  <uses-permission android:name="android.permission.BLUETOOTH" />
+  <uses-permission android:name="android.permission.VIBRATE" />
+  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+  <application android:label="Power Tests">
+    <uses-library android:name="android.test.runner" />
+  </application>
+
+  <instrumentation
+    android:name="android.test.InstrumentationTestRunner"
+    android:targetPackage="com.android.dummy"
+    android:label="UB-UIAutomator Power Tests">
+  </instrumentation>
+</manifest>
+
diff --git a/libraries/power-helper/sample/src/com/android/dummy/DummyPowerTest.java b/libraries/power-helper/sample/src/com/android/dummy/DummyPowerTest.java
new file mode 100644
index 0000000..ab4bf9b
--- /dev/null
+++ b/libraries/power-helper/sample/src/com/android/dummy/DummyPowerTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 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.dummy;
+
+import android.os.SystemClock;
+import com.android.helper.PowerTestHelper;
+
+public class DummyPowerTest extends PowerTestHelper {
+
+    public void testDummy() throws Exception {
+        writePowerLogStart(getPropertyString("TestCase"));
+
+        SystemClock.sleep(40*1000);
+
+        writePowerLogEnd(getPropertyString("TestCase"));
+    }
+}
diff --git a/libraries/power-helper/src/com/android/helper/PowerTestHelper.java b/libraries/power-helper/src/com/android/helper/PowerTestHelper.java
new file mode 100644
index 0000000..f290205
--- /dev/null
+++ b/libraries/power-helper/src/com/android/helper/PowerTestHelper.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2014 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.helper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import android.os.Bundle;
+import android.os.Environment;
+
+import android.os.SystemClock;
+import android.support.test.uiautomator.UiAutomatorTestCase;
+import android.test.InstrumentationTestRunner;
+import android.util.Log;
+
+public class PowerTestHelper extends UiAutomatorTestCase {
+    private final static String PARAM_CONFIG = "conf";
+    private final static String SD_CARD_PATH =
+        Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
+    private final static String POWER_OUTPUT = SD_CARD_PATH + "autotester.log";
+    private final static String PROPERTY_FILE_NAME = SD_CARD_PATH + "PowerTests.conf";
+    private final static long SYNC_DELAY = 10 * 1000; // 10 secs
+    private final static String TAG = "PowerTestHelper";
+
+    private Bundle mParams;
+
+    @Override
+    public Bundle getParams() {
+        if (mParams == null) {
+            mParams = ((InstrumentationTestRunner) getInstrumentation()).getArguments();
+        }
+        return mParams;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mParams = getParams();
+        assertNotNull("mParams is null", mParams);
+
+        // Wait for USB to be disconnected by the test harness
+        SystemClock.sleep(SYNC_DELAY);
+    }
+
+    /**
+     * Expects a file from the command line via conf param or default following
+     * format each on its own line. <code>
+     *    key=Value
+     *    Browser_URL1=cnn.com
+     *    Browser_URL2=google.com
+     *    Camera_ShutterDelay=1000
+     *    etc...
+     * </code>
+     * @param Bundle params
+     * @param key
+     * @return the value of the property else defaultValue
+     * @throws FileNotFoundException
+     * @throws IOException
+     */
+    protected String getPropertyString(String key)
+            throws FileNotFoundException, IOException {
+        String value = getProperty(key);
+        if (value != null && !value.isEmpty())
+            return value;
+        return null;
+    }
+
+    /**
+     * Expects a file from the command line via conf param or default following
+     * format each on its own line. <code>
+     *    key=Value
+     *    Browser_URL1=cnn.com
+     *    Browser_URL2=google.com
+     *    Camera_ShutterDelay=1000
+     *    etc...
+     * </code>
+     * @param Bundle params
+     * @param key
+     * @return the value of the property else defaultValue
+     * @throws FileNotFoundException
+     * @throws IOException
+     */
+    protected long getPropertyLong(String key)
+            throws FileNotFoundException, IOException {
+        String value = getProperty(key);
+        if (value != null && !value.trim().isEmpty())
+            return Long.valueOf(value.trim());
+        return 0;
+    }
+
+    private String getProperty(String key)
+            throws FileNotFoundException, IOException {
+        String value;
+
+        Properties prop = new Properties();
+        FileInputStream inputStream = new FileInputStream(mParams.getString(PARAM_CONFIG,
+                PROPERTY_FILE_NAME));
+        prop.load(inputStream);
+        value = prop.getProperty(key);
+        inputStream.close();
+
+        return value;
+    }
+
+    /**
+     * The power log capture when the measuremnt start and end. It will be
+     * merged with the monsoon raw power data to get the average power usage in
+     * that particular time frame.
+     * @param logType
+     * @param testCase
+     * @param delay
+     * @throws IOException
+     */
+    protected void writePowerLog(String logType, String testCase, long delay)
+            throws IOException {
+        writePowerLog(logType, testCase, System.currentTimeMillis(), delay);
+    }
+
+    /**
+     * Power log capture the time when the measurement start and end. It will be
+     * merged with the monsoon raw power data to get the average power usage in
+     * that particular time frame.
+     * @param logType
+     * @param testCase : Test case name
+     * @param time : Specific time stamp
+     * @param delay : Delay for the actual log time.
+     * @throws IOException
+     */
+    protected void writePowerLog(String logType, String testCase, long time,
+            long delay) throws IOException {
+        FileWriter outputWriter = new FileWriter(new File(POWER_OUTPUT), true);
+        outputWriter.write(String.format("%d %s %s\n", (time + delay),
+                logType, testCase));
+        outputWriter.close();
+    }
+
+    protected void writePowerLogStart(String testCase) throws IOException {
+        writePowerLog("AUTOTEST_TEST_BEGIN", testCase, 5 * 1000);
+    }
+
+    protected void writePowerLogEnd(String testCase) throws IOException {
+        writePowerLog("AUTOTEST_TEST_SUCCESS", testCase, 0);
+    }
+
+    protected void writePowerLogIdleStart(String testCase, long delay) throws IOException {
+        writePowerLog("AUTOTEST_TEST_BEGIN", testCase, delay);
+    }
+
+    protected void writePowerLogIdleEnd(String testCase, long delay) throws IOException {
+        writePowerLog("AUTOTEST_TEST_SUCCESS", testCase, delay);
+    }
+}