Revise VVM enabled setting strategy
When a new SIM is inserted the system VVM client should be enabled by
default, unless the carrier's VVM app is installed.
If the carrier's VVM app is installed it should have higher priority
over the system VVM client. The system VVM client should disable itself
to let the carrier VVM app handle voicemails. The exception is if the
system VVM client was enabled explicitly by the user, it should not
transfer the responsibility of VVM handling.
In b/29254367 we found that when a new SIM is swapped in, the system VVM
client could be disabled by default, even though no carrier VVM app is
present. The root cause is fix in ag/1128444, but the original logic to
enable/disable system VVM client is convoluted and fragile so it is
rewritten.
The enabled settings could be flipped anywhere before this CL, which
will update the user set status stored in a preference. The full set of
conditions to enable/disable VVM is only observed in SimChangeReceiver,
which could change the enabled status while Other components just read
the status.
After this CL, only the VoicemailSettingsActivity is allowed to write
to the setting. When
VisualVoicemailSettingsUtil.isVisualVoicemailEnabled() is called, the
setting written by VoicemailSettingsActivity will be respected. If it is
not present, a full query will be done to
OmtpVvmCarrierConfigHelper.isEnabledByDefault(). Other conditions such
as R.bool.allow_visual_voicemail is also incorporated into
isVisualVoicemailEnabled().
When a new SIM is inserted, no preferences are set so isEnabledByDefault()
will be called. Since no carrier app is installed it will return true and
VVM will be enabled.
If a carrier VVM app is installed, the system client will be shut down
with VvmPackageInstallReceiver. Since isEnabledByDefault() will return
false from now on, there is no need to change the settings.
If a carrier VVM app is uninstalled, isEnabledByDefault() will return
true, and on the next boot the system client will be activated. The
system client should be activated upon uninstallation, but that is not a
regression and should be done in another CL.
If the setting is set by the user, then it will override the above logic.
Change-Id: I544b90d092765ae98c462897216d8a596244310f
Fixes: 29254367
diff --git a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
index 62abffd..94d286e 100644
--- a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
+++ b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
@@ -22,8 +22,11 @@
import com.android.internal.telephony.Phone;
import com.android.phone.PhoneUtils;
+import com.android.phone.R;
import com.android.phone.vvm.omtp.OmtpConstants;
+import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper;
import com.android.phone.vvm.omtp.sms.StatusMessage;
+import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
/**
* Save visual voicemail login values and whether or not a particular account is enabled in shared
@@ -36,9 +39,6 @@
"visual_voicemail_";
private static final String IS_ENABLED_KEY = "is_enabled";
- // If a carrier vvm app is installed, Google visual voicemail is automatically switched off
- // however, the user can override this setting.
- private static final String IS_USER_SET = "is_user_set";
// Record the timestamp of the last full sync so that duplicate syncs can be reduced.
private static final String LAST_FULL_SYNC_TIMESTAMP = "last_full_sync_timestamp";
// Constant indicating that there has never been a full sync.
@@ -49,23 +49,14 @@
private static final long MAX_SYNC_RETRY_INTERVAL_MS = 86400000; // 24 hours
private static final long DEFAULT_SYNC_RETRY_INTERVAL_MS = 900000; // 15 minutes
-
- public static void setVisualVoicemailEnabled(Phone phone, boolean isEnabled,
- boolean isUserSet) {
- setVisualVoicemailEnabled(phone.getContext(), PhoneUtils.makePstnPhoneAccountHandle(phone),
- isEnabled, isUserSet);
- }
-
- public static void setVisualVoicemailEnabled(Context context, PhoneAccountHandle phoneAccount,
- boolean isEnabled, boolean isUserSet) {
+ /* package */
+ static void setVisualVoicemailEnabled(Context context, PhoneAccountHandle phoneAccount,
+ boolean isEnabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(
- getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount), isEnabled);
- editor.putBoolean(
- getVisualVoicemailSharedPrefsKey(IS_USER_SET, phoneAccount),
- isUserSet);
- editor.commit();
+ prefs.edit()
+ .putBoolean(getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount),
+ isEnabled)
+ .apply();
}
public static boolean isVisualVoicemailEnabled(Context context,
@@ -73,9 +64,19 @@
if (phoneAccount == null) {
return false;
}
+ if (!context.getResources().getBoolean(R.bool.allow_visual_voicemail)) {
+ return false;
+ }
+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getBoolean(getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount),
- false);
+ String key = getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount);
+ if (prefs.contains(key)) {
+ // isEnableByDefault is a bit expensive, so don't use it as default value of
+ // getBoolean(). The "false" here should never be actually used.
+ return prefs.getBoolean(key, false);
+ }
+ return new OmtpVvmCarrierConfigHelper(context,
+ PhoneAccountHandleConverter.toSubId(phoneAccount)).isEnabledByDefault();
}
public static boolean isVisualVoicemailEnabled(Phone phone) {
@@ -84,9 +85,10 @@
}
/**
- * Differentiate user-enabled/disabled to know whether to ignore automatic enabling and
- * disabling by the system. This is relevant when a carrier vvm app is installed and the user
- * manually enables dialer visual voicemail. In that case we would want that setting to persist.
+ * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM
+ * app is installed). This is used to determine whether to disable the client when the carrier
+ * VVM app is installed. If the carrier VVM app is installed the client should give priority to
+ * it if the settings are not touched.
*/
public static boolean isVisualVoicemailUserSet(Context context,
PhoneAccountHandle phoneAccount) {
@@ -94,9 +96,7 @@
return false;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getBoolean(
- getVisualVoicemailSharedPrefsKey(IS_USER_SET, phoneAccount),
- false);
+ return prefs.contains(getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount));
}
public static void setVisualVoicemailCredentialsFromStatusMessage(Context context,
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index fc53f15..09f9e03 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -30,6 +30,7 @@
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.provider.ContactsContract.CommonDataKinds;
+import android.telecom.PhoneAccountHandle;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
@@ -397,8 +398,10 @@
VoicemailNotificationSettingsUtil.setVibrationEnabled(
mPhone, Boolean.TRUE.equals(objValue));
} else if (preference.getKey().equals(mVoicemailVisualVoicemail.getKey())) {
- boolean isEnabled = (Boolean) objValue;
- VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(mPhone, isEnabled, true);
+ boolean isEnabled = (boolean) objValue;
+ PhoneAccountHandle handle = PhoneUtils.makePstnPhoneAccountHandle(mPhone);
+ VisualVoicemailSettingsUtil
+ .setVisualVoicemailEnabled(mPhone.getContext(), handle, isEnabled);
PreferenceScreen prefSet = getPreferenceScreen();
if (isEnabled) {
OmtpVvmSourceManager.getInstance(mPhone.getContext()).addPhoneStateListener(mPhone);
diff --git a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
index 798f5da..cd27ade 100644
--- a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
+++ b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
@@ -174,6 +174,10 @@
* so by checking if the carrier's voicemail app is installed.
*/
public boolean isEnabledByDefault() {
+ if (!isValid()) {
+ return false;
+ }
+
Set<String> carrierPackages = getCarrierVvmPackageNames();
if (carrierPackages == null) {
return true;
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index 01d6bf9..833daa9 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -28,7 +28,6 @@
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
-import com.android.phone.R;
import com.android.phone.settings.VisualVoicemailSettingsUtil;
import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager;
import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
@@ -90,24 +89,7 @@
if (carrierConfigHelper.isValid()) {
PhoneAccountHandle phoneAccount = PhoneAccountHandleConverter.fromSubId(subId);
- boolean isUserSet = VisualVoicemailSettingsUtil.isVisualVoicemailUserSet(
- context, phoneAccount);
- boolean isEnabledInSettings =
- VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(context,
- phoneAccount);
- boolean isSupported =
- context.getResources().getBoolean(R.bool.allow_visual_voicemail);
- boolean isEnabled = isSupported && (isUserSet ? isEnabledInSettings :
- carrierConfigHelper.isEnabledByDefault());
-
- if (!isUserSet) {
- // Preserve the previous setting for "isVisualVoicemailEnabled" if it is
- // set by the user, otherwise, set this value for the first time.
- VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(context, phoneAccount,
- isEnabled, /** isUserSet */false);
- }
-
- if (isEnabled) {
+ if (VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(context, phoneAccount)) {
LocalLogHelper.log(TAG, "Sim state or carrier config changed: requesting"
+ " activation for " + phoneAccount.getId());
diff --git a/src/com/android/phone/vvm/omtp/VvmPackageInstallReceiver.java b/src/com/android/phone/vvm/omtp/VvmPackageInstallReceiver.java
index 8d438ef..08faba7 100644
--- a/src/com/android/phone/vvm/omtp/VvmPackageInstallReceiver.java
+++ b/src/com/android/phone/vvm/omtp/VvmPackageInstallReceiver.java
@@ -56,8 +56,9 @@
continue;
}
if (carrierConfigHelper.getCarrierVvmPackageNames().contains(packageName)) {
- VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(
- context, phoneAccount, false, false);
+ // Force deactivate the client. The user can re-enable it in the settings.
+ // There are no need to update the settings for deactivation. At this point, if the
+ // default value is used it should be false because a carrier package is present.
OmtpVvmSourceManager.getInstance(context).removeSource(phoneAccount);
carrierConfigHelper.startDeactivation();
}
diff --git a/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java b/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
index feb3c5a..d9939c2 100644
--- a/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
+++ b/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
@@ -166,11 +166,7 @@
PhoneGlobals.getInstance().clearMwiIndicator(subId);
} else {
- Log.w(TAG, "Visual voicemail not available for subscriber.");
- // Override default isEnabled setting to false since visual voicemail is unable to
- // be accessed for some reason.
- VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(mContext, phone,
- /* isEnabled */ false, /* isUserSet */ true);
+ Log.e(TAG, "Visual voicemail not available for subscriber.");
}
}
}