Changed VoicemailProvider demo app to use new VoicemailContract api.
- Use new VoicemailContract instead of VoicemailProvider for API. VoicemailContract will soon be submitted to framework/base. The local copy will then be deleted. - Got rid of some unused util/core classes. Change-Id: Ic7ac76777023a8b94a5ddf2f90caf0bf48d1f60c
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1" android:versionName="1.0" package="com.example.android.voicemail">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" />
|
||||
<uses-sdk android:targetSdkVersion="9" />
|
||||
<uses-sdk android:minSdkVersion="13"
|
||||
android:targetSdkVersion="13" />
|
||||
|
||||
<uses-permission android:name="com.android.providers.voicemail.permission.READ_WRITE_OWN_VOICEMAIL" />
|
||||
<uses-permission android:name="com.android.voicemail.permission.READ_WRITE_OWN_VOICEMAIL" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.providers.voicemail.api;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* Defines the constants needed to access and interact with the voicemail content provider.
|
||||
*/
|
||||
public class VoicemailProvider {
|
||||
/** The authority used by the voicemail provider. */
|
||||
public static final String AUTHORITY =
|
||||
"com.android.providers.voicemail";
|
||||
|
||||
/** The main URI exposed by the service. */
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail");
|
||||
/** The URI to fetch an individual voicemail. */
|
||||
public static final Uri CONTENT_URI_ID_QUERY =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail/");
|
||||
/** The URI to fetch all voicemails from a given provider. */
|
||||
public static final Uri CONTENT_URI_PROVIDER_QUERY =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail/provider/");
|
||||
/** The URI to fetch an individual voicemail from a given provider. */
|
||||
public static final Uri CONTENT_URI_PROVIDER_ID_QUERY =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail/provider/");
|
||||
|
||||
/** Broadcast intent when a new voicemail record is inserted. */
|
||||
public static final String ACTION_NEW_VOICEMAIL = "android.intent.action.NEW_VOICEMAIL";
|
||||
/**
|
||||
* Extra included in {@value Intent#ACTION_PROVIDER_CHANGED} and {@value #ACTION_NEW_VOICEMAIL}
|
||||
* broadcast intents to indicate the package that caused the change in content provider.
|
||||
* <p>
|
||||
* Receivers of the broadcast can use this field to determine if this is a self change.
|
||||
*/
|
||||
public static final String EXTRA_CHANGED_BY =
|
||||
"com.android.providers.voicemail.changed_by";
|
||||
|
||||
/** The different tables defined by the content provider. */
|
||||
public static final class Tables {
|
||||
/** The table containing voicemail information. */
|
||||
public static final class Voicemails {
|
||||
public static final String NAME = "voicemails";
|
||||
|
||||
/** The mime type for a collection of voicemails. */
|
||||
public static final String DIR_TYPE =
|
||||
"vnd.android.cursor.dir/voicemails";
|
||||
|
||||
/** The different columns contained within the voicemail table. */
|
||||
public static final class Columns {
|
||||
public static final String _ID = "_id";
|
||||
public static final String _DATA = "_data";
|
||||
public static final String _DATA_FILE_EXISTS = "_data_file_exists";
|
||||
public static final String NUMBER = "number";
|
||||
public static final String DATE = "date";
|
||||
public static final String DURATION = "duration";
|
||||
public static final String PROVIDER = "provider";
|
||||
public static final String PROVIDER_DATA = "provider_data";
|
||||
public static final String DATA_MIME_TYPE = "data_mime_type";
|
||||
public static final String READ_STATUS = "read_status";
|
||||
/**
|
||||
* Current mailbox state of the message.
|
||||
* <p>
|
||||
* Legal values: 0(Inbox)/1(Deleted)/2(Undeleted).
|
||||
*/
|
||||
public static final String STATE = "state";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.example.android.provider;
|
||||
|
||||
// This is a COPY of the voicemail provider contract file checked in at
|
||||
// framework/base/core/java/android/provider. The API is currently hidden so
|
||||
// it is not available through the SDK and hence is not available to the sample
|
||||
// code.
|
||||
// TODO: get rid of this copy once the voicemail provider API is opened ups.
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.CallLog.Calls;
|
||||
|
||||
/**
|
||||
* The contract between the voicemail provider and applications. Contains
|
||||
* definitions for the supported URIs and columns.
|
||||
*
|
||||
* <P>Voicemails are inserted by what is called as a "voicemail source"
|
||||
* application, which is responsible for syncing voicemail data between a remote
|
||||
* server and the local voicemail content provider. "voicemail source"
|
||||
* application should use the source specific {@link #CONTENT_URI_SOURCE} URI
|
||||
* to insert and retrieve voicemails.
|
||||
*
|
||||
* <P>In addition to the {@link ContentObserver} notifications the voicemail
|
||||
* provider also generates broadcast intents to notify change for applications
|
||||
* that are not active and therefore cannot listen to ContentObserver
|
||||
* notifications. Broadcast intents with following actions are generated:
|
||||
* <ul>
|
||||
* <li> {@link #ACTION_NEW_VOICEMAIL} is generated for each new voicemail
|
||||
* inserted.
|
||||
* </li>
|
||||
* <li> {@link Intent#ACTION_PROVIDER_CHANGED} is generated for any change
|
||||
* made into the database, including new voicemail.
|
||||
* </li>
|
||||
* </ul>
|
||||
* @hide
|
||||
*/
|
||||
// TODO: unhide when the API is approved by android-api-council
|
||||
public class VoicemailContract {
|
||||
/** Not instantiable. */
|
||||
private VoicemailContract() {
|
||||
}
|
||||
|
||||
/** The authority used by the voicemail provider. */
|
||||
public static final String AUTHORITY = "com.android.voicemail";
|
||||
|
||||
/** URI to insert/retrieve all voicemails. */
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail");
|
||||
/** URI to insert/retrieve voicemails by a given voicemail source. */
|
||||
public static final Uri CONTENT_URI_SOURCE =
|
||||
Uri.parse("content://" + AUTHORITY + "/voicemail/source/");
|
||||
|
||||
// TODO: Move ACTION_NEW_VOICEMAIL to the Intent class.
|
||||
/** Broadcast intent when a new voicemail record is inserted. */
|
||||
public static final String ACTION_NEW_VOICEMAIL = "android.intent.action.NEW_VOICEMAIL";
|
||||
/**
|
||||
* Extra included in {@value Intent#ACTION_PROVIDER_CHANGED} and
|
||||
* {@value #ACTION_NEW_VOICEMAIL} broadcast intents to indicate the package
|
||||
* that caused the change in content provider.
|
||||
* <p>Receivers of the broadcast can use this field to determine if this is
|
||||
* a self change.
|
||||
*/
|
||||
public static final String EXTRA_CHANGED_BY = "com.android.voicemail.extra.CHANGED_BY";
|
||||
|
||||
/** The mime type for a collection of voicemails. */
|
||||
public static final String DIR_TYPE =
|
||||
"vnd.android.cursor.dir/voicemails";
|
||||
|
||||
public static final class Voicemails implements BaseColumns {
|
||||
/** Not instantiable. */
|
||||
private Voicemails() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Phone number of the voicemail sender.
|
||||
* <P>Type: TEXT</P>
|
||||
*/
|
||||
public static final String NUMBER = Calls.NUMBER;
|
||||
/**
|
||||
* The date the voicemail was sent, in milliseconds since the epoch
|
||||
* <P>Type: INTEGER (long)</P>
|
||||
*/
|
||||
public static final String DATE = Calls.DATE;
|
||||
/**
|
||||
* The duration of the voicemail in seconds.
|
||||
* <P>Type: INTEGER (long)</P>
|
||||
*/
|
||||
public static final String DURATION = Calls.DURATION;
|
||||
/**
|
||||
* Whether this is a new voicemail (i.e. has not been heard).
|
||||
* <P>Type: INTEGER (boolean)</P>
|
||||
*/
|
||||
public static final String NEW = Calls.NEW;
|
||||
/**
|
||||
* The mail box state of the voicemail.
|
||||
* <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
|
||||
* {@link #STATE_UNDELETED}.
|
||||
* <P>Type: INTEGER</P>
|
||||
*/
|
||||
public static final String STATE = "state";
|
||||
/** Value of {@link #STATE} when the voicemail is in inbox. */
|
||||
public static int STATE_INBOX = 0;
|
||||
/** Value of {@link #STATE} when the voicemail has been marked as deleted. */
|
||||
public static int STATE_DELETED = 1;
|
||||
/** Value of {@link #STATE} when the voicemail has marked as undeleted. */
|
||||
public static int STATE_UNDELETED = 2;
|
||||
/**
|
||||
* Package name of the source application that inserted the voicemail.
|
||||
* <P>Type: TEXT</P>
|
||||
*/
|
||||
public static final String SOURCE_PACKAGE = "source_package";
|
||||
/**
|
||||
* Application-specific data available to the source application that
|
||||
* inserted the voicemail. This is typically used to store the source
|
||||
* specific message id to identify this voicemail on the remote
|
||||
* voicemail server.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P> Note that this is NOT the voicemail media content data.
|
||||
*/
|
||||
public static final String SOURCE_DATA = "source_data";
|
||||
/**
|
||||
* Whether the media content for this voicemail is available for
|
||||
* consumption.
|
||||
* <P>Type: INTEGER (boolean)</P>
|
||||
*/
|
||||
public static final String HAS_CONTENT = "has_content";
|
||||
/**
|
||||
* MIME type of the media content for the voicemail.
|
||||
* <P>Type: TEXT</P>
|
||||
*/
|
||||
public static final String MIME_TYPE = "mime_type";
|
||||
/**
|
||||
* Path to the media content file. Internal only field.
|
||||
* @hide
|
||||
*/
|
||||
public static final String _DATA = "_data";
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,8 @@ public class AddVoicemailActivity extends Activity {
|
||||
long duration = durationStr.length() != 0 ? Long.parseLong(durationStr) : 0;
|
||||
return VoicemailImpl.createForInsertion(time, sender)
|
||||
.setDuration(duration)
|
||||
.setSource(sourcePackageName)
|
||||
.setSourcePackage(sourcePackageName)
|
||||
.setMailbox(Voicemail.Mailbox.INBOX)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import com.example.android.provider.VoicemailContract;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
@@ -41,11 +43,11 @@ public interface Voicemail {
|
||||
*/
|
||||
public enum Mailbox {
|
||||
/** After being fetched from the server, a message usually starts in the inbox. */
|
||||
INBOX(0),
|
||||
INBOX(VoicemailContract.Voicemails.STATE_INBOX),
|
||||
/** Indicates that a message has been deleted. */
|
||||
DELETED(1),
|
||||
DELETED(VoicemailContract.Voicemails.STATE_DELETED),
|
||||
/** Restored from having been deleted, distinct from being in the inbox. */
|
||||
UNDELETED(2);
|
||||
UNDELETED(VoicemailContract.Voicemails.STATE_UNDELETED);
|
||||
|
||||
private final int mValue;
|
||||
|
||||
@@ -89,24 +91,21 @@ public interface Voicemail {
|
||||
* Returns the package name of the source that added this voicemail, or null if this field is
|
||||
* not set.
|
||||
*/
|
||||
public String getSource();
|
||||
public String getSourcePackage();
|
||||
|
||||
public boolean hasSource();
|
||||
public boolean hasSourcePackage();
|
||||
|
||||
/**
|
||||
* Returns the provider-specific data type stored with the voicemail, or null if this field is
|
||||
* not set.
|
||||
* Returns the application-specific data type stored with the voicemail, or null if this field
|
||||
* is not set.
|
||||
* <p>
|
||||
* Provider data is typically used as an identifier to uniquely identify the voicemail against
|
||||
* Source data is typically used as an identifier to uniquely identify the voicemail against
|
||||
* the voicemail server. This is likely to be something like the IMAP UID, or some other
|
||||
* server-generated identifying string.
|
||||
*/
|
||||
// TODO:4: we should rename the provider data field to be called provider message id, which is
|
||||
// more explicit. I think we should also rename the get id method to get content id or something
|
||||
// like that.
|
||||
public String getProviderData();
|
||||
public String getSourceData();
|
||||
|
||||
public boolean hasProviderData();
|
||||
public boolean hasSourceData();
|
||||
|
||||
/**
|
||||
* Gets the Uri that can be used to refer to this voicemail, and to make it play.
|
||||
|
||||
@@ -16,38 +16,31 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.DATE;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.DURATION;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.NUMBER;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.PROVIDER;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.PROVIDER_DATA;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.READ_STATUS;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.STATE;
|
||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.concatenateClausesWithAnd;
|
||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.concatenateClausesWithOr;
|
||||
import static com.example.android.voicemail.common.utils.DbQueryUtils.getEqualityClause;
|
||||
|
||||
import com.example.android.voicemail.common.core.Voicemail.Mailbox;
|
||||
import com.example.android.voicemail.common.utils.DbQueryUtils;
|
||||
import com.example.android.provider.VoicemailContract.Voicemails;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.providers.voicemail.api.VoicemailProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Factory class to create {@link VoicemailFilter} objects for various filtering needs.
|
||||
* <p>
|
||||
* Factory methods like {@link #createWithMailbox(Mailbox)}, {@link #createWithReadStatus(boolean)} and
|
||||
* {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that matches the
|
||||
* value of the specific field.
|
||||
* Factory methods like {@link #createWithMailbox(Mailbox)}, {@link #createWithReadStatus(boolean)}
|
||||
* and {@link #createWithMatchingFields(Voicemail)} can be used to create a voicemail filter that
|
||||
* matches the value of the specific field.
|
||||
* <p>
|
||||
* It it possible to combine multiple filters with OR or AND operation using the methods
|
||||
* {@link #createWithOrOf(VoicemailFilter...)} and {@link #createWithAndOf(VoicemailFilter...)} respectively.
|
||||
* It is possible to combine multiple filters with OR or AND operation using the methods
|
||||
* {@link #createWithOrOf(VoicemailFilter...)} and {@link #createWithAndOf(VoicemailFilter...)}
|
||||
* respectively.
|
||||
* <p>
|
||||
* {@link #createWithWhereClause(String)} can be used to create an arbitrary filter for a specific where
|
||||
* clause. Using this method requires the knowledge of the name of columns used in voicemail
|
||||
* {@link #createWithWhereClause(String)} can be used to create an arbitrary filter for a specific
|
||||
* where clause. Using this method requires the knowledge of the name of columns used in voicemail
|
||||
* content provider database and is therefore less recommended.
|
||||
*/
|
||||
public class VoicemailFilterFactory {
|
||||
@@ -60,8 +53,8 @@ public class VoicemailFilterFactory {
|
||||
|
||||
/**
|
||||
* Creates a voicemail filter with the specified where clause. Use this method only if you know
|
||||
* and want to directly use the column names of the content provider. For most of the usages one
|
||||
* the other factory methods should be good enough.
|
||||
* and want to directly use the column names of the content provider. For most of the usages
|
||||
* one of the other factory methods should be good enough.
|
||||
*/
|
||||
public static VoicemailFilter createWithWhereClause(final String whereClause) {
|
||||
return new VoicemailFilter() {
|
||||
@@ -81,17 +74,20 @@ public class VoicemailFilterFactory {
|
||||
if (fieldMatch == null) {
|
||||
throw new IllegalArgumentException("Cannot create filter null fieldMatch");
|
||||
}
|
||||
return VoicemailFilterFactory.createWithWhereClause(getWhereClauseForMatchingFields(fieldMatch));
|
||||
return VoicemailFilterFactory.createWithWhereClause(
|
||||
getWhereClauseForMatchingFields(fieldMatch));
|
||||
}
|
||||
|
||||
/** Creates a voicemail filter with the specified mailbox state. */
|
||||
public static VoicemailFilter createWithMailbox(Mailbox mailbox) {
|
||||
return createWithMatchingFields(VoicemailImpl.createEmptyBuilder().setMailbox(mailbox).build());
|
||||
return createWithMatchingFields(
|
||||
VoicemailImpl.createEmptyBuilder().setMailbox(mailbox).build());
|
||||
}
|
||||
|
||||
/** Creates a voicemail filter with the specified read status. */
|
||||
public static VoicemailFilter createWithReadStatus(boolean isRead) {
|
||||
return createWithMatchingFields(VoicemailImpl.createEmptyBuilder().setIsRead(isRead).build());
|
||||
return createWithMatchingFields(
|
||||
VoicemailImpl.createEmptyBuilder().setIsRead(isRead).build());
|
||||
}
|
||||
|
||||
/** Combine multiple filters with OR clause. */
|
||||
@@ -115,26 +111,29 @@ public class VoicemailFilterFactory {
|
||||
private static String getWhereClauseForMatchingFields(Voicemail fieldMatch) {
|
||||
List<String> clauses = new ArrayList<String>();
|
||||
if (fieldMatch.hasRead()) {
|
||||
clauses.add(getEqualityClause(READ_STATUS, fieldMatch.isRead() ? "1" : "0"));
|
||||
clauses.add(getEqualityClause(Voicemails.NEW, fieldMatch.isRead() ? "1" : "0"));
|
||||
}
|
||||
if (fieldMatch.hasMailbox()) {
|
||||
clauses.add(getEqualityClause(STATE,
|
||||
clauses.add(getEqualityClause(Voicemails.STATE,
|
||||
Integer.toString(fieldMatch.getMailbox().getValue())));
|
||||
}
|
||||
if (fieldMatch.hasNumber()) {
|
||||
clauses.add(getEqualityClause(NUMBER, fieldMatch.getNumber()));
|
||||
clauses.add(getEqualityClause(Voicemails.NUMBER, fieldMatch.getNumber()));
|
||||
}
|
||||
if (fieldMatch.hasSource()) {
|
||||
clauses.add(getEqualityClause(PROVIDER, fieldMatch.getSource()));
|
||||
if (fieldMatch.hasSourcePackage()) {
|
||||
clauses.add(getEqualityClause(Voicemails.SOURCE_PACKAGE,
|
||||
fieldMatch.getSourcePackage()));
|
||||
}
|
||||
if (fieldMatch.hasProviderData()) {
|
||||
clauses.add(getEqualityClause(PROVIDER_DATA, fieldMatch.getProviderData()));
|
||||
if (fieldMatch.hasSourceData()) {
|
||||
clauses.add(getEqualityClause(Voicemails.SOURCE_DATA, fieldMatch.getSourceData()));
|
||||
}
|
||||
if (fieldMatch.hasDuration()) {
|
||||
clauses.add(getEqualityClause(DURATION, Long.toString(fieldMatch.getDuration())));
|
||||
clauses.add(getEqualityClause(Voicemails.DURATION,
|
||||
Long.toString(fieldMatch.getDuration())));
|
||||
}
|
||||
if (fieldMatch.hasTimestampMillis()) {
|
||||
clauses.add(getEqualityClause(DATE, Long.toString(fieldMatch.getTimestampMillis())));
|
||||
clauses.add(getEqualityClause(Voicemails.DATE,
|
||||
Long.toString(fieldMatch.getTimestampMillis())));
|
||||
}
|
||||
// Empty filter.
|
||||
if (clauses.size() == 0) {
|
||||
@@ -142,9 +141,4 @@ public class VoicemailFilterFactory {
|
||||
}
|
||||
return concatenateClausesWithAnd(clauses.toArray(new String[0]));
|
||||
}
|
||||
|
||||
private static String getEqualityClause(String field, String value) {
|
||||
return DbQueryUtils.getEqualityClause(VoicemailProvider.Tables.Voicemails.NAME, field,
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,14 +89,16 @@ public final class VoicemailImpl implements Voicemail {
|
||||
* Builder pattern for creating a {@link VoicemailImpl}.
|
||||
* <p>
|
||||
* All fields are optional, and can be set with the various {@code setXXX} methods.
|
||||
* <p>
|
||||
* This class is <b>not thread safe</b>
|
||||
*/
|
||||
public static class Builder {
|
||||
private Long mBuilderTimestamp;
|
||||
private String mBuilderNumber;
|
||||
private Long mBuilderId;
|
||||
private Long mBuilderDuration;
|
||||
private String mBuilderSource;
|
||||
private String mBuilderProviderData;
|
||||
private String mBuilderSourcePackage;
|
||||
private String mBuilderSourceData;
|
||||
private Uri mBuilderUri;
|
||||
private Voicemail.Mailbox mBuilderMailbox;
|
||||
private Boolean mBuilderIsRead;
|
||||
@@ -126,13 +128,13 @@ public final class VoicemailImpl implements Voicemail {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSource(String source) {
|
||||
mBuilderSource = source;
|
||||
public Builder setSourcePackage(String sourcePackage) {
|
||||
mBuilderSourcePackage = sourcePackage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setProviderData(String providerData) {
|
||||
mBuilderProviderData = providerData;
|
||||
public Builder setSourceData(String sourceData) {
|
||||
mBuilderSourceData = sourceData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -159,7 +161,7 @@ public final class VoicemailImpl implements Voicemail {
|
||||
public VoicemailImpl build() {
|
||||
return new VoicemailImpl(mBuilderTimestamp, mBuilderNumber, mBuilderId,
|
||||
mBuilderDuration,
|
||||
mBuilderSource, mBuilderProviderData, mBuilderUri, mBuilderMailbox,
|
||||
mBuilderSourcePackage, mBuilderSourceData, mBuilderUri, mBuilderMailbox,
|
||||
mBuilderIsRead,
|
||||
mBuilderHasContent);
|
||||
}
|
||||
@@ -206,22 +208,22 @@ public final class VoicemailImpl implements Voicemail {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
public String getSourcePackage() {
|
||||
return mSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSource() {
|
||||
public boolean hasSourcePackage() {
|
||||
return mSource != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderData() {
|
||||
public String getSourceData() {
|
||||
return mProviderData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProviderData() {
|
||||
public boolean hasSourceData() {
|
||||
return mProviderData != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Stores and retrieves relevant bits of voicemails in an Intent.
|
||||
*/
|
||||
public class VoicemailIntentUtils {
|
||||
/** The String used when storing provider data in intents. */
|
||||
public static final String PROVIDER_DATA_KEY = VoicemailImpl.class.getName() + ".PROVIDER_DATA";
|
||||
|
||||
// Private constructor, utility class.
|
||||
private VoicemailIntentUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the {@link Voicemail#getProviderData()} value into an intent.
|
||||
*
|
||||
* @see #extractIdentifierFromIntent(Intent)
|
||||
*/
|
||||
public static void storeIdentifierInIntent(Intent intent, Voicemail message) {
|
||||
intent.putExtra(PROVIDER_DATA_KEY, message.getProviderData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the {@link Voicemail#getProviderData()} from an intent.
|
||||
* <p>
|
||||
* Returns null if the Intent contains no such identifier, or has no extras.
|
||||
*
|
||||
* @see #storeIdentifierInIntent(Intent, Voicemail)
|
||||
*/
|
||||
public static String extractIdentifierFromIntent(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
return (extras == null ? null : extras.getString(PROVIDER_DATA_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the extras stored by {@link #storeIdentifierInIntent(Intent, Voicemail)} between two
|
||||
* intents.
|
||||
*/
|
||||
public static void copyExtrasBetween(Intent from, Intent to) {
|
||||
Bundle extras = from.getExtras();
|
||||
if (extras.containsKey(PROVIDER_DATA_KEY)) {
|
||||
to.putExtra(PROVIDER_DATA_KEY, extras.getString(PROVIDER_DATA_KEY));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
/**
|
||||
* The payload for a voicemail, usually audio data.
|
||||
*/
|
||||
public interface VoicemailPayload {
|
||||
public String getMimeType();
|
||||
|
||||
public byte[] getBytes();
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
/**
|
||||
* Concrete implementation of {@link VoicemailPayload} interface.
|
||||
*/
|
||||
public class VoicemailPayloadImpl implements VoicemailPayload {
|
||||
private final String mMimeType;
|
||||
private final byte[] mBytes;
|
||||
|
||||
public VoicemailPayloadImpl(String mimeType, byte[] bytes) {
|
||||
mMimeType = mimeType;
|
||||
mBytes = bytes.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
return mBytes.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMimeType() {
|
||||
return mMimeType;
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.example.android.provider.VoicemailContract;
|
||||
|
||||
import com.android.providers.voicemail.api.VoicemailProvider;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -74,7 +74,7 @@ public interface VoicemailProviderHelper {
|
||||
* It is expected that there be one such voicemail. Returns null if no such voicemail exists,
|
||||
* and returns one chosen arbitrarily if more than one exists.
|
||||
*/
|
||||
public Voicemail findVoicemailByProviderData(String providerData);
|
||||
public Voicemail findVoicemailBySourceData(String providerData);
|
||||
|
||||
/**
|
||||
* Returns the {@link Voicemail} corresponding to a given Uri. The uri must correspond to a
|
||||
@@ -121,7 +121,7 @@ public interface VoicemailProviderHelper {
|
||||
*
|
||||
* @param filter The filter to apply while retrieving voicemails.
|
||||
* @param sortColumn The column to sort by. Must be one of the values defined in
|
||||
* {@link VoicemailProvider.Tables.Voicemails.Columns}.
|
||||
* {@link VoicemailContract.Voicemails}.
|
||||
* @param sortOrder Order to sort by
|
||||
* @return the list of voicemails, sorted by the requested DB column in specified sort order.
|
||||
*/
|
||||
|
||||
@@ -16,18 +16,8 @@
|
||||
|
||||
package com.example.android.voicemail.common.core;
|
||||
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.CONTENT_URI_PROVIDER_ID_QUERY;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.DATA_MIME_TYPE;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.DATE;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.DURATION;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.NUMBER;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.PROVIDER;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.PROVIDER_DATA;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.READ_STATUS;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns.STATE;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns._DATA_FILE_EXISTS;
|
||||
import static com.android.providers.voicemail.api.VoicemailProvider.Tables.Voicemails.Columns._ID;
|
||||
|
||||
import com.example.android.provider.VoicemailContract;
|
||||
import com.example.android.provider.VoicemailContract.Voicemails;
|
||||
import com.example.android.voicemail.common.logging.Logger;
|
||||
import com.example.android.voicemail.common.utils.CloseUtils;
|
||||
import com.example.android.voicemail.common.utils.DbQueryUtils;
|
||||
@@ -39,8 +29,6 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.providers.voicemail.api.VoicemailProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -54,8 +42,15 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
|
||||
/** Full projection on the voicemail table, giving us all the columns. */
|
||||
private static final String[] FULL_PROJECTION = new String[] {
|
||||
_ID, _DATA_FILE_EXISTS, NUMBER, DURATION, DATE, PROVIDER, PROVIDER_DATA, READ_STATUS,
|
||||
STATE
|
||||
Voicemails._ID,
|
||||
Voicemails.HAS_CONTENT,
|
||||
Voicemails.NUMBER,
|
||||
Voicemails.DURATION,
|
||||
Voicemails.DATE,
|
||||
Voicemails.SOURCE_PACKAGE,
|
||||
Voicemails.SOURCE_DATA,
|
||||
Voicemails.NEW,
|
||||
Voicemails.STATE
|
||||
};
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
@@ -81,7 +76,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
* <code>com.android.providers.voicemail.permission.READ_WRITE_OWN_VOICEMAIL</code>.
|
||||
*/
|
||||
public static VoicemailProviderHelper createFullVoicemailProvider(Context context) {
|
||||
return new VoicemailProviderHelpers(VoicemailProvider.CONTENT_URI,
|
||||
return new VoicemailProviderHelpers(VoicemailContract.CONTENT_URI,
|
||||
context.getContentResolver());
|
||||
}
|
||||
|
||||
@@ -93,7 +88,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
* <code>com.android.providers.voicemail.permission.READ_WRITE_OWN_VOICEMAIL</code>.
|
||||
*/
|
||||
public static VoicemailProviderHelper createPackageScopedVoicemailProvider(Context context) {
|
||||
Uri providerUri = Uri.withAppendedPath(VoicemailProvider.CONTENT_URI_PROVIDER_QUERY,
|
||||
Uri providerUri = Uri.withAppendedPath(VoicemailContract.CONTENT_URI_SOURCE,
|
||||
context.getPackageName());
|
||||
return new VoicemailProviderHelpers(providerUri, context.getContentResolver());
|
||||
}
|
||||
@@ -120,7 +115,7 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
@Override
|
||||
public OutputStream setVoicemailContent(Uri voicemailUri, String mimeType) throws IOException {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DATA_MIME_TYPE, mimeType);
|
||||
values.put(Voicemails.MIME_TYPE, mimeType);
|
||||
int updatedCount = mContentResolver.update(voicemailUri, values, null, null);
|
||||
if (updatedCount != 1) {
|
||||
throw new IOException("Updating voicemail should have updated 1 row, was: "
|
||||
@@ -131,15 +126,14 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Voicemail findVoicemailByProviderData(String providerData) {
|
||||
public Voicemail findVoicemailBySourceData(String sourceData) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = mContentResolver.query(mBaseUri, FULL_PROJECTION,
|
||||
DbQueryUtils.getEqualityClause(
|
||||
VoicemailProvider.Tables.Voicemails.NAME, PROVIDER_DATA, providerData),
|
||||
DbQueryUtils.getEqualityClause(Voicemails.SOURCE_DATA, sourceData),
|
||||
null, null);
|
||||
if (cursor.getCount() != 1) {
|
||||
logger.w("Expected 1 voicemail matching providerData " + providerData + ", got " +
|
||||
logger.w("Expected 1 voicemail matching sourceData " + sourceData + ", got " +
|
||||
cursor.getCount());
|
||||
return null;
|
||||
}
|
||||
@@ -244,23 +238,26 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
}
|
||||
|
||||
private VoicemailImpl getVoicemailFromCursor(Cursor cursor) {
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(_ID));
|
||||
String provider = cursor.getString(cursor.getColumnIndexOrThrow(PROVIDER));
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(Voicemails._ID));
|
||||
String sourcePackage = cursor.getString(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.SOURCE_PACKAGE));
|
||||
Uri voicemailUri = ContentUris.withAppendedId(
|
||||
Uri.withAppendedPath(CONTENT_URI_PROVIDER_ID_QUERY, provider), id);
|
||||
Uri.withAppendedPath(VoicemailContract.CONTENT_URI_SOURCE, sourcePackage), id);
|
||||
VoicemailImpl voicemail = VoicemailImpl
|
||||
.createEmptyBuilder()
|
||||
.setTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(DATE)))
|
||||
.setNumber(cursor.getString(cursor.getColumnIndexOrThrow(NUMBER)))
|
||||
.setTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(Voicemails.DATE)))
|
||||
.setNumber(cursor.getString(cursor.getColumnIndexOrThrow(Voicemails.NUMBER)))
|
||||
.setId(id)
|
||||
.setDuration(cursor.getLong(cursor.getColumnIndexOrThrow(DURATION)))
|
||||
.setSource(provider)
|
||||
.setProviderData(cursor.getString(cursor.getColumnIndexOrThrow(PROVIDER_DATA)))
|
||||
.setDuration(cursor.getLong(cursor.getColumnIndexOrThrow(Voicemails.DURATION)))
|
||||
.setSourcePackage(sourcePackage)
|
||||
.setSourceData(cursor.getString(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.SOURCE_DATA)))
|
||||
.setUri(voicemailUri)
|
||||
.setHasContent(cursor.getInt(cursor.getColumnIndexOrThrow(_DATA_FILE_EXISTS)) == 1)
|
||||
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(READ_STATUS)) == 1)
|
||||
.setMailbox(
|
||||
mapValueToMailBoxEnum(cursor.getInt(cursor.getColumnIndexOrThrow(STATE))))
|
||||
.setHasContent(cursor.getInt(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.HAS_CONTENT)) == 1)
|
||||
.setIsRead(cursor.getInt(cursor.getColumnIndexOrThrow(Voicemails.NEW)) == 1)
|
||||
.setMailbox(mapValueToMailBoxEnum(cursor.getInt(
|
||||
cursor.getColumnIndexOrThrow(Voicemails.STATE))))
|
||||
.build();
|
||||
return voicemail;
|
||||
}
|
||||
@@ -280,25 +277,25 @@ public final class VoicemailProviderHelpers implements VoicemailProviderHelper {
|
||||
private ContentValues getContentValues(Voicemail voicemail) {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
if (voicemail.hasTimestampMillis()) {
|
||||
contentValues.put(DATE, String.valueOf(voicemail.getTimestampMillis()));
|
||||
contentValues.put(Voicemails.DATE, String.valueOf(voicemail.getTimestampMillis()));
|
||||
}
|
||||
if (voicemail.hasNumber()) {
|
||||
contentValues.put(NUMBER, voicemail.getNumber());
|
||||
contentValues.put(Voicemails.NUMBER, voicemail.getNumber());
|
||||
}
|
||||
if (voicemail.hasDuration()) {
|
||||
contentValues.put(DURATION, String.valueOf(voicemail.getDuration()));
|
||||
contentValues.put(Voicemails.DURATION, String.valueOf(voicemail.getDuration()));
|
||||
}
|
||||
if (voicemail.hasSource()) {
|
||||
contentValues.put(PROVIDER, voicemail.getSource());
|
||||
if (voicemail.hasSourcePackage()) {
|
||||
contentValues.put(Voicemails.SOURCE_PACKAGE, voicemail.getSourcePackage());
|
||||
}
|
||||
if (voicemail.hasProviderData()) {
|
||||
contentValues.put(PROVIDER_DATA, voicemail.getProviderData());
|
||||
if (voicemail.hasSourceData()) {
|
||||
contentValues.put(Voicemails.SOURCE_DATA, voicemail.getSourceData());
|
||||
}
|
||||
if (voicemail.hasRead()) {
|
||||
contentValues.put(READ_STATUS, voicemail.isRead() ? 1 : 0);
|
||||
contentValues.put(Voicemails.NEW, voicemail.isRead() ? 1 : 0);
|
||||
}
|
||||
if (voicemail.hasMailbox()) {
|
||||
contentValues.put(STATE, voicemail.getMailbox().getValue());
|
||||
contentValues.put(Voicemails.STATE, voicemail.getMailbox().getValue());
|
||||
}
|
||||
return contentValues;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,14 @@ public class DbQueryUtils {
|
||||
private DbQueryUtils() {
|
||||
}
|
||||
|
||||
/** Returns a WHERE clause assert equality of a field to a value. */
|
||||
/** Returns a WHERE clause assert equality of a field to a value for the specified table . */
|
||||
public static String getEqualityClause(String table, String field, String value) {
|
||||
return getEqualityClause(table + "." + field, value);
|
||||
}
|
||||
|
||||
/** Returns a WHERE clause assert equality of a field to a value. */
|
||||
public static String getEqualityClause(String field, String value) {
|
||||
StringBuilder clause = new StringBuilder();
|
||||
clause.append(table);
|
||||
clause.append(".");
|
||||
clause.append(field);
|
||||
clause.append(" = ");
|
||||
DatabaseUtils.appendEscapedSQLString(clause, value);
|
||||
|
||||
Reference in New Issue
Block a user