Merge "* DO NOT MERGE * Fixes crashes on Watch device." into oreo-mr1-cts-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 8076fc4..2b40fb5 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
       android:versionCode="5"
-      android:versionName="8.1_r6">
+      android:versionName="8.1_r7">
 
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27"/>
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
index f51e2e8..7c807c2 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
@@ -624,17 +624,12 @@
                 return;
             }
 
-            mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
             if (mHasVibrator) {
+                mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
                 if (RINGER_MODE_VIBRATE != mAudioManager.getRingerMode()) {
                     setFailed();
                     return;
                 }
-            } else {
-                if (RINGER_MODE_SILENT != mAudioManager.getRingerMode()) {
-                    setFailed();
-                    return;
-                }
             }
             status = PASS;
         }
diff --git a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
index 37b9461..1b1e669 100644
--- a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
@@ -17,6 +17,7 @@
 package android.permission2.cts;
 
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.test.AndroidTestCase;
 
 /**
@@ -47,21 +48,7 @@
         Intent.ACTION_SHUTDOWN,
         Intent.ACTION_DEVICE_STORAGE_LOW,
         Intent.ACTION_DEVICE_STORAGE_OK,
-        Intent.ACTION_NEW_OUTGOING_CALL,
         Intent.ACTION_REBOOT,
-        "android.intent.action.SERVICE_STATE",
-        "android.intent.action.RADIO_TECHNOLOGY",
-        "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED",
-        "android.intent.action.SIG_STR",
-        "android.intent.action.ANY_DATA_STATE",
-        "android.intent.action.DATA_CONNECTION_FAILED",
-        "android.intent.action.SIM_STATE_CHANGED",
-        "android.intent.action.NETWORK_SET_TIME",
-        "android.intent.action.NETWORK_SET_TIMEZONE",
-        "com.android.internal.intent.action.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS",
-        "android.intent.action.ACTION_MDN_STATE_CHANGED",
-        "android.provider.Telephony.SPN_STRINGS_UPDATED",
-        "android.intent.action.ANY_DATA_STATE",
         "com.android.server.WifiManager.action.START_SCAN",
         "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP",
         "android.net.wifi.WIFI_STATE_CHANGED",
@@ -85,6 +72,23 @@
         "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"
     };
 
+    private static final String BROADCASTS_TELEPHONY[] = new String[] {
+        Intent.ACTION_NEW_OUTGOING_CALL,
+        "android.intent.action.SERVICE_STATE",
+        "android.intent.action.SIG_STR",
+        "android.intent.action.RADIO_TECHNOLOGY",
+        "android.intent.action.ANY_DATA_STATE",
+        "android.intent.action.ACTION_MDN_STATE_CHANGED",
+        "android.provider.Telephony.SPN_STRINGS_UPDATED",
+        "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED",
+        "android.intent.action.SIM_STATE_CHANGED",
+        "android.intent.action.DATA_CONNECTION_FAILED",
+        "android.intent.action.NETWORK_SET_TIME",
+        "android.intent.action.NETWORK_SET_TIMEZONE",
+        "com.android.internal.intent.action.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS",
+        "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED",
+    };
+
     /**
      * Verify that protected broadcast actions can't be sent.
      */
@@ -99,4 +103,19 @@
             }
         }
     }
+
+    public void testSendProtectedTelephonyBroadcasts() {
+        if (!getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
+        for (String action : BROADCASTS_TELEPHONY) {
+            try {
+                Intent intent = new Intent(action);
+                getContext().sendBroadcast(intent);
+                fail("expected security exception broadcasting telephony action: " + action);
+            } catch (SecurityException expected) {
+                assertNotNull("security exception's error message.", expected.getMessage());
+            }
+        }
+    }
 }
diff --git a/tests/tests/print/src/android/print/cts/BasePrintTest.java b/tests/tests/print/src/android/print/cts/BasePrintTest.java
old mode 100644
new mode 100755
index a352ca6..e29b17f
--- a/tests/tests/print/src/android/print/cts/BasePrintTest.java
+++ b/tests/tests/print/src/android/print/cts/BasePrintTest.java
@@ -196,13 +196,6 @@
 
         Instrumentation instrumentation = getInstrumentation();
 
-        // Prevent rotation
-        getUiDevice().freezeRotation();
-        while (!getUiDevice().isNaturalOrientation()) {
-            getUiDevice().setOrientationNatural();
-            getUiDevice().waitForIdle();
-        }
-
         // Make sure we start with a clean slate.
         Log.d(LOG_TAG, "clearPrintSpoolerData()");
         clearPrintSpoolerData();
@@ -267,6 +260,13 @@
         assumeTrue(getInstrumentation().getContext().getPackageManager().hasSystemFeature(
                 PackageManager.FEATURE_PRINTING));
 
+        // Prevent rotation
+        getUiDevice().freezeRotation();
+        while (!getUiDevice().isNaturalOrientation()) {
+            getUiDevice().setOrientationNatural();
+            getUiDevice().waitForIdle();
+        }
+
         // Initialize the latches.
         Log.d(LOG_TAG, "init counters");
         mCancelOperationCounter = new CallCounter();
@@ -298,6 +298,9 @@
 
         sIdToTest.remove(mTestId);
 
+        // Allow rotation
+        getUiDevice().unfreezeRotation();
+
         Log.d(LOG_TAG, "tearDown() done");
     }
 
@@ -320,9 +323,6 @@
         SystemUtil.runShellCommand(instrumentation, "settings put secure "
                     + Settings.Secure.DISABLED_PRINT_SERVICES + " null");
 
-        // Allow rotation
-        getUiDevice().unfreezeRotation();
-
         Log.d(LOG_TAG, "tearDownClass() done");
     }
 
diff --git a/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
index e97a9ac..992cbca 100644
--- a/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
@@ -85,6 +85,8 @@
         startRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
 
         connection.setRttTextStream((Connection.RttTextStream) startRttCounter.getArgs(0)[0]);
+        connection.setConnectionProperties(
+            connection.getConnectionProperties() | Connection.PROPERTY_IS_RTT);
         connection.sendRttInitiationSuccess();
         TestUtils.waitOnAllHandlers(getInstrumentation());
         verifyRttEnabled(call, connection);
@@ -176,6 +178,8 @@
                 connection.getInvokeCounter(MockConnection.ON_STOP_RTT);
         call.stopRtt();
         stopRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        connection.setConnectionProperties(
+            connection.getConnectionProperties() & ~Connection.PROPERTY_IS_RTT);
         TestUtils.waitOnAllHandlers(getInstrumentation());
         verifyRttDisabled(call);
     }
@@ -196,6 +200,8 @@
                 connection.getInvokeCounter(MockConnection.ON_STOP_RTT);
         call.stopRtt();
         stopRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        connection.setConnectionProperties(
+            connection.getConnectionProperties() & ~Connection.PROPERTY_IS_RTT);
         TestUtils.waitOnAllHandlers(getInstrumentation());
         verifyRttDisabled(call);
     }
diff --git a/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallService.java b/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallService.java
index 81a731f..3481672 100644
--- a/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallService.java
+++ b/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallService.java
@@ -65,6 +65,15 @@
                 return INVALID_STATE;
             }
         }
+
+        public int waitDialingState() {
+            while (true) {
+                int state = waitOnStateChanged();
+                if (state == Call.STATE_DIALING || state == INVALID_STATE) {
+                    return state;
+                }
+            }
+        }
     }
 
     private static final String LOG_TAG="SelfMgAwareICS";
diff --git a/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallServiceTest.java b/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallServiceTest.java
index aa683a2..d0e8e48 100644
--- a/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallServiceTest.java
+++ b/tests/tests/telecom3/src/android/telecom/cts/SelfManagedAwareInCallServiceTest.java
@@ -179,7 +179,7 @@
         assertNotNull(callbacks);
 
         // Call will first be dialing.
-        assertEquals(Call.STATE_DIALING, callbacks.waitOnStateChanged());
+        assertEquals(Call.STATE_DIALING, callbacks.waitDialingState());
 
         // Set active from the connection side.
         connection.setActive();
diff --git a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
index c8718b6..6cf147f 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
@@ -339,41 +339,6 @@
         assertEquals("6512223333", ttsSpans[0].getArgs().get(TtsSpan.ARG_NUMBER_PARTS));
     }
 
-    public void testCompare() {
-        assertFalse(PhoneNumberUtils.compare("", ""));
-
-        assertTrue(PhoneNumberUtils.compare("911", "911"));
-        assertFalse(PhoneNumberUtils.compare("911", "18005550911"));
-        assertTrue(PhoneNumberUtils.compare("5555", "5555"));
-        assertFalse(PhoneNumberUtils.compare("5555", "180055555555"));
-
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "+17005554141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "+1 (700).555-4141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "+1 (700).555-4141,1234"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "17005554141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "7005554141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "5554141"));
-        assertTrue(PhoneNumberUtils.compare("17005554141", "5554141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "01117005554141"));
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "0017005554141"));
-        assertTrue(PhoneNumberUtils.compare("17005554141", "0017005554141"));
-
-
-        assertTrue(PhoneNumberUtils.compare("+17005554141", "**31#+17005554141"));
-
-        assertFalse(PhoneNumberUtils.compare("+1 999 7005554141", "+1 7005554141"));
-        assertTrue(PhoneNumberUtils.compare("011 1 7005554141", "7005554141"));
-
-        assertFalse(PhoneNumberUtils.compare("011 11 7005554141", "+17005554141"));
-
-        assertFalse(PhoneNumberUtils.compare("+17005554141", "7085882300"));
-
-        assertTrue(PhoneNumberUtils.compare("+44 207 792 3490", "0 207 792 3490"));
-
-        assertFalse(PhoneNumberUtils.compare("+44 207 792 3490", "00 207 792 3490"));
-        assertFalse(PhoneNumberUtils.compare("+44 207 792 3490", "011 207 792 3490"));
-    }
-
     public void testFormatNumberToE164() {
         assertNull(PhoneNumberUtils.formatNumber("invalid#", "US"));
         assertNull(PhoneNumberUtils.formatNumberToE164("1234567", "US"));
diff --git a/tests/tests/text/src/android/text/cts/MyanmarTest.java b/tests/tests/text/src/android/text/cts/MyanmarTest.java
index 8a71adb..916b451 100644
--- a/tests/tests/text/src/android/text/cts/MyanmarTest.java
+++ b/tests/tests/text/src/android/text/cts/MyanmarTest.java
@@ -19,16 +19,20 @@
 import static org.junit.Assert.assertTrue;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
+import android.text.TextUtils;
 import android.widget.TextView;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.Locale;
+
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class MyanmarTest {
@@ -38,6 +42,21 @@
     @UiThreadTest
     @Test
     public void testCompositionSemantics() {
+        boolean isMyanmarSupported = false;
+        final String[] localeNames = Resources.getSystem().getStringArray(
+                Resources.getSystem().getIdentifier("supported_locales", "array", "android"));
+        for (String localeName : localeNames) {
+            if (TextUtils.equals("my", Locale.forLanguageTag(localeName).getLanguage())) {
+                isMyanmarSupported = true;
+                break;
+            }
+        }
+        if (!isMyanmarSupported) {
+            // Ignoring since no Myanmar font guarantee if Myanmar is not listed in supported
+            // locales.
+            return;
+        }
+
         Context context = InstrumentationRegistry.getTargetContext();
         String textA = "\u1019\u102d\u102f";
         String textB = "\u1019\u102f\u102d"; // wrong order for Unicode
diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk
index bfcb266..3950cb0 100644
--- a/tools/cts-tradefed/Android.mk
+++ b/tools/cts-tradefed/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH)
 LOCAL_SUITE_NAME := CTS
 LOCAL_SUITE_FULLNAME := "Compatibility Test Suite"
-LOCAL_SUITE_VERSION := 8.1_r6
+LOCAL_SUITE_VERSION := 8.1_r7
 LOCAL_STATIC_JAVA_LIBRARIES += cts-tradefed-harness
 
 LOCAL_MODULE := cts-tradefed