summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail/impl/sync/VvmAccountManager.java
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-08-31 06:57:16 -0700
committerEric Erfanian <erfanian@google.com>2017-08-31 16:13:53 +0000
commit2ca4318cc1ee57dda907ba2069bd61d162b1baef (patch)
treee282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/voicemail/impl/sync/VvmAccountManager.java
parent68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff)
Update Dialer source to latest internal Google revision.
Previously, Android's Dialer app was developed in an internal Google source control system and only exported to public during AOSP drops. The Dialer team is now switching to a public development model similar to the telephony team. This CL represents all internal Google changes that were committed to Dialer between the public O release and today's tip of tree on internal master. This CL squashes those changes into a single commit. In subsequent changes, changes will be exported on a per-commit basis. Test: make, flash install, run Merged-In: I45270eaa8ce732d71a1bd84b08c7fa0e99af3160 Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8 PiperOrigin-RevId: 167068436
Diffstat (limited to 'java/com/android/voicemail/impl/sync/VvmAccountManager.java')
-rw-r--r--java/com/android/voicemail/impl/sync/VvmAccountManager.java61
1 files changed, 57 insertions, 4 deletions
diff --git a/java/com/android/voicemail/impl/sync/VvmAccountManager.java b/java/com/android/voicemail/impl/sync/VvmAccountManager.java
index cc4e31fe3..2625fba0c 100644
--- a/java/com/android/voicemail/impl/sync/VvmAccountManager.java
+++ b/java/com/android/voicemail/impl/sync/VvmAccountManager.java
@@ -15,14 +15,20 @@
*/
package com.android.voicemail.impl.sync;
+import android.annotation.TargetApi;
import android.content.Context;
+import android.os.Build.VERSION_CODES;
+import android.os.UserManager;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.util.ArraySet;
import com.android.dialer.common.Assert;
+import com.android.dialer.common.PerAccountSharedPreferences;
import com.android.dialer.common.concurrent.ThreadUtil;
+import com.android.dialer.util.DialerUtils;
import com.android.voicemail.impl.OmtpConstants;
import com.android.voicemail.impl.VisualVoicemailPreferences;
import com.android.voicemail.impl.VoicemailStatus;
@@ -40,6 +46,7 @@ import java.util.Set;
* #removeAccount(Context, PhoneAccountHandle)} should be called to clear the connection information
* and allow reactivation.
*/
+@TargetApi(VERSION_CODES.O)
public class VvmAccountManager {
public static final String TAG = "VvmAccountManager";
@@ -49,7 +56,7 @@ public class VvmAccountManager {
void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated);
}
- private static final String IS_ACCOUNT_ACTIVATED = "is_account_activated";
+ @VisibleForTesting static final String IS_ACCOUNT_ACTIVATED = "is_account_activated";
private static Set<Listener> listeners = new ArraySet<>();
@@ -57,7 +64,8 @@ public class VvmAccountManager {
Context context, PhoneAccountHandle phoneAccountHandle, StatusMessage statusMessage) {
VisualVoicemailPreferences preferences =
new VisualVoicemailPreferences(context, phoneAccountHandle);
- statusMessage.putStatus(preferences.edit()).putBoolean(IS_ACCOUNT_ACTIVATED, true).apply();
+ statusMessage.putStatus(preferences.edit()).apply();
+ setAccountActivated(context, phoneAccountHandle, true);
ThreadUtil.postOnUiThread(
() -> {
@@ -69,10 +77,10 @@ public class VvmAccountManager {
public static void removeAccount(Context context, PhoneAccountHandle phoneAccount) {
VoicemailStatus.disable(context, phoneAccount);
+ setAccountActivated(context, phoneAccount, false);
VisualVoicemailPreferences preferences = new VisualVoicemailPreferences(context, phoneAccount);
preferences
.edit()
- .putBoolean(IS_ACCOUNT_ACTIVATED, false)
.putString(OmtpConstants.IMAP_USER_NAME, null)
.putString(OmtpConstants.IMAP_PASSWORD, null)
.apply();
@@ -86,7 +94,9 @@ public class VvmAccountManager {
public static boolean isAccountActivated(Context context, PhoneAccountHandle phoneAccount) {
Assert.isNotNull(phoneAccount);
- VisualVoicemailPreferences preferences = new VisualVoicemailPreferences(context, phoneAccount);
+ PerAccountSharedPreferences preferences =
+ getPreferenceForActivationState(context, phoneAccount);
+ migrateActivationState(context, preferences, phoneAccount);
return preferences.getBoolean(IS_ACCOUNT_ACTIVATED, false);
}
@@ -113,4 +123,47 @@ public class VvmAccountManager {
Assert.isMainThread();
listeners.remove(listener);
}
+
+ /**
+ * The activation state is moved from credential protected storage to device protected storage
+ * after v10, so it can be checked under FBE. The state should be migrated to avoid reactivation.
+ */
+ private static void migrateActivationState(
+ Context context,
+ PerAccountSharedPreferences deviceProtectedPreference,
+ PhoneAccountHandle phoneAccountHandle) {
+ if (!context.getSystemService(UserManager.class).isUserUnlocked()) {
+ return;
+ }
+ if (deviceProtectedPreference.contains(IS_ACCOUNT_ACTIVATED)) {
+ return;
+ }
+
+ PerAccountSharedPreferences credentialProtectedPreference =
+ new VisualVoicemailPreferences(context, phoneAccountHandle);
+
+ deviceProtectedPreference
+ .edit()
+ .putBoolean(
+ IS_ACCOUNT_ACTIVATED,
+ credentialProtectedPreference.getBoolean(IS_ACCOUNT_ACTIVATED, false))
+ .apply();
+ }
+
+ private static void setAccountActivated(
+ Context context, PhoneAccountHandle phoneAccountHandle, boolean activated) {
+ Assert.isNotNull(phoneAccountHandle);
+ getPreferenceForActivationState(context, phoneAccountHandle)
+ .edit()
+ .putBoolean(IS_ACCOUNT_ACTIVATED, activated)
+ .apply();
+ }
+
+ private static PerAccountSharedPreferences getPreferenceForActivationState(
+ Context context, PhoneAccountHandle phoneAccountHandle) {
+ return new PerAccountSharedPreferences(
+ context,
+ phoneAccountHandle,
+ DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context));
+ }
}