diff options
author | Matt Garnes <matt@cyngn.com> | 2015-07-20 15:28:17 -0700 |
---|---|---|
committer | Matt Garnes <matt@cyngn.com> | 2015-08-06 14:52:57 -0700 |
commit | 9e6ec9e8ba2b880d0d005a01090aa6ca3ca3e465 (patch) | |
tree | 5ec99d6fb0559377e09f8c7a4a2a8c0e1f413dd1 /tests | |
parent | 0cdb1d513c70a794db0e29696ef620c573aa96ea (diff) | |
download | vendor_cmsdk-9e6ec9e8ba2b880d0d005a01090aa6ca3ca3e465.zip vendor_cmsdk-9e6ec9e8ba2b880d0d005a01090aa6ca3ca3e465.tar.gz vendor_cmsdk-9e6ec9e8ba2b880d0d005a01090aa6ca3ca3e465.tar.bz2 |
Add AlarmClock support for CM DeskClock manipulation.
- In order to externalize the AlarmClock provider within DeskClock, move
the database contract, ClockContract, into the SDK so that interested parties can
reference it.
- Add CyanogenModAlarmClock to add new utilities for turning existing
alarms on/off and creating new alarms.
Change-Id: I1f11ccc3988bdef10d721e2038b2c7d69a4ae598
Diffstat (limited to 'tests')
-rw-r--r-- | tests/AndroidManifest.xml | 10 | ||||
-rw-r--r-- | tests/res/values/strings.xml | 1 | ||||
-rw-r--r-- | tests/src/org/cyanogenmod/tests/alarmclock/CMAlarmClockTest.java | 135 |
3 files changed, 146 insertions, 0 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 8aae204..e4ad867 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -8,6 +8,9 @@ <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <uses-permission android:name="cyanogenmod.permission.MODIFY_NETWORK_SETTINGS" /> <uses-permission android:name="android.permission.REBOOT" /> + <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> + <uses-permission android:name="cyanogenmod.alarmclock.permission.MANAGE_ALARMS" /> + <uses-permission android:name="cyanogenmod.alarmclock.permission.READ_ALARMS" /> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <uses-library android:name="android.test.runner" /> @@ -25,6 +28,13 @@ <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> + <activity android:name=".alarmclock.CMAlarmClockTest" + android:label="@string/alarm_tests_activity_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> <activity android:name=".profiles.ProfileTest" android:label="@string/app_name"> <intent-filter> diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml index e07e6c1..6195f2b 100644 --- a/tests/res/values/strings.xml +++ b/tests/res/values/strings.xml @@ -2,4 +2,5 @@ <resources> <string name="app_name">CM Platform Tests</string> <string name="settings_tests_activity_name">CM Platform Settings Tests</string> + <string name="alarm_tests_activity_name">CM Platform Alarm Clock Tests</string> </resources> diff --git a/tests/src/org/cyanogenmod/tests/alarmclock/CMAlarmClockTest.java b/tests/src/org/cyanogenmod/tests/alarmclock/CMAlarmClockTest.java new file mode 100644 index 0000000..83a1c1f --- /dev/null +++ b/tests/src/org/cyanogenmod/tests/alarmclock/CMAlarmClockTest.java @@ -0,0 +1,135 @@ +package org.cyanogenmod.tests.alarmclock; + +import android.content.Intent; +import android.database.Cursor; +import android.database.DatabaseUtils; +import android.net.Uri; +import android.provider.AlarmClock; +import android.util.Log; +import android.widget.Toast; +import cyanogenmod.alarmclock.ClockContract; +import cyanogenmod.alarmclock.CyanogenModAlarmClock; +import org.cyanogenmod.tests.TestActivity; + +/** + * Tests functionality added in {@link cyanogenmod.alarmclock.CyanogenModAlarmClock} + */ +public class CMAlarmClockTest extends TestActivity { + private static final String TAG = "CMAlarmClockTest"; + + private static final String[] ALARM_QUERY_COLUMNS = { + ClockContract.AlarmsColumns._ID, + ClockContract.AlarmsColumns.LABEL, + ClockContract.AlarmsColumns.VIBRATE, + ClockContract.AlarmsColumns.RINGTONE, + ClockContract.AlarmsColumns.INCREASING_VOLUME, + ClockContract.AlarmsColumns.PROFILE, + ClockContract.AlarmsColumns.ENABLED + }; + + @Override + protected String tag() { + return null; + } + + @Override + protected Test[] tests() { + return mTests; + } + + private Test[] mTests = new Test[] { + new Test("Test query alarms and dump to log") { + public void run() { + Uri clockUri = ClockContract.AlarmsColumns.CONTENT_URI; + Cursor allAlarms = getContentResolver().query(clockUri, + ALARM_QUERY_COLUMNS, null, null, null); + Log.d(TAG, "All alarms: " + DatabaseUtils.dumpCursorToString(allAlarms)); + if (allAlarms != null && !allAlarms.isClosed()) { + allAlarms.close(); + } + } + }, + new Test("Test create alarm") { + public void run() { + Intent intent = CyanogenModAlarmClock.createAlarmIntent(CMAlarmClockTest.this); + intent.putExtra(AlarmClock.EXTRA_HOUR, 13); + intent.putExtra(AlarmClock.EXTRA_MINUTES, 35); + intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Test from third party!"); + intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true); + startActivityForResult(intent, 0); + } + }, + new Test("Enable the first alarm if it exists") { + public void run() { + setAlarmEnabledAtIndex(0, true); + } + }, + new Test("Disable the first alarm if it exists") { + public void run() { + setAlarmEnabledAtIndex(0, false); + } + }, + new Test("Enable the second alarm if it exists") { + public void run() { + setAlarmEnabledAtIndex(1, true); + } + }, + new Test("Disable the second alarm if it exists") { + public void run() { + setAlarmEnabledAtIndex(1, false); + } + }, + }; + + /** + * Retrieve the id of the alarm within the Alarms table at the given index. + * @param index The index of the alarm for which to retrieve the id, beginning at zero. + * @return The ID of the alarm at the given index or -1L if + * no alarm exists at that index. + */ + private long getAlarmIdAtIndex(int index) { + Uri clockUri = ClockContract.AlarmsColumns.CONTENT_URI; + Cursor allAlarms = getContentResolver().query(clockUri, + new String[]{ClockContract.AlarmsColumns._ID}, null, null, null); + long theIdToReturn = -1L; + int current = 0; + int idColumnIndex = allAlarms.getColumnIndex(ClockContract.AlarmsColumns._ID); + allAlarms.moveToFirst(); + while(!allAlarms.isAfterLast()) { + if (current == index) { + theIdToReturn = allAlarms.getLong(idColumnIndex); + break; + } + current++; + allAlarms.moveToNext(); + } + if (allAlarms != null && !allAlarms.isClosed()) { + allAlarms.close(); + } + return theIdToReturn; + } + + /** + * Construct a new Intent that will launch a DeskClock IntentService to + * set an alarm's state to enabled or disabled. + * @param alarmId The ID of the alarm that we will toggle. + * @param enabledState The new state of the alarm, whether it will be enabled or disabled. + * @return The Intent to launch that will perform this action. + */ + private Intent getIntentToSetAlarmEnabled(long alarmId, boolean enabledState) { + Intent intent = new Intent(CyanogenModAlarmClock.ACTION_SET_ALARM_ENABLED); + intent.setPackage("com.android.deskclock"); + intent.putExtra(CyanogenModAlarmClock.EXTRA_ALARM_ID, alarmId); + intent.putExtra(CyanogenModAlarmClock.EXTRA_ENABLED, enabledState); + return intent; + } + + private void setAlarmEnabledAtIndex(int index, boolean enabled) { + long firstAlarmId = getAlarmIdAtIndex(index); + if (firstAlarmId == -1L) { + Toast.makeText(this, "Alarm not found!", Toast.LENGTH_SHORT); + } else { + startService(getIntentToSetAlarmEnabled(firstAlarmId, enabled)); + } + } +} |