1 // Copyright 2013 Google Inc. All Rights Reserved. 2 3 package com.android.cts.verifier.deskclock; 4 5 import android.content.Intent; 6 import android.content.pm.PackageManager; 7 import android.database.DataSetObserver; 8 import android.os.Bundle; 9 import android.provider.AlarmClock; 10 import android.util.Log; 11 12 import com.android.cts.verifier.ArrayTestListAdapter; 13 import com.android.cts.verifier.IntentDrivenTestActivity; 14 import com.android.cts.verifier.IntentDrivenTestActivity.ButtonInfo; 15 import com.android.cts.verifier.IntentDrivenTestActivity.IntentFactory; 16 import com.android.cts.verifier.IntentDrivenTestActivity.TestInfo; 17 import com.android.cts.verifier.PassFailButtons; 18 import com.android.cts.verifier.R; 19 import com.android.cts.verifier.TestListAdapter.TestListItem; 20 21 import java.util.ArrayList; 22 import java.util.Calendar; 23 24 /** 25 * Activity that lists all the DeskClock tests. 26 */ 27 public class DeskClockTestsActivity extends PassFailButtons.TestListActivity { 28 29 private static final String TAG = DeskClockTestsActivity.class.getSimpleName(); 30 31 private static final String SHOW_ALARMS_TEST = "SHOW_ALARMS"; 32 public static final String SET_ALARM_WITH_UI_TEST = "SET_ALARM_WITH_UI"; 33 public static final String START_ALARM_TEST = "START_ALARM"; 34 public static final String CREATE_ALARM_TEST = "CREATE_ALARM"; 35 public static final String SET_TIMER_WITH_UI_TEST = "SET_TIMER_WITH_UI"; 36 public static final String START_TIMER = "START_TIMER"; 37 public static final String START_TIMER_WITH_UI = "START_TIMER_WITH_UI"; 38 39 private static final ArrayList<Integer> DAYS = new ArrayList<Integer>(); 40 41 private static final Intent CREATE_ALARM_INTENT = new Intent(AlarmClock.ACTION_SET_ALARM) 42 .putExtra(AlarmClock.EXTRA_MESSAGE, "Create Alarm Test") 43 .putExtra(AlarmClock.EXTRA_SKIP_UI, false) 44 .putExtra(AlarmClock.EXTRA_VIBRATE, true) 45 .putExtra(AlarmClock.EXTRA_RINGTONE, AlarmClock.VALUE_RINGTONE_SILENT) 46 .putExtra(AlarmClock.EXTRA_HOUR, 1) 47 .putExtra(AlarmClock.EXTRA_MINUTES, 23) 48 .putExtra(AlarmClock.EXTRA_DAYS, DAYS); 49 50 static { 51 DAYS.add(Calendar.MONDAY); 52 DAYS.add(Calendar.WEDNESDAY); 53 } 54 55 private static final Intent SHOW__ALARMS_INTENT = new Intent(AlarmClock.ACTION_SHOW_ALARMS); 56 57 private static final Intent SET_ALARM_WITH_UI_INTENT = new Intent(AlarmClock.ACTION_SET_ALARM) 58 .putExtra(AlarmClock.EXTRA_SKIP_UI, false); 59 60 private static final Intent SET_TIMER_WITH_UI_INTENT = new Intent(AlarmClock.ACTION_SET_TIMER) 61 .putExtra(AlarmClock.EXTRA_SKIP_UI, false); 62 63 private static final Intent START_TIMER_INTENT = new Intent(AlarmClock.ACTION_SET_TIMER) 64 .putExtra(AlarmClock.EXTRA_SKIP_UI, true) 65 .putExtra(AlarmClock.EXTRA_MESSAGE, "Start Timer Test") 66 .putExtra(AlarmClock.EXTRA_LENGTH, 30); 67 68 private static final Intent START_TIMER_WITH_UI_INTENT = new Intent(AlarmClock.ACTION_SET_TIMER) 69 .putExtra(AlarmClock.EXTRA_SKIP_UI, false) 70 .putExtra(AlarmClock.EXTRA_MESSAGE, "Start Timer Test") 71 .putExtra(AlarmClock.EXTRA_LENGTH, 30); 72 73 private static final TestInfo[] ALARM_TESTS = new TestInfo[] { 74 new TestInfo( 75 SHOW_ALARMS_TEST, 76 R.string.dc_show_alarms_test, 77 R.string.dc_show_alarms_test_info, 78 new ButtonInfo( 79 R.string.dc_show_alarms_button, 80 SHOW__ALARMS_INTENT)), 81 new TestInfo( 82 SET_ALARM_WITH_UI_TEST, 83 R.string.dc_set_alarm_with_ui_test, 84 R.string.dc_set_alarm_with_ui_test_info, 85 new ButtonInfo( 86 R.string.dc_set_alarm_button, 87 SET_ALARM_WITH_UI_INTENT)), 88 new TestInfo( 89 START_ALARM_TEST, 90 R.string.dc_start_alarm_test, 91 R.string.dc_start_alarm_test_info, 92 new ButtonInfo( 93 R.string.dc_start_alarm_button, 94 DeskClockIntentFactory.class.getName()), 95 new ButtonInfo( 96 R.string.dc_set_alarm_verify_button, 97 SHOW__ALARMS_INTENT)), 98 new TestInfo( 99 CREATE_ALARM_TEST, 100 R.string.dc_full_alarm_test, 101 R.string.dc_full_alarm_test_info, 102 new ButtonInfo( 103 R.string.dc_full_alarm_button, 104 CREATE_ALARM_INTENT)), 105 }; 106 107 private static final TestInfo[] TIMER_TESTS = new TestInfo[] { 108 new TestInfo( 109 SET_TIMER_WITH_UI_TEST, 110 R.string.dc_set_timer_with_ui_test, 111 R.string.dc_set_timer_with_ui_test_info, 112 new ButtonInfo( 113 R.string.dc_set_timer_with_ui_button, 114 SET_TIMER_WITH_UI_INTENT)), 115 new TestInfo( 116 START_TIMER, 117 R.string.dc_start_timer_test, 118 R.string.dc_start_timer_test_info, 119 new ButtonInfo( 120 R.string.dc_start_timer_button, 121 START_TIMER_INTENT)), 122 new TestInfo( 123 START_TIMER_WITH_UI, 124 R.string.dc_start_timer_with_ui_test, 125 R.string.dc_start_timer_with_ui_test_info, 126 new ButtonInfo( 127 R.string.dc_start_timer_button, 128 START_TIMER_WITH_UI_INTENT)), 129 }; 130 131 @Override onCreate(Bundle savedInstanceState)132 protected void onCreate(Bundle savedInstanceState) { 133 super.onCreate(savedInstanceState); 134 setContentView(R.layout.pass_fail_list); 135 setInfoResources(R.string.deskclock_tests, R.string.deskclock_tests_info, 0); 136 setPassFailButtonClickListeners(); 137 138 getPassButton().setEnabled(false); 139 140 final ArrayTestListAdapter adapter = new ArrayTestListAdapter(this); 141 142 adapter.add(TestListItem.newCategory(this, R.string.deskclock_group_alarms)); 143 addTests(adapter, ALARM_TESTS); 144 145 adapter.add(TestListItem.newCategory(this, R.string.deskclock_group_timers)); 146 addTests(adapter, TIMER_TESTS); 147 148 adapter.registerDataSetObserver(new DataSetObserver() { 149 @Override 150 public void onChanged() { 151 updatePassButton(); 152 } 153 }); 154 155 setTestListAdapter(adapter); 156 } 157 addTests(ArrayTestListAdapter adapter, TestInfo[] tests)158 private void addTests(ArrayTestListAdapter adapter, TestInfo[] tests) { 159 for (TestInfo info : tests) { 160 161 // TODO(b/291214170): Enable START_ALARM test once Wear Alarm app fixes EXTRA_SKIP_UI. 162 // See b/291214170#comment14. 163 if (isWearDevice() && info.getTestId().equals(START_ALARM_TEST)) { 164 continue; 165 } 166 167 // TODO(b/232182401): Enable START_TIMER test once Wear Timer app fixes EXTRA_SKIP_UI. 168 // See b/232182401#comment7. 169 if (isWearDevice() && info.getTestId().equals(START_TIMER)) { 170 continue; 171 } 172 173 int title = info.getTitle(); 174 String testId = info.getTestId(); 175 Intent intent = IntentDrivenTestActivity.newIntent(this, testId, title, 176 info.getInfoText(), info.getButtons()); 177 Log.d(TAG, "Adding test with " + IntentDrivenTestActivity.toString(this, intent)); 178 adapter.add(TestListItem.newTest(this, title, testId, intent, 179 /* applicableFeatures= */ null)); 180 } 181 } 182 isWearDevice()183 private boolean isWearDevice() { 184 final PackageManager pm = getApplicationContext().getPackageManager(); 185 return pm.hasSystemFeature(PackageManager.FEATURE_WATCH); 186 } 187 188 public static class DeskClockIntentFactory implements IntentFactory { 189 @Override createIntents(String testId, int buttonText)190 public Intent[] createIntents(String testId, int buttonText) { 191 if (testId.equals(START_ALARM_TEST)) { 192 // Alarm should go off 2 minutes from now 193 final Calendar cal = Calendar.getInstance(); 194 cal.setTimeInMillis(cal.getTimeInMillis() + 120000); 195 return new Intent[] { 196 new Intent(AlarmClock.ACTION_SET_ALARM) 197 .putExtra(AlarmClock.EXTRA_MESSAGE, "Start Alarm Test") 198 .putExtra(AlarmClock.EXTRA_SKIP_UI, true) 199 .putExtra(AlarmClock.EXTRA_VIBRATE, true) 200 .putExtra(AlarmClock.EXTRA_RINGTONE, AlarmClock.VALUE_RINGTONE_SILENT) 201 .putExtra(AlarmClock.EXTRA_HOUR, cal.get(Calendar.HOUR_OF_DAY)) 202 .putExtra(AlarmClock.EXTRA_MINUTES, cal.get(Calendar.MINUTE)), 203 }; 204 } else { 205 throw new IllegalArgumentException("Unknown test: " + testId); 206 } 207 } 208 } 209 } 210