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.voicemail.impl.settings; 17 18 import android.content.Context; 19 import android.telecom.PhoneAccountHandle; 20 import com.android.dialer.common.Assert; 21 import com.android.voicemail.VoicemailComponent; 22 import com.android.voicemail.impl.OmtpVvmCarrierConfigHelper; 23 import com.android.voicemail.impl.R; 24 import com.android.voicemail.impl.VisualVoicemailPreferences; 25 import com.android.voicemail.impl.VvmLog; 26 import com.android.voicemail.impl.sync.VvmAccountManager; 27 28 /** Save whether or not a particular account is enabled in shared to be retrieved later. */ 29 public class VisualVoicemailSettingsUtil { 30 31 private static final String IS_ENABLED_KEY = "is_enabled"; 32 setEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled)33 public static void setEnabled( 34 Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { 35 VvmLog.i("VisualVoicemailSettingsUtil.setEnable", phoneAccount + " enabled:" + isEnabled); 36 new VisualVoicemailPreferences(context, phoneAccount) 37 .edit() 38 .putBoolean(IS_ENABLED_KEY, isEnabled) 39 .apply(); 40 OmtpVvmCarrierConfigHelper config = new OmtpVvmCarrierConfigHelper(context, phoneAccount); 41 if (isEnabled) { 42 config.startActivation(); 43 } else { 44 VvmAccountManager.removeAccount(context, phoneAccount); 45 config.startDeactivation(); 46 } 47 } 48 setArchiveEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled)49 public static void setArchiveEnabled( 50 Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { 51 Assert.checkArgument( 52 VoicemailComponent.get(context).getVoicemailClient().isVoicemailArchiveAvailable(context)); 53 new VisualVoicemailPreferences(context, phoneAccount) 54 .edit() 55 .putBoolean(context.getString(R.string.voicemail_visual_voicemail_archive_key), isEnabled) 56 .apply(); 57 } 58 isEnabled(Context context, PhoneAccountHandle phoneAccount)59 public static boolean isEnabled(Context context, PhoneAccountHandle phoneAccount) { 60 if (phoneAccount == null) { 61 return false; 62 } 63 64 VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); 65 if (prefs.contains(IS_ENABLED_KEY)) { 66 // isEnableByDefault is a bit expensive, so don't use it as default value of 67 // getBoolean(). The "false" here should never be actually used. 68 return prefs.getBoolean(IS_ENABLED_KEY, false); 69 } 70 return new OmtpVvmCarrierConfigHelper(context, phoneAccount).isEnabledByDefault(); 71 } 72 isArchiveEnabled(Context context, PhoneAccountHandle phoneAccount)73 public static boolean isArchiveEnabled(Context context, PhoneAccountHandle phoneAccount) { 74 Assert.isNotNull(phoneAccount); 75 76 VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); 77 return prefs.getBoolean( 78 context.getString(R.string.voicemail_visual_voicemail_archive_key), false); 79 } 80 81 /** 82 * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM 83 * app is installed). This is used to determine whether to disable the client when the carrier VVM 84 * app is installed. If the carrier VVM app is installed the client should give priority to it if 85 * the settings are not touched. 86 */ isEnabledUserSet(Context context, PhoneAccountHandle phoneAccount)87 public static boolean isEnabledUserSet(Context context, PhoneAccountHandle phoneAccount) { 88 if (phoneAccount == null) { 89 return false; 90 } 91 VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); 92 return prefs.contains(IS_ENABLED_KEY); 93 } 94 } 95