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.settings; 17 18 import android.content.Context; 19 import android.telecom.PhoneAccountHandle; 20 import com.android.phone.R; 21 import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper; 22 import com.android.phone.vvm.omtp.VisualVoicemailPreferences; 23 import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager; 24 import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter; 25 26 /** 27 * Save whether or not a particular account is enabled in shared to be retrieved later. 28 */ 29 public class VisualVoicemailSettingsUtil { 30 31 private static final String IS_ENABLED_KEY = "is_enabled"; 32 33 setEnabled(Context context, PhoneAccountHandle phoneAccount, boolean isEnabled)34 public static void setEnabled(Context context, PhoneAccountHandle phoneAccount, 35 boolean isEnabled) { 36 new VisualVoicemailPreferences(context, phoneAccount).edit() 37 .putBoolean(IS_ENABLED_KEY, isEnabled) 38 .apply(); 39 OmtpVvmCarrierConfigHelper config = new OmtpVvmCarrierConfigHelper(context, phoneAccount); 40 if (isEnabled) { 41 OmtpVvmSourceManager.getInstance(context).addPhoneStateListener(phoneAccount); 42 config.startActivation(); 43 } else { 44 OmtpVvmSourceManager.getInstance(context).removeSource(phoneAccount); 45 config.startDeactivation(); 46 } 47 } 48 isEnabled(Context context, PhoneAccountHandle phoneAccount)49 public static boolean isEnabled(Context context, 50 PhoneAccountHandle phoneAccount) { 51 if (phoneAccount == null) { 52 return false; 53 } 54 if (!context.getResources().getBoolean(R.bool.allow_visual_voicemail)) { 55 return false; 56 } 57 58 VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); 59 if (prefs.contains(IS_ENABLED_KEY)) { 60 // isEnableByDefault is a bit expensive, so don't use it as default value of 61 // getBoolean(). The "false" here should never be actually used. 62 return prefs.getBoolean(IS_ENABLED_KEY, false); 63 } 64 return new OmtpVvmCarrierConfigHelper(context, 65 PhoneAccountHandleConverter.toSubId(phoneAccount)).isEnabledByDefault(); 66 } 67 68 /** 69 * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM 70 * app is installed). This is used to determine whether to disable the client when the carrier 71 * VVM app is installed. If the carrier VVM app is installed the client should give priority to 72 * it if the settings are not touched. 73 */ isEnabledUserSet(Context context, PhoneAccountHandle phoneAccount)74 public static boolean isEnabledUserSet(Context context, 75 PhoneAccountHandle phoneAccount) { 76 if (phoneAccount == null) { 77 return false; 78 } 79 VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); 80 return prefs.contains(IS_ENABLED_KEY); 81 } 82 } 83