am 1347eb70: am e4279ccb: am ed2852cf: am a6ca91d9: am f1f502b5: Merge "Skip CTS tests if zen_mode or airplane setting is not set or if voice intents are not supported by the platform. This can happen on certain platforms (fugu, for example) or on devices (zen_mode ma

* commit '1347eb705f1a82fa5e7f53873fc1038f5ff984f8':
  Skip CTS tests if zen_mode or airplane setting is not set or if voice intents are not supported by the platform. This can happen on certain platforms (fugu, for example) or on devices (zen_mode may not be in Settings, for example).
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java b/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java
index 0089e69..4e5b4ce 100644
--- a/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java
@@ -23,6 +23,8 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.provider.AlarmClock;
 import android.os.Bundle;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.Log;
@@ -68,8 +70,40 @@
                 new IntentFilter(Utils.BROADCAST_INTENT + testCaseType.toString()));
     }
 
+    private boolean isIntentAupported(TestcaseType testCaseType) {
+        Intent intent;
+        switch (testCaseType) {
+          case DISMISS_ALARM:
+              intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
+              break;
+
+          case SET_ALARM:
+          case SET_ALARM_FOR_DISMISSAL:
+              intent = new Intent(AlarmClock.ACTION_SET_ALARM);
+              break;
+
+          case SNOOZE_ALARM:
+              intent = new Intent(AlarmClock.ACTION_SNOOZE_ALARM);
+              break;
+
+          default:
+              // shouldn't happen
+              return false;
+        }
+        final PackageManager manager = mContext.getPackageManager();
+        assertNotNull(manager);
+        if (manager.resolveActivity(intent, 0) == null) {
+            Log.i(TAG, "No Voice Activity found for the intent: " + intent.getAction());
+            return false;
+        }
+        return true;
+    }
+
     protected String runTest(TestcaseType testCaseType) throws Exception {
         Log.i(TAG, "Begin Testing: " + testCaseType);
+        // Make sure the corresponding intent is supported by the platform, before testing.
+        if (!isIntentAupported(testCaseType)) return Utils.COMPLETION_RESULT;
+
         if (!startTestActivity(testCaseType)) {
             fail("test activity start failed for testcase = " + testCaseType);
             return "";
diff --git a/tests/tests/voicesettings/src/android/voicesettings/cts/AirplaneModeTest.java b/tests/tests/voicesettings/src/android/voicesettings/cts/AirplaneModeTest.java
index 8abe396..4597651 100644
--- a/tests/tests/voicesettings/src/android/voicesettings/cts/AirplaneModeTest.java
+++ b/tests/tests/voicesettings/src/android/voicesettings/cts/AirplaneModeTest.java
@@ -33,9 +33,16 @@
     }
 
     public void testAll() throws Exception {
+        int mode;
+        try {
+            mode = getMode();
+            Log.i(TAG, "Before testing, AIRPLANE_MODE is set to: " + mode);
+        } catch (Settings.SettingNotFoundException e) {
+            // if the mode is not supported, don't run the test.
+            Log.i(TAG, "airplane mode is not found in Settings. Skipping AirplaneModeTest");
+            return;
+        }
         startTestActivity("AIRPLANE_MODE");
-        int mode = getMode();
-        Log.i(TAG, "Before testing, AIRPLANE_MODE is set to: " + mode);
         if (mode == AIRPLANE_MODE_IS_OFF) {
             // mode is currently OFF.
             // run a test to turn it on.
@@ -70,7 +77,7 @@
         return true;
     }
 
-    private int getMode() throws Exception {
+    private int getMode() throws Settings.SettingNotFoundException {
         return Settings.Global.getInt(mContext.getContentResolver(),
             Settings.Global.AIRPLANE_MODE_ON);
     }
diff --git a/tests/tests/voicesettings/src/android/voicesettings/cts/ZenModeTest.java b/tests/tests/voicesettings/src/android/voicesettings/cts/ZenModeTest.java
index 8c2efbe..ca86918 100644
--- a/tests/tests/voicesettings/src/android/voicesettings/cts/ZenModeTest.java
+++ b/tests/tests/voicesettings/src/android/voicesettings/cts/ZenModeTest.java
@@ -39,9 +39,16 @@
     }
 
     public void testAll() throws Exception {
+        int mode;
+        try {
+            mode = getMode();
+            Log.i(TAG, "Before testing, zen-mode is set to: " + mode);
+        } catch (Settings.SettingNotFoundException e) {
+            // if the mode is not supported, don't run the test.
+            Log.i(TAG, "zen_mode is not found in Settings. Skipping ZenModeTest");
+            return;
+        }
         startTestActivity("ZEN_MODE");
-        int mode = getMode();
-        Log.i(TAG, "Before testing, zen-mode is set to: " + mode);
         if (mode == ZEN_MODE_IS_OFF) {
             // mode is currently OFF.
             // run a test to turn it on.
@@ -85,7 +92,7 @@
         return true;
     }
 
-    private int getMode() throws Exception {
+    private int getMode() throws Settings.SettingNotFoundException {
         return Settings.Global.getInt(mContext.getContentResolver(), ZEN_MODE);
     }
 }