migration user setting to VM notificationchannel
- move voicemailNotificationSettingsUtil from package/service/telephony
to framework/opt/telephony/util so that it can be referenced by
notificationChannelController
- voicemail notification user preference was based on subId but
notification channel don't differentiate subId. simply read the
default subId from preference and migrate if there is a match.
Bug: 62100344
Test: Manual test
Change-Id: If9f446e094216a54087c9af4f7634f1d096669c9
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 8afe14f..b5b4bb6 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -93,11 +93,10 @@
import com.android.internal.telephony.uicc.UiccCard;
import com.android.internal.telephony.uicc.UiccCardApplication;
import com.android.internal.telephony.uicc.UiccController;
+import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
import com.android.internal.util.HexDump;
-import com.android.phone.settings.VoicemailNotificationSettingsUtil;
import com.android.phone.vvm.PhoneAccountHandleConverter;
import com.android.phone.vvm.RemoteVvmTaskManager;
-import com.android.phone.vvm.VisualVoicemailPreferences;
import com.android.phone.vvm.VisualVoicemailSettingsUtil;
import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
@@ -3437,7 +3436,7 @@
phone = mPhone;
}
- return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
+ return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
}
/**
@@ -3464,7 +3463,7 @@
if (phone == null){
phone = mPhone;
}
- VoicemailNotificationSettingsUtil.setRingtoneUri(phone, uri);
+ VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
}
/**
@@ -3481,7 +3480,7 @@
phone = mPhone;
}
- return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
+ return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
}
/**
@@ -3509,7 +3508,7 @@
if (phone == null){
phone = mPhone;
}
- VoicemailNotificationSettingsUtil.setVibrationEnabled(phone, enabled);
+ VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
}
/**
diff --git a/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java b/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java
deleted file mode 100644
index fb7baf5..0000000
--- a/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone.settings;
-
-import android.app.NotificationChannel;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.preference.PreferenceManager;
-import android.telephony.TelephonyManager;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.util.NotificationChannelController;
-import com.android.phone.R;
-
-public class VoicemailNotificationSettingsUtil {
- private static final String VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY_PREFIX =
- "voicemail_notification_ringtone_";
- private static final String VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY_PREFIX =
- "voicemail_notification_vibrate_";
-
- // Old voicemail notification vibration string constants used for migration.
- private static final String OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY =
- "button_voicemail_notification_ringtone_key";
- private static final String OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY =
- "button_voicemail_notification_vibrate_key";
- private static final String OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY =
- "button_voicemail_notification_vibrate_when_key";
- private static final String OLD_VOICEMAIL_RINGTONE_SHARED_PREFS_KEY =
- "button_voicemail_notification_ringtone_key";
- private static final String OLD_VOICEMAIL_VIBRATION_ALWAYS = "always";
- private static final String OLD_VOICEMAIL_VIBRATION_NEVER = "never";
-
- public static void setVibrationEnabled(Phone phone, boolean isEnabled) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(getVoicemailVibrationSharedPrefsKey(phone), isEnabled);
- editor.commit();
- }
-
- public static boolean isVibrationEnabled(Phone phone) {
- final NotificationChannel channel = NotificationChannelController.getChannel(
- NotificationChannelController.CHANNEL_ID_VOICE_MAIL, phone.getContext());
- return (channel != null) ? channel.shouldVibrate() : false;
- }
-
- public static void setRingtoneUri(Phone phone, Uri ringtoneUri) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
- String ringtoneUriStr = ringtoneUri != null ? ringtoneUri.toString() : "";
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(getVoicemailRingtoneSharedPrefsKey(phone), ringtoneUriStr);
- editor.commit();
- }
-
- public static Uri getRingtoneUri(Phone phone) {
- final NotificationChannel channel = NotificationChannelController.getChannel(
- NotificationChannelController.CHANNEL_ID_VOICE_MAIL, phone.getContext());
- return (channel != null) ? channel.getSound() : null;
- }
-
- /**
- * Migrate voicemail settings from {@link #OLD_VIBRATE_WHEN_KEY} or
- * {@link #OLD_VOICEMAIL_NOTIFICATION_VIBRATE_KEY}.
- *
- * TODO: Add helper which migrates settings from old version to new version.
- */
- private static void migrateVoicemailVibrationSettingsIfNeeded(
- Phone phone, SharedPreferences prefs) {
- String key = getVoicemailVibrationSharedPrefsKey(phone);
- TelephonyManager telephonyManager = TelephonyManager.from(phone.getContext());
-
- // Skip if a preference exists, or if phone is MSIM.
- if (prefs.contains(key) || telephonyManager.getPhoneCount() != 1) {
- return;
- }
-
- if (prefs.contains(OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY)) {
- boolean voicemailVibrate = prefs.getBoolean(
- OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY, false /* defValue */);
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(key, voicemailVibrate)
- .remove(OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY)
- .commit();
- }
-
- if (prefs.contains(OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY)) {
- // If vibrateWhen is always, then voicemailVibrate should be true.
- // If it is "only in silent mode", or "never", then voicemailVibrate should be false.
- String vibrateWhen = prefs.getString(
- OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY, OLD_VOICEMAIL_VIBRATION_NEVER);
- boolean voicemailVibrate = vibrateWhen.equals(OLD_VOICEMAIL_VIBRATION_ALWAYS);
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(key, voicemailVibrate)
- .remove(OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY)
- .commit();
- }
- }
-
- /**
- * Migrate voicemail settings from OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY.
- *
- * TODO: Add helper which migrates settings from old version to new version.
- */
- private static void migrateVoicemailRingtoneSettingsIfNeeded(
- Phone phone, SharedPreferences prefs) {
- String key = getVoicemailRingtoneSharedPrefsKey(phone);
- TelephonyManager telephonyManager = TelephonyManager.from(phone.getContext());
-
- // Skip if a preference exists, or if phone is MSIM.
- if (prefs.contains(key) || telephonyManager.getPhoneCount() != 1) {
- return;
- }
-
- if (prefs.contains(OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY)) {
- String uriString = prefs.getString(
- OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY, null /* defValue */);
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(key, uriString)
- .remove(OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY)
- .commit();
- }
- }
-
- private static String getVoicemailVibrationSharedPrefsKey(Phone phone) {
- return VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY_PREFIX + phone.getSubId();
- }
-
- public static String getVoicemailRingtoneSharedPrefsKey(Phone phone) {
- return VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY_PREFIX + phone.getSubId();
- }
-}