Fix ABVT tests

Bug : 31244625
Bug : 31244622
Bug : 31244671
Bug : 31244913

Change-Id: I5e20066c2ca0009c0865a98794a7e83d5cc394dc
diff --git a/tests/androidbvt/src/com/android/androidbvt/SysQuickSettingTests.java b/tests/androidbvt/src/com/android/androidbvt/SysQuickSettingTests.java
deleted file mode 100644
index bcdd68a..0000000
--- a/tests/androidbvt/src/com/android/androidbvt/SysQuickSettingTests.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2016 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.androidbvt;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.net.wifi.WifiManager;
-import android.os.Environment;
-import android.provider.Settings;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.Direction;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.Until;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import junit.framework.TestCase;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/*
- * Basic Quick Setting Tests
- * 1. Check Quick Setting tiles
- * 2. 
- */
-public class SysQuickSettingTests extends TestCase {
-    private Context mContext = null;
-    private AndroidBvtHelper mABvtHelper = null;
-    private ContentResolver mResolver = null;
-    private UiDevice mDevice = null;
-
-    private Map<String, List<String>> QuickSettingTiles = new HashMap<String, List<String>>();
-    {
-        List<String> tiles = Arrays.asList("Wi-Fi","Do not disturb","Battery","Flashlight","screen","Bluetooth","Airplane mode","Location");
-        QuickSettingTiles.put("Tablet", tiles);
-        tiles.add("SIM");
-        QuickSettingTiles.put("Phone", tiles);
-        List<String> tilesMr1 = Arrays.asList("Wi-Fi","SIM", "Do not disturb","Battery","Flashlight","screen","Bluetooth","Airplane mode","Nearby");
-        QuickSettingTiles.put("MR1", tilesMr1);
-    }
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        mContext = InstrumentationRegistry.getTargetContext();
-        mResolver = mContext.getContentResolver();
-        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        super.tearDown();
-    }
-
-    /**
-     * Following test will open Quick Setting shade, and verify icons in the shade
-     */
-    @MediumTest
-    public void testQuickSettings() throws Exception {
-        mDevice.openQuickSettings();
-        Thread.sleep(mABvtHelper.LONG_TIMEOUT);
-        List<String> tiles = null;
-        // Verify quick settings are displayed on the phone screen.
-        if (mABvtHelper.isTablet()){
-            tiles = QuickSettingTiles.get("Tablet");
-        }else if (mABvtHelper.isNexusExperienceDevice()){
-            tiles = QuickSettingTiles.get("MR1");
-        }else{
-            tiles = QuickSettingTiles.get("Phone");
-        }
-        for (String tile : tiles) {
-            UiObject2 quickSettingTile = mDevice.wait(
-                    Until.findObject(By.descContains(tile)),
-                    mABvtHelper.SHORT_TIMEOUT);
-            assertNotNull(String.format("%s did not load correctly", tile),
-                    quickSettingTile);
-        }
-        // Verify tapping on Settings icon in Quick settings launches Settings.
-        mDevice.wait(Until.findObject(By.descContains("Open settings.")), mABvtHelper.LONG_TIMEOUT)
-                .click();
-        UiObject2 settingHeading = mDevice.wait(Until.findObject(By.text("Settings")),
-                mABvtHelper.LONG_TIMEOUT);
-        assertNotNull("Setting menu has not loaded correctly", settingHeading);
-    }
-
-    /**
-     * Verify User can change settings from quick setting shade
-     * can check these setting values: Wifi, Do not disturb, flashlight,Orientation,Bluetooth, Airplane mode
-     */
-    @MediumTest
-    public void testQuickSettingValues() throws Exception{
-        mDevice.openQuickSettings();
-        //test Airplane mode
-        airplaneModeTest();
-        //test wifi
-        String beforeWifiValue = Settings.Global.getString(mResolver, Settings.Global.WIFI_ON);
-        
-        //test Do not disturb
-        //test FlashLight
-        //test Orientation
-        //test BlueTooth
-        //test Airplane mode
-        mDevice.pressBack();
-    }
-
-    public void airplaneModeTest() throws Exception{
-        int onSetting = Integer.parseInt(Settings.Global.getString(
-                mResolver,
-                Settings.Global.AIRPLANE_MODE_ON));
-        ChangeQuickSetting("Airplane");
-        Thread.sleep(mABvtHelper.LONG_TIMEOUT);
-        int changedSetting = Integer.parseInt(Settings.Global.getString(
-                mResolver,
-                Settings.Global.AIRPLANE_MODE_ON));
-        assertTrue("Airplane can't be changed!" , onSetting != changedSetting);
-        ChangeQuickSetting("Airplane");
-    }
-
-    public void wifiTest(){
-        
-    }
-
-    public void ChangeQuickSetting(String aSettingDesc){
-        UiObject2 aSetting = mDevice.wait(Until.findObject(By.descContains(aSettingDesc)),
-                mABvtHelper.LONG_TIMEOUT);
-        if (aSetting != null){
-            aSetting.click();
-        }
-    }
-}
diff --git a/tests/androidbvt/src/com/android/androidbvt/SysSettingTests.java b/tests/androidbvt/src/com/android/androidbvt/SysSettingTests.java
index ec4fb8b..cce964c 100644
--- a/tests/androidbvt/src/com/android/androidbvt/SysSettingTests.java
+++ b/tests/androidbvt/src/com/android/androidbvt/SysSettingTests.java
@@ -16,12 +16,11 @@
 
 package com.android.androidbvt;
 
-import android.bluetooth.BluetoothManager;
 import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.net.wifi.WifiManager;
-import android.os.Environment;
 import android.provider.Settings;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.uiautomator.By;
@@ -31,17 +30,13 @@
 import android.test.suitebuilder.annotation.LargeTest;
 import android.test.suitebuilder.annotation.MediumTest;
 import com.android.androidbvt.AndroidBvtHelper.SettingType;
-
-import junit.framework.TestCase;
-
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.regex.Pattern;
 import junit.framework.TestCase;
-
 /**
  * Contain following tests for setting tests:
  * -Verify that common settings are set to default value
@@ -165,7 +160,8 @@
     @MediumTest
     public void testNavigationToNOESettings() {
         mABvtHelper.launchApp("com.android.settings", "Settings");
-        mDevice.wait(Until.findObject(By.text("SUPPORT")), mABvtHelper.LONG_TIMEOUT).click();
+        Pattern pattern = Pattern.compile("Support", Pattern.CASE_INSENSITIVE);
+        mDevice.wait(Until.findObject(By.text(pattern)), mABvtHelper.LONG_TIMEOUT).click();
         assertTrue("", mDevice.wait(Until.hasObject(By.text("We're here to help")),
                 mABvtHelper.LONG_TIMEOUT));
         assertTrue("", mDevice.wait(Until.hasObject(By.text("Search help & send feedback")),
diff --git a/tests/androidbvt/src/com/android/androidbvt/SysUILockScreenTests.java b/tests/androidbvt/src/com/android/androidbvt/SysUILockScreenTests.java
index 2badc9a..c766498 100644
--- a/tests/androidbvt/src/com/android/androidbvt/SysUILockScreenTests.java
+++ b/tests/androidbvt/src/com/android/androidbvt/SysUILockScreenTests.java
@@ -217,7 +217,8 @@
             mCameraHelper.capturePhoto();
             Thread.sleep(mABvtHelper.LONG_TIMEOUT * 2);
             // Find Photo/Video viewer in bottom control panel and click to view photo taken
-            mDevice.wait(Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
+            mDevice.wait(
+                    Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
                     mABvtHelper.LONG_TIMEOUT).click();
             Thread.sleep(mABvtHelper.LONG_TIMEOUT);
             // Ensure image view loaded and image detail icon is present
@@ -231,7 +232,8 @@
             // Hence, Image_Detail icon should be absent
             assertFalse("Photos taken from lockscreen can't be viewed",
                     mDevice.wait(Until.hasObject(
-                            By.res(mABvtHelper.CAMERA2_PACKAGE, "filmstrip_bottom_control_details")),
+                            By.res(mABvtHelper.CAMERA2_PACKAGE,
+                                    "filmstrip_bottom_control_details")),
                             mABvtHelper.LONG_TIMEOUT));
         } finally {
             mDevice.pressHome();
@@ -257,19 +259,22 @@
             // Capture video for time equal to LONG_TIMEOUT
             mCameraHelper.captureVideo((long) mABvtHelper.LONG_TIMEOUT);
             Thread.sleep(mABvtHelper.LONG_TIMEOUT);
-            mDevice.wait(Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
+            mDevice.wait(
+                    Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
                     mABvtHelper.LONG_TIMEOUT).click();
             Thread.sleep(mABvtHelper.LONG_TIMEOUT);
             // Ensure video_play_button is present
             assertTrue("Video taken from lockscreen can't be viewed",
-                    mDevice.wait(Until.hasObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "play_button")),
+                    mDevice.wait(
+                            Until.hasObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "play_button")),
                             mABvtHelper.LONG_TIMEOUT));
             swipePhotoVideoLeft();
             // As only videos taken in lock screen are visible
             // After swiping left there shouldn't be any video
             // Hence, video_play_button should be absent
             assertFalse("",
-                    mDevice.wait(Until.hasObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "play_button")),
+                    mDevice.wait(
+                            Until.hasObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "play_button")),
                             mABvtHelper.LONG_TIMEOUT));
         } finally {
             mDevice.pressHome();
@@ -292,7 +297,8 @@
             launchCameraOnLockScreen();
             mCameraHelper.goToCameraMode();
             Thread.sleep(mABvtHelper.LONG_TIMEOUT);
-            mDevice.wait(Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
+            mDevice.wait(
+                    Until.findObject(By.res(mABvtHelper.CAMERA2_PACKAGE, "rounded_thumbnail_view")),
                     mABvtHelper.LONG_TIMEOUT).click();
             mDevice.wait(
                     Until.hasObject(By.res("com.android.systemui:id/keyguard_security_container")),
@@ -333,9 +339,11 @@
         File cameraFolder = new File(String.format("%s/Camera", path));
         File[] files = cameraFolder.listFiles();
         int count = 0;
-        for (File f : files) {
-            if (f.isFile() && f.getName().endsWith(String.format("%s", ext))) {
-                count++;
+        if (files != null) {
+            for (File f : files) {
+                if (f.isFile() && f.getName().endsWith(String.format("%s", ext))) {
+                    count++;
+                }
             }
         }
         return count;
@@ -446,4 +454,4 @@
         KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
         return km.isKeyguardSecure();
     }
-}
+}
\ No newline at end of file
diff --git a/tests/androidbvt/src/com/android/androidbvt/SysUIMultiWindowTests.java b/tests/androidbvt/src/com/android/androidbvt/SysUIMultiWindowTests.java
index 10f5b63..87b2724 100644
--- a/tests/androidbvt/src/com/android/androidbvt/SysUIMultiWindowTests.java
+++ b/tests/androidbvt/src/com/android/androidbvt/SysUIMultiWindowTests.java
@@ -34,6 +34,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import junit.framework.TestCase;
+import android.util.Log;
 
 @HermeticTest
 public class SysUIMultiWindowTests extends TestCase {
@@ -168,13 +169,13 @@
                     Until.findObjects(By.res(mABvtHelper.SYSTEMUI_PACKAGE, "title")),
                     mABvtHelper.LONG_TIMEOUT);
             for (UiObject2 recent : recentsObjects) {
-                actualAppsInRecents.add(
-                        recent.getText());
+                String appName = recent.getText();
+                Log.i(mABvtHelper.TEST_TAG, "Apps in Recents" + appName);
+                actualAppsInRecents.add(appName);
             }
-            assertTrue("Recents shouldn't have more than 2 apps", actualAppsInRecents.size() == 2);
-            actualAppsInRecents.removeAll(expectedAppsInRecents);
-            assertTrue("Actual recents apps doesn't match with expected",
-                    actualAppsInRecents.size() == 0);
+            expectedAppsInRecents.removeAll(actualAppsInRecents);
+            assertTrue("Expected recents apps doesn't match with actual",
+                    expectedAppsInRecents.size() == 0);
             // Change window mode to full screen
             mABvtHelper.changeWindowMode(taskId, mABvtHelper.FULLSCREEN);
             mDevice.waitForIdle();