Home | History | Annotate | Download | only in omtp
      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     @Override
     35     public void onReceive(Context context, Intent intent) {
     36         if (intent.getData() == null) {
     37             return;
     38         }
     39 
     40         String packageName = intent.getData().getSchemeSpecificPart();
     41         if (packageName == null) {
     42             return;
     43         }
     44 
     45         OmtpVvmSourceManager vvmSourceManager = OmtpVvmSourceManager.getInstance(context);
     46         Set<PhoneAccountHandle> phoneAccounts = vvmSourceManager.getOmtpVvmSources();
     47         for (PhoneAccountHandle phoneAccount : phoneAccounts) {
     48             if (VisualVoicemailSettingsUtil.isVisualVoicemailUserSet(context, phoneAccount)) {
     49                 // Skip the check if this voicemail source's setting is overridden by the user.
     50                 continue;
     51             }
     52 
     53             OmtpVvmCarrierConfigHelper carrierConfigHelper = new OmtpVvmCarrierConfigHelper(
     54                     context, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccount));
     55             if (packageName.equals(carrierConfigHelper.getCarrierVvmPackageName())) {
     56                 VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(
     57                         context, phoneAccount, false, false);
     58                 OmtpVvmSourceManager.getInstance(context).removeSource(phoneAccount);
     59             }
     60         }
     61     }
     62 }
     63