diff options
author | Eric Erfanian <erfanian@google.com> | 2017-06-22 09:39:08 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-06-22 17:23:58 +0000 |
commit | 842a9777de13bebb1c82f9d57222c52f9ddec558 (patch) | |
tree | 742285fa641f62ba0b358a65a452f4f65db04ce2 /java/com/android/voicemail/impl/sync/VvmAccountManager.java | |
parent | a8a71b12c67ca852382e94d5e6d5d04430529902 (diff) |
Update AOSP Dialer source from internal google3 repository at
cl/159771812.
Test: make, treehugger
This CL updates the AOSP Dialer source with all the changes that have
gone into the private google3 repository. This includes all the
changes from cl/159428781 (6/19/2017) to cl/159771812 (6/22/2017).
These changes track the dialer V11 release.
This goal of these drops is to keep the AOSP source in sync with the
internal google3 repository. Currently these sync are done by hand
with very minor modifications to the internal source code.
See the Android.mk file for list of modifications.
Merged-In: I39aba7e972bac6e5864e70ed693849d90ecd7e08
Change-Id: Ia87877f7ae67c5b56078477b8b08082de1355315
Diffstat (limited to 'java/com/android/voicemail/impl/sync/VvmAccountManager.java')
-rw-r--r-- | java/com/android/voicemail/impl/sync/VvmAccountManager.java | 61 |
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)); + } } |