1 /* 2 * Copyright (C) 2017 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; 18 19 import android.annotation.TargetApi; 20 import android.content.Context; 21 import android.os.Build.VERSION_CODES; 22 import android.telecom.PhoneAccountHandle; 23 import android.telecom.TelecomManager; 24 import com.android.voicemail.impl.settings.VisualVoicemailSettingsUtil; 25 26 /** 27 * When a new package is installed, check if it matches any of the vvm carrier apps of the currently 28 * enabled dialer VVM sources. The dialer VVM client will be disabled upon carrier VVM app 29 * installation, unless it was explicitly enabled by the user. 30 * 31 * <p>The ACTION_PACKAGE_ADDED broadcast can no longer be received. (see 32 * https://developer.android.com/preview/features/background.html#broadcasts) New apps are scanned 33 * when a VVM SMS is received instead, as it can be a result of the carrier VVM app trying to run 34 * activation. 35 */ 36 @TargetApi(VERSION_CODES.O) 37 public final class VvmPackageInstallHandler { 38 39 /** 40 * Iterates through all phone account and disable VVM on a account if {@code packageName} is 41 * listed as a carrier VVM package. 42 */ handlePackageInstalled(Context context)43 public static void handlePackageInstalled(Context context) { 44 // This get called every time an app is installed and will be noisy. Don't log until the app 45 // is identified as a carrier VVM app. 46 for (PhoneAccountHandle phoneAccount : 47 context.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts()) { 48 OmtpVvmCarrierConfigHelper carrierConfigHelper = 49 new OmtpVvmCarrierConfigHelper(context, phoneAccount); 50 if (!carrierConfigHelper.isValid()) { 51 continue; 52 } 53 if (!carrierConfigHelper.isCarrierAppInstalled()) { 54 continue; 55 } 56 57 // Force deactivate the client. 58 VvmLog.i( 59 "VvmPackageInstallHandler.handlePackageInstalled", 60 "Carrier VVM package installed, disabling system VVM client"); 61 VisualVoicemailSettingsUtil.setEnabled(context, phoneAccount, false); 62 } 63 } 64 } 65