1 /* 2 * Copyright (C) 2015 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 package com.android.phone.vvm.omtp; 17 18 import android.content.BroadcastReceiver; 19 import android.content.Context; 20 import android.content.Intent; 21 import android.telecom.PhoneAccountHandle; 22 23 import com.android.phone.PhoneUtils; 24 import com.android.phone.settings.VisualVoicemailSettingsUtil; 25 import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager; 26 27 import java.util.Set; 28 29 /** 30 * When a new package is installed, check if it matches any of the vvm carrier apps of the currently 31 * enabled dialer vvm sources. 32 */ 33 public class VvmPackageInstallReceiver extends BroadcastReceiver { 34 35 private static final String TAG = "VvmPkgInstallReceiver"; 36 37 @Override 38 public void onReceive(Context context, Intent intent) { 39 if (intent.getData() == null) { 40 return; 41 } 42 43 String packageName = intent.getData().getSchemeSpecificPart(); 44 if (packageName == null) { 45 return; 46 } 47 48 OmtpVvmSourceManager vvmSourceManager = OmtpVvmSourceManager.getInstance(context); 49 Set<PhoneAccountHandle> phoneAccounts = vvmSourceManager.getOmtpVvmSources(); 50 for (PhoneAccountHandle phoneAccount : phoneAccounts) { 51 if (VisualVoicemailSettingsUtil.isEnabledUserSet(context, phoneAccount)) { 52 // Skip the check if this voicemail source's setting is overridden by the user. 53 continue; 54 } 55 56 OmtpVvmCarrierConfigHelper carrierConfigHelper = new OmtpVvmCarrierConfigHelper( 57 context, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccount)); 58 if (carrierConfigHelper.getCarrierVvmPackageNames() == null) { 59 continue; 60 } 61 if (carrierConfigHelper.getCarrierVvmPackageNames().contains(packageName)) { 62 // Force deactivate the client. The user can re-enable it in the settings. 63 // There are no need to update the settings for deactivation. At this point, if the 64 // default value is used it should be false because a carrier package is present. 65 VvmLog.i(TAG, "Carrier VVM package installed, disabling system VVM client"); 66 OmtpVvmSourceManager.getInstance(context).removeSource(phoneAccount); 67 carrierConfigHelper.startDeactivation(); 68 } 69 } 70 } 71 } 72