Set HAS_CONTENT field from the app after writing audio content.
In change-id I93e4b467acdefe339fa70dd751ea05f195c32e71 content voicemail content provider was modified to no more automatically set the has_content field. The app now needs to set this field itself after writing the content. bug: 5147190 Change-Id: If3c66a86803f7587677c2ec09965b89f31f6268e
This commit is contained in:
@@ -206,13 +206,10 @@ public class AddVoicemailActivity extends Activity {
|
||||
Uri newVoicemailUri = mVoicemailProviderHelper.insert(voicemail);
|
||||
logger.i("Inserted new voicemail URI: " + newVoicemailUri);
|
||||
if (inputAudioStream != null) {
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = mVoicemailProviderHelper.setVoicemailContent(
|
||||
newVoicemailUri, getContentResolver().getType(recordingUri));
|
||||
copyStreamData(inputAudioStream, outputStream);
|
||||
mVoicemailProviderHelper.setVoicemailContent(newVoicemailUri, inputAudioStream,
|
||||
getContentResolver().getType(recordingUri));
|
||||
} finally {
|
||||
CloseUtils.closeQuietly(outputStream);
|
||||
CloseUtils.closeQuietly(inputAudioStream);
|
||||
}
|
||||
}
|
||||
@@ -228,13 +225,5 @@ public class AddVoicemailActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private void copyStreamData(InputStream in, OutputStream out) throws IOException {
|
||||
// Copy 8K chunk at a time.
|
||||
byte[] data = new byte[8 * 1024];
|
||||
int numBytes;
|
||||
while ((numBytes = in.read(data)) > 0) {
|
||||
out.write(data, 0, numBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import android.provider.VoicemailContract;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -99,14 +99,25 @@ public interface VoicemailProviderHelper {
|
||||
public int update(Uri uri, Voicemail voicemail);
|
||||
|
||||
/**
|
||||
* Get the OutputStream to write the voicemail content with the given mime type.
|
||||
* Sets the voicemail content from the supplied input stream.
|
||||
* <p>
|
||||
* <b>Remember to close the OutputStream after you're done writing.</b>
|
||||
* The inputStream is owned by the caller and must be closed by it as usual after the call has
|
||||
* returned.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the file or no voicemail is found matching
|
||||
* the given Uri
|
||||
*/
|
||||
public OutputStream setVoicemailContent(Uri voicemailUri, String mimeType) throws IOException;
|
||||
public void setVoicemailContent(Uri voicemailUri, InputStream inputStream, String mimeType)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the voicemail content from the supplied byte array.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the file or no voicemail is found matching
|
||||
* the given Uri
|
||||
*/
|
||||
public void setVoicemailContent(Uri voicemailUri, byte[] inputBytes, String mimeType)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Fetch all the voicemails accessible to this voicemail content provider.
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.provider.VoicemailContract;
|
||||
import android.provider.VoicemailContract.Voicemails;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -114,16 +115,45 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream setVoicemailContent(Uri voicemailUri, String mimeType) throws IOException {
|
||||
public void setVoicemailContent(Uri voicemailUri, InputStream inputStream, String mimeType)
|
||||
throws IOException {
|
||||
setVoicemailContent(voicemailUri, null, inputStream, mimeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVoicemailContent(Uri voicemailUri, byte[] inputBytes, String mimeType)
|
||||
throws IOException {
|
||||
setVoicemailContent(voicemailUri, inputBytes, null, mimeType);
|
||||
}
|
||||
|
||||
private void setVoicemailContent(Uri voicemailUri, byte[] inputBytes, InputStream inputStream,
|
||||
String mimeType) throws IOException {
|
||||
if (inputBytes != null && inputStream != null) {
|
||||
throw new IllegalArgumentException("Both inputBytes & inputStream non-null. Don't" +
|
||||
" know which one to use.");
|
||||
}
|
||||
|
||||
logger.d(String.format("Writing new voicemail content: %s", voicemailUri));
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = mContentResolver.openOutputStream(voicemailUri);
|
||||
if (inputBytes != null) {
|
||||
outputStream.write(inputBytes);
|
||||
} else if (inputStream != null) {
|
||||
copyStreamData(inputStream, outputStream);
|
||||
}
|
||||
} finally {
|
||||
CloseUtils.closeQuietly(outputStream);
|
||||
}
|
||||
// Update mime_type & has_content after we are done with file update.
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Voicemails.MIME_TYPE, mimeType);
|
||||
values.put(Voicemails.HAS_CONTENT, true);
|
||||
int updatedCount = mContentResolver.update(voicemailUri, values, null, null);
|
||||
if (updatedCount != 1) {
|
||||
throw new IOException("Updating voicemail should have updated 1 row, was: "
|
||||
+ updatedCount);
|
||||
}
|
||||
logger.d(String.format("Writing new voicemail content: %s", voicemailUri));
|
||||
return mContentResolver.openOutputStream(voicemailUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,4 +318,13 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
}
|
||||
return contentValues;
|
||||
}
|
||||
|
||||
private void copyStreamData(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] data = new byte[8 * 1024];
|
||||
int numBytes;
|
||||
while ((numBytes = in.read(data)) > 0) {
|
||||
out.write(data, 0, numBytes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user