Update RTT CTS tests for changes

Set/unset the RTT master switch system property before running tests
because Telecom depends on it

Test: cts
Change-Id: I0e9d61d5dd3f92a487ef8c5cc55f3d8999685f2b
Merged-In: I0e9d61d5dd3f92a487ef8c5cc55f3d8999685f2b
diff --git a/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
index e97a9ac..588aa64 100644
--- a/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
@@ -34,11 +34,23 @@
     };
     private static final int RTT_FAILURE_REASON = 2;
 
+    private boolean mInitialRttMode;
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         if (mShouldTestTelecom) {
             setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE);
+            mInitialRttMode = getRttMasterSwitch();
+            setRttMasterSwitch(false);
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (mShouldTestTelecom) {
+            setRttMasterSwitch(mInitialRttMode);
         }
     }
 
@@ -60,6 +72,7 @@
             return;
         }
 
+        setRttMasterSwitch(true);
         placeRttCall(true);
         final MockConnection connection = verifyConnectionForIncomingCall();
         final MockInCallService inCallService = mInCallCallbacks.getService();
@@ -85,6 +98,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 +191,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 +213,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);
     }
@@ -273,6 +292,7 @@
 
         }
     }
+
     private void placeRttCall(boolean incoming) {
         Bundle extras = new Bundle();
         extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, true);
@@ -284,4 +304,14 @@
             placeAndVerifyCall(outgoingCallExtras);
         }
     }
+
+    private void setRttMasterSwitch(boolean on) throws Exception {
+        TestUtils.executeShellCommand(getInstrumentation(),
+                "settings put system rtt_calling_mode " + (on ? 1 : 0));
+    }
+
+    private boolean getRttMasterSwitch() throws Exception {
+        return Integer.valueOf(TestUtils.executeShellCommand(
+                getInstrumentation(), "settings get system rtt_calling_mode")) == 1;
+    }
 }