diff options
-rw-r--r-- | api/current.txt | 17 | ||||
-rw-r--r-- | api/system-current.txt | 17 | ||||
-rw-r--r-- | core/java/android/provider/VoicemailContract.java | 47 | ||||
-rw-r--r-- | telecomm/java/android/telecom/VvmSyncService.java | 114 |
4 files changed, 49 insertions, 146 deletions
diff --git a/api/current.txt b/api/current.txt index bfe8f62..2e51637 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26507,6 +26507,7 @@ package android.provider { public static final class VoicemailContract.Status implements android.provider.BaseColumns { method public static android.net.Uri buildSourceUri(java.lang.String); + method public static void setStatus(android.content.Context, android.telecom.PhoneAccountHandle, int, int, int); field public static final java.lang.String CONFIGURATION_STATE = "configuration_state"; field public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2; // 0x2 field public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1; // 0x1 @@ -29056,22 +29057,6 @@ package android.telecom { method public android.telecom.Voicemail.Builder setUri(android.net.Uri); } - public class VvmSyncService extends android.app.Service { - ctor public VvmSyncService(); - method public android.os.IBinder onBind(android.content.Intent); - } - - public class VvmSyncService.VvmSyncAdapter extends android.content.AbstractThreadedSyncAdapter { - ctor public VvmSyncService.VvmSyncAdapter(android.content.Context, boolean); - method protected java.util.List<android.telecom.Voicemail> downloadVoicemails(); - method public void onPerformSync(android.accounts.Account, android.os.Bundle, java.lang.String, android.content.ContentProviderClient, android.content.SyncResult); - method protected void syncToServer(); - field public static final java.lang.String NEW_VOICEMAIL_DATA = "extra_new_voicemail_data"; - field public static final java.lang.String SYNC_EXTRA_CODE = "sync_extra_code"; - field public static final int SYNC_EXTRA_MAILBOX_UPDATE = 2; // 0x2 - field public static final int SYNC_EXTRA_NEW_VOICEMAIL = 1; // 0x1 - } - } package android.telephony { diff --git a/api/system-current.txt b/api/system-current.txt index 6a2b3d2..3821544 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -28103,6 +28103,7 @@ package android.provider { public static final class VoicemailContract.Status implements android.provider.BaseColumns { method public static android.net.Uri buildSourceUri(java.lang.String); + method public static void setStatus(android.content.Context, android.telecom.PhoneAccountHandle, int, int, int); field public static final java.lang.String CONFIGURATION_STATE = "configuration_state"; field public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2; // 0x2 field public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1; // 0x1 @@ -31176,22 +31177,6 @@ package android.telecom { method public android.telecom.Voicemail.Builder setUri(android.net.Uri); } - public class VvmSyncService extends android.app.Service { - ctor public VvmSyncService(); - method public android.os.IBinder onBind(android.content.Intent); - } - - public class VvmSyncService.VvmSyncAdapter extends android.content.AbstractThreadedSyncAdapter { - ctor public VvmSyncService.VvmSyncAdapter(android.content.Context, boolean); - method protected java.util.List<android.telecom.Voicemail> downloadVoicemails(); - method public void onPerformSync(android.accounts.Account, android.os.Bundle, java.lang.String, android.content.ContentProviderClient, android.content.SyncResult); - method protected void syncToServer(); - field public static final java.lang.String NEW_VOICEMAIL_DATA = "extra_new_voicemail_data"; - field public static final java.lang.String SYNC_EXTRA_CODE = "sync_extra_code"; - field public static final int SYNC_EXTRA_MAILBOX_UPDATE = 2; // 0x2 - field public static final int SYNC_EXTRA_NEW_VOICEMAIL = 1; // 0x1 - } - } package android.telephony { diff --git a/core/java/android/provider/VoicemailContract.java b/core/java/android/provider/VoicemailContract.java index 03cf6e3..0da4fd5 100644 --- a/core/java/android/provider/VoicemailContract.java +++ b/core/java/android/provider/VoicemailContract.java @@ -24,8 +24,10 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; +import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; +import android.telecom.PhoneAccountHandle; import android.telecom.Voicemail; import java.util.List; @@ -428,5 +430,50 @@ public class VoicemailContract { return Status.CONTENT_URI.buildUpon() .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build(); } + + /** + * A helper method to set the status of a voicemail source. + * + * @param context The context from the package calling the method. This will be the source. + * @param accountHandle The handle for the account the source is associated with. + * @param configurationState See {@link Status#CONFIGURATION_STATE} + * @param dataChannelState See {@link Status#DATA_CHANNEL_STATE} + * @param notificationChannelState See {@link Status#NOTIFICATION_CHANNEL_STATE} + */ + public static void setStatus(Context context, PhoneAccountHandle accountHandle, + int configurationState, int dataChannelState, int notificationChannelState) { + ContentResolver contentResolver = context.getContentResolver(); + Uri statusUri = buildSourceUri(context.getPackageName()); + ContentValues values = new ContentValues(); + values.put(Status.PHONE_ACCOUNT_COMPONENT_NAME, + accountHandle.getComponentName().toString()); + values.put(Status.PHONE_ACCOUNT_ID, accountHandle.getId()); + values.put(Status.CONFIGURATION_STATE, configurationState); + values.put(Status.DATA_CHANNEL_STATE, dataChannelState); + values.put(Status.NOTIFICATION_CHANNEL_STATE, notificationChannelState); + + if (isStatusPresent(contentResolver, statusUri)) { + contentResolver.update(statusUri, values, null, null); + } else { + contentResolver.insert(statusUri, values); + } + } + + /** + * Determines if a voicemail source exists in the status table. + * + * @param contentResolver A content resolver constructed from the appropriate context. + * @param statusUri The content uri for the source. + * @return {@code true} if a status entry for this source exists + */ + private static boolean isStatusPresent(ContentResolver contentResolver, Uri statusUri) { + Cursor cursor = null; + try { + cursor = contentResolver.query(statusUri, null, null, null, null); + return cursor != null && cursor.getCount() != 0; + } finally { + if (cursor != null) cursor.close(); + } + } } } diff --git a/telecomm/java/android/telecom/VvmSyncService.java b/telecomm/java/android/telecom/VvmSyncService.java deleted file mode 100644 index 2aaf348..0000000 --- a/telecomm/java/android/telecom/VvmSyncService.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2015 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 - */ - -/** - * A {@link Service} which runs the internal implementation of {@link AbstractThreadedSyncAdapter}, - * syncing voicemails to and from a visual voicemail server. - */ - -package android.telecom; - -import android.accounts.Account; -import android.app.Service; -import android.content.AbstractThreadedSyncAdapter; -import android.content.ContentProviderClient; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.SyncResult; -import android.os.Bundle; -import android.os.IBinder; -import android.provider.VoicemailContract; - -import java.util.ArrayList; -import java.util.List; - -/** - * A service to run the VvmSyncAdapter. - */ -public class VvmSyncService extends Service { - // Storage for an instance of the sync adapter - private static VvmSyncAdapter sSyncAdapter = null; - // Object to use as a thread-safe lock - private static final Object sSyncAdapterLock = new Object(); - - @Override - public void onCreate() { - synchronized (sSyncAdapterLock) { - if (sSyncAdapter == null) { - sSyncAdapter = new VvmSyncAdapter(getApplicationContext(), true); - } - } - } - - @Override - public IBinder onBind(Intent intent) { - return sSyncAdapter.getSyncAdapterBinder(); - } - - public class VvmSyncAdapter extends AbstractThreadedSyncAdapter { - /** The key to get the extra designating the type of sync action to perform. */ - public final static String SYNC_EXTRA_CODE = "sync_extra_code"; - /** The key to get the {@code Voicemail} object for a new voicemail. */ - public final static String NEW_VOICEMAIL_DATA = "extra_new_voicemail_data"; - /** Sync a new voicemail from the carrier to the device. */ - public final static int SYNC_EXTRA_NEW_VOICEMAIL = 1; - /** Sync all voicemails because the mailbox was changed remotely. */ - public final static int SYNC_EXTRA_MAILBOX_UPDATE = 2; - - private final Context mContext; - - public VvmSyncAdapter(Context context, boolean autoInitialize) { - super(context, autoInitialize); - mContext = context; - } - - @Override - public void onPerformSync(Account account, Bundle extras, String authority, - ContentProviderClient provider, SyncResult syncResult) { - if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false)) { - // notify server that voicemail has been changed - syncToServer(); - } - - final int syncAction = extras.getInt(SYNC_EXTRA_CODE); - switch (syncAction) { - /** sync from carrier */ - case SYNC_EXTRA_NEW_VOICEMAIL: - // Log new voicemail in voicemail provider. - Voicemail newVoicemail = extras.getParcelable(NEW_VOICEMAIL_DATA); - VoicemailContract.Voicemails.insert(mContext, newVoicemail); - break; - case SYNC_EXTRA_MAILBOX_UPDATE: - // Clear and reload all voicemails because the mailbox was updated remotely. - VoicemailContract.Voicemails.deleteAll(mContext); - List<Voicemail> voicemails = downloadVoicemails(); - VoicemailContract.Voicemails.insert(mContext, voicemails); - break; - default: - break; - } - } - - /** Subclasses should implement this method to sync changes to server */ - protected void syncToServer() { } - - /** Subclasses should implement this method to download voicemails */ - protected List<Voicemail> downloadVoicemails() { - return new ArrayList<Voicemail>(); - } - } -} |