Merge "Added skip button for emergency call test" into pi-dev
am: de2466c0af

Change-Id: Ie26f1bdd8fe25fa70107feb4176c4ba66237b796
diff --git a/apps/CtsVerifier/res/layout-land/gnss_emergency_test.xml b/apps/CtsVerifier/res/layout-land/gnss_emergency_test.xml
new file mode 100644
index 0000000..bf3f29d
--- /dev/null
+++ b/apps/CtsVerifier/res/layout-land/gnss_emergency_test.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<com.android.cts.verifier.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <LinearLayout app:ctsv_layout_box="all"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        >
+
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            android:layout_weight="1">
+
+            <TextView android:id="@+id/text"
+                android:textSize="14sp"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
+
+            <ScrollView
+                android:id="@+id/log_scroll_view"
+                android:fillViewport="true"
+                android:layout_height="match_parent"
+                android:layout_width="0dp"
+                android:layout_weight="1">
+
+                <LinearLayout
+                    android:id="@+id/log_layout"
+                    android:orientation="vertical"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"/>
+            </ScrollView>
+
+        </LinearLayout>
+        <Button
+            android:id="@+id/next_button"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/next_button_text" />
+        <include layout="@layout/pass_fail_buttons" />
+    </LinearLayout>
+</com.android.cts.verifier.BoxInsetLayout>
\ No newline at end of file
diff --git a/apps/CtsVerifier/res/layout-port/gnss_emergency_test.xml b/apps/CtsVerifier/res/layout-port/gnss_emergency_test.xml
new file mode 100644
index 0000000..fb23a32
--- /dev/null
+++ b/apps/CtsVerifier/res/layout-port/gnss_emergency_test.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/RootLayoutPadding"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <TextView
+        android:id="@+id/text"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="14sp" />
+
+    <ScrollView
+        android:id="@+id/log_scroll_view"
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:fillViewport="true">
+
+        <LinearLayout
+            android:id="@+id/log_layout"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:orientation="vertical" />
+
+    </ScrollView>
+
+    <Button
+        android:id="@+id/next_button"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/next_button_text" />
+    <include layout="@layout/pass_fail_buttons" />
+
+</LinearLayout>
diff --git a/apps/CtsVerifier/res/layout-small/gnss_emergency_test.xml b/apps/CtsVerifier/res/layout-small/gnss_emergency_test.xml
new file mode 100644
index 0000000..7bd48f5
--- /dev/null
+++ b/apps/CtsVerifier/res/layout-small/gnss_emergency_test.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/RootLayoutPadding"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <ScrollView
+        android:id="@+id/log_scroll_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:fillViewport="true">
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/text"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textSize="14sp" />
+
+            <LinearLayout
+                android:id="@+id/log_layout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical" />
+
+            <Button
+                android:id="@+id/next_button"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/next_button_text" />
+            <include layout="@layout/pass_fail_buttons" />
+        </LinearLayout>
+
+    </ScrollView>
+</LinearLayout>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 751766c..ac97379 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -609,10 +609,13 @@
     <string name="location_emergency_call_test_info">This test verifies whether basic features
         (wifi, sms, gps) works correctly during the emergency call. Make sure the device is using
         a special white listed sim card. The wifi and GPS should be on and have internet connection.
+        Press the pass button to skip this test if outside US/Canada.
     </string>
     <string name="emergency_call_confirm_info">This test will dial 911! Please make sure to use a
         whitelisted sim card to run this test!
     </string>
+    <string name="emergency_call_skip_info">Current device doesn\'t support cellular network. Skipping the Test.
+    </string>
     <string name="emergency_call_emergency_number_hint_text">
         Emergency Number:
     </string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallBaseTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallBaseTestActivity.java
index ef88e9b..531b40b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallBaseTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallBaseTestActivity.java
@@ -26,7 +26,9 @@
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.FrameLayout;
+import android.widget.Toast;
 import com.android.cts.verifier.R;
+import com.android.cts.verifier.TestResult;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -46,7 +48,7 @@
      * @param testClass The test class to execute, it must be a subclass of {@link AndroidTestCase}.
      */
     protected EmergencyCallBaseTestActivity(Class<? extends GnssTestCase> testClass) {
-        super(testClass);
+        super(testClass, R.layout.gnss_emergency_test);
     }
 
     protected abstract long getPhoneCallDurationMs();
@@ -54,9 +56,12 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
         // override the test info
         mTextView.setText(R.string.location_emergency_call_test_info);
         EmergencyCallUtil.setDefaultDialer(this, this.getPackageName());
+        setPassFailButtonClickListeners();
+
     }
 
     @Override
@@ -69,6 +74,15 @@
 
     @Override
     public void onClick(View target) {
+        // skip current test if device doesn't support cellular
+        if (!EmergencyCallUtil.isPhoneDevice(this)) {
+            String skipInfo = getResources().getString(R.string.emergency_call_skip_info);
+            TestResult.setPassedResult(this, super.getClass().getName(), skipInfo);
+            Toast toast = Toast.makeText(getApplicationContext(), skipInfo, Toast.LENGTH_LONG);
+            toast.show();
+            this.finish();
+            return;
+        }
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         final FrameLayout frameView = new FrameLayout(this);
         builder.setView(frameView);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallUtil.java b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallUtil.java
index 12b7ac2..328498e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallUtil.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/EmergencyCallUtil.java
@@ -89,6 +89,15 @@
         new Thread(runnable).start();
     }
 
+    public static boolean isPhoneDevice(Activity activity) {
+        TelephonyManager tMgr =
+            (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
+        if(tMgr.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
+            return false;
+        }
+        return true;
+    }
+
     private static void endCall(Context context) {
         try {
             TelephonyManager telephonyManager =
@@ -116,5 +125,4 @@
             (TelephonyManager)activity.getSystemService(Context.TELEPHONY_SERVICE);
         return tMgr.getLine1Number();
     }
-
-}
\ No newline at end of file
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/GnssCtsTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/GnssCtsTestActivity.java
index 1e7e481..20a618c 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/location/base/GnssCtsTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/location/base/GnssCtsTestActivity.java
@@ -59,6 +59,18 @@
         super(testClass);
     }
 
+    /**
+     * Constructor to be used by subclasses. It allows to provide a custom layout for the test UI.
+     *
+     * @param testClass The class that contains the tests. It is dependant on test executor
+     *                  implemented by subclasses.
+     * @param layoutId The Id of the layout to use for the test UI. The layout must contain all the
+     *                 elements in the base layout {@code R.layout.gnss_test}.
+     */
+    protected GnssCtsTestActivity(Class<? extends GnssTestCase> testClass, int layoutId) {
+        super(testClass, layoutId);
+    }
+
     @Override
     protected void activitySetUp() throws InterruptedException {
         waitForUserToBegin();