summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Trask <joshtrask@google.com>2018-04-16 13:26:39 -0400
committerJoshua Trask <joshtrask@google.com>2018-04-17 12:49:58 -0400
commitb0e684630fef899a1eb9ef113a12fe228da15f1d (patch)
treed47f7cc0696966d49a933a0e2b6f4b9a4211761b
parent9518632678e83c9f7889556f4f5a7b0b1822c281 (diff)
downloadMediaProvider-b0e684630fef899a1eb9ef113a12fe228da15f1d.tar.gz
Only set RESULT_CANCELED for RingtonePickerActivity if it's explicitly canceled.
In handset, a RESULT_OK status with a null EXTRA_RINGTONE_PICKED_URI indicates an affirmative selection of the "Silent" ringtone. We were previously returning RESULT_CANCELED if the selection was the same as the previously-selected ringtone (which would over-trigger when clients omitted the EXTRA_RINGTONE_EXISTING_URI, indicating that they don't know any existing ringtone, but not necessarily that they would default to 'silent' if the picker is canceled). After this change, we'll correctly return RESULT_OK with a null extra. In Wear, no client requires us to set RESULT_CANCELED just to indicate that the selection was unchanged or restored to default by the time the user left the activity, and since we have no explicit "cancel" button the result is just the same as if the user re-selected the same ringtone; we can simply use RESULT_OK every time. Bug: 67351809 Fixes: 67351809 Test: manual - repro'd with the RingtonePicker.apk from b/67351809 before making this change, and then observed the correct behavior after the change. Change-Id: I7601618d14af020a8b135a36838fcea0f087ebb9
-rw-r--r--src/com/android/providers/media/RingtonePickerActivity.java42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/com/android/providers/media/RingtonePickerActivity.java b/src/com/android/providers/media/RingtonePickerActivity.java
index 7d91b6bcc..fffd83042 100644
--- a/src/com/android/providers/media/RingtonePickerActivity.java
+++ b/src/com/android/providers/media/RingtonePickerActivity.java
@@ -168,7 +168,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
// In the buttonless (watch-only) version, preemptively set our result since we won't
// have another chance to do so before the activity closes.
if (!mShowOkCancelButtons) {
- setResultFromSelection();
+ setSuccessResultWithRingtone(getCurrentlySelectedRingtoneUri());
}
// Play clip
@@ -372,7 +372,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
// In the buttonless (watch-only) version, preemptively set our result since we won't
// have another chance to do so before the activity closes.
if (!mShowOkCancelButtons) {
- setResultFromSelection();
+ setSuccessResultWithRingtone(getCurrentlySelectedRingtoneUri());
}
// If external storage is available, add a button to install sounds from storage.
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
@@ -481,7 +481,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
mRingtoneManager.stopPreviousRingtone();
if (positiveResult) {
- setResultFromSelection();
+ setSuccessResultWithRingtone(getCurrentlySelectedRingtoneUri());
} else {
setResult(RESULT_CANCELED);
}
@@ -498,7 +498,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
// In the buttonless (watch-only) version, preemptively set our result since we won't
// have another chance to do so before the activity closes.
if (!mShowOkCancelButtons) {
- setResultFromSelection();
+ setSuccessResultWithRingtone(getCurrentlySelectedRingtoneUri());
}
}
@@ -566,27 +566,21 @@ public final class RingtonePickerActivity extends AlertActivity implements
}
}
- private void setResultFromSelection() {
- // Obtain the currently selected ringtone
- Uri uri = null;
- if (getCheckedItem() == mDefaultRingtonePos) {
- // Set it to the default Uri that they originally gave us
- uri = mUriForDefaultItem;
- } else if (getCheckedItem() == mSilentPos) {
- // A null Uri is for the 'Silent' item
- uri = null;
- } else {
- uri = mRingtoneManager.getRingtoneUri(getRingtoneManagerPosition(getCheckedItem()));
- }
+ private void setSuccessResultWithRingtone(Uri ringtoneUri) {
+ setResult(RESULT_OK,
+ new Intent().putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, ringtoneUri));
+ }
- // Return new URI if another ringtone was selected, as there's no ok/cancel button
- if (Objects.equals(uri, mExistingUri)) {
- setResult(RESULT_CANCELED);
- } else {
- Intent resultIntent = new Intent();
- resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, uri);
- setResult(RESULT_OK, resultIntent);
- }
+ private Uri getCurrentlySelectedRingtoneUri() {
+ if (getCheckedItem() == mDefaultRingtonePos) {
+ // Use the default Uri that they originally gave us.
+ return mUriForDefaultItem;
+ } else if (getCheckedItem() == mSilentPos) {
+ // Use a null Uri for the 'Silent' item.
+ return null;
+ } else {
+ return mRingtoneManager.getRingtoneUri(getRingtoneManagerPosition(getCheckedItem()));
+ }
}
private void saveAnyPlayingRingtone() {