1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.voicemail.impl.sync; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.provider.VoicemailContract; 23 import android.telecom.PhoneAccountHandle; 24 import android.telecom.TelecomManager; 25 import com.android.voicemail.VoicemailComponent; 26 import com.android.voicemail.impl.ActivationTask; 27 import com.android.voicemail.impl.VvmLog; 28 import com.android.voicemail.impl.settings.VisualVoicemailSettingsUtil; 29 import java.util.List; 30 31 public class OmtpVvmSyncReceiver extends BroadcastReceiver { 32 33 private static final String TAG = "OmtpVvmSyncReceiver"; 34 35 @Override onReceive(final Context context, Intent intent)36 public void onReceive(final Context context, Intent intent) { 37 if (!VoicemailComponent.get(context).getVoicemailClient().isVoicemailModuleEnabled()) { 38 // ACTION_SYNC_VOICEMAIL is available pre-O, ignore if received. 39 return; 40 } 41 42 if (VoicemailContract.ACTION_SYNC_VOICEMAIL.equals(intent.getAction())) { 43 VvmLog.v(TAG, "Sync intent received"); 44 45 List<PhoneAccountHandle> accounts = 46 context.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts(); 47 for (PhoneAccountHandle phoneAccount : accounts) { 48 if (!VisualVoicemailSettingsUtil.isEnabled(context, phoneAccount)) { 49 continue; 50 } 51 if (!VvmAccountManager.isAccountActivated(context, phoneAccount)) { 52 VvmLog.i(TAG, "Unactivated account " + phoneAccount + " found, activating"); 53 ActivationTask.start(context, phoneAccount, null); 54 } else { 55 SyncTask.start(context, phoneAccount, OmtpVvmSyncService.SYNC_FULL_SYNC); 56 } 57 } 58 } 59 } 60 } 61