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.phone.vvm.omtp.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.phone.settings.VisualVoicemailSettingsUtil; 26 import com.android.phone.vvm.omtp.ActivationTask; 27 import com.android.phone.vvm.omtp.VvmLog; 28 import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter; 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 (VoicemailContract.ACTION_SYNC_VOICEMAIL.equals(intent.getAction())) { 38 VvmLog.v(TAG, "Sync intent received"); 39 for (PhoneAccountHandle source : OmtpVvmSourceManager.getInstance(context) 40 .getOmtpVvmSources()) { 41 SyncTask.start(context, source, OmtpVvmSyncService.SYNC_FULL_SYNC); 42 } 43 activateUnactivatedAccounts(context); 44 } 45 } 46 activateUnactivatedAccounts(Context context)47 private static void activateUnactivatedAccounts(Context context) { 48 List<PhoneAccountHandle> accounts = 49 context.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts(); 50 for (PhoneAccountHandle phoneAccount : accounts) { 51 if (!VisualVoicemailSettingsUtil.isEnabled(context, phoneAccount)) { 52 continue; 53 } 54 int subId = PhoneAccountHandleConverter.toSubId(phoneAccount); 55 if (!OmtpVvmSourceManager.getInstance(context).isVvmSourceRegistered(phoneAccount)) { 56 VvmLog.i(TAG, "Unactivated account " + phoneAccount + " found, activating"); 57 ActivationTask.start(context, subId, null); 58 } 59 } 60 } 61 } 62