From 04ac49e193abe45fadda780668ff911b98ac3c3e Mon Sep 17 00:00:00 2001 From: uabdullah Date: Thu, 5 Apr 2018 07:22:44 -0700 Subject: Support new voicemail fragment in old peer. This makes the old peer read the CallLogConfig#isNewVoicemailFragmentEnabled and show the old or new fragment accordingly. If the user is viewing the NewVoicemail and the CallLogConfig needs to disable the framework, the new fragment is immediately replaced with the old one. This is necessary because if the user were to scroll the fragment, the AnnotatedCallLog database would be read, which would trigger creation. I tested this by flipping flags and observing underlying data being removed: > dialer-cmd configprovider set new_voicemail_fragment_enabled false > adb shell ls /data/data/com.google.android.dialer/databases/ && echo && adb shell cat /data/user_de/0/com.google.android.dialer/shared_prefs/com.google.android.dialer_preferences.xml I test flipping flags back and forth on the voicemail tab, call log tab and ensuring that they are independent. Bug: 77601968 Test: unit and manual. Some tests are failing, so to ensure we can have the voicemail ready for the bug bash tomorrow, I've ignored them temporarily but will be fixed in a follow up CL (tracked by b/77601893) PiperOrigin-RevId: 191738860 Change-Id: I24ca38b862e98324cf802a3020e7e9df31c0b966 --- .../dialer/main/impl/OldMainActivityPeer.java | 98 +++++++++++++++++----- 1 file changed, 77 insertions(+), 21 deletions(-) (limited to 'java/com/android/dialer/main') diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java index c15d7c1a8..d2a6fd8a4 100644 --- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java +++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java @@ -111,6 +111,7 @@ import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.PermissionsUtil; import com.android.dialer.util.TransactionSafeActivity; +import com.android.dialer.voicemail.listui.NewVoicemailFragment; import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler; import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler.Source; import com.android.dialer.voicemailstatus.VisualVoicemailEnabledChecker; @@ -141,7 +142,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen // TODO(calderwoodra): change to AppCompatActivity once new speed dial ships private final TransactionSafeActivity activity; - private final BroadcastReceiver disableNewCallLogReceiver = + private final BroadcastReceiver disableCallLogFrameworkReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -149,12 +150,13 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen return; } /* - * Remove the NewCallLogFragment if it is currently attached. If this is not done, user - * interaction with the fragment could cause call log framework state to be unexpectedly - * written. For example scrolling could cause the AnnotatedCallLog to be read (which would - * trigger database creation). + * Remove the NewCallLogFragment and NewVoicemailFragment if it is currently attached. If + * this is not done, user interaction with the fragment could cause call log framework + * state to be unexpectedly written. For example scrolling could cause the + * AnnotatedCallLog to be read (which would trigger database creation). */ bottomNavTabListener.disableNewCallLogFragment(); + bottomNavTabListener.disableNewVoicemailFragment(); } }; @@ -476,14 +478,16 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen * (which would trigger database creation). */ LocalBroadcastManager.getInstance(activity) - .registerReceiver(disableNewCallLogReceiver, new IntentFilter("disableNewCallLogFragment")); + .registerReceiver( + disableCallLogFrameworkReceiver, new IntentFilter("disableCallLogFramework")); /* - * Similar to above, if the new call log is being shown and then the activity is paused, when - * the user returns we need to remove the NewCallLogFragment if the framework has been disabled - * in the meantime. + * Similar to above, if the new call log/new voicemail is being shown and then the activity is + * paused, when the user returns we need to remove the NewCallLogFragment if the framework has + * been disabled in the meantime. */ bottomNavTabListener.ensureCorrectCallLogShown(); + bottomNavTabListener.ensureCorrectVoicemailShown(); if (bottomNavTabListener.newCallLogFragmentActive()) { missedCallCountObserver.onChange(false); // Set the initial value for the badge @@ -509,7 +513,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen @Override public void onActivityPause() { searchController.onActivityPause(); - LocalBroadcastManager.getInstance(activity).unregisterReceiver(disableNewCallLogReceiver); + LocalBroadcastManager.getInstance(activity).unregisterReceiver(disableCallLogFrameworkReceiver); activity.getContentResolver().unregisterContentObserver(missedCallCountObserver); } @@ -1000,7 +1004,9 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen public void onActivityResume() { activityIsAlive = true; registerVoicemailStatusContentObserver(context); - callLogQueryHandler.fetchVoicemailStatus(); + if (!bottomNavTabListener.newVoicemailFragmentActive()) { + callLogQueryHandler.fetchVoicemailStatus(); + } if (!bottomNavTabListener.newCallLogFragmentActive()) { callLogQueryHandler.fetchMissedCallsUnreadCount(); } @@ -1267,6 +1273,24 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } } + void disableNewVoicemailFragment() { + LogUtil.i("MainBottomNavBarBottomNavTabListener.disableNewVoicemailFragment", "disabled"); + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (supportFragment != null) { + supportFragmentManager.beginTransaction().remove(supportFragment).commit(); + // If the NewVoicemailFragment was showing, immediately show the old voicemail fragment + // instead. + if (selectedTab == TabIndex.VOICEMAIL) { + LogUtil.i( + "MainBottomNavBarBottomNavTabListener.disableNewVoicemailFragment", "showing old"); + Fragment fragment = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + showFragment( + fragment == null ? new VisualVoicemailCallLogFragment() : fragment, VOICEMAIL_TAG); + } + } + } + void ensureCorrectCallLogShown() { android.support.v4.app.Fragment supportFragment = supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); @@ -1277,6 +1301,18 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } } + void ensureCorrectVoicemailShown() { + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (supportFragment != null + && !CallLogConfigComponent.get(activity) + .callLogConfig() + .isNewVoicemailFragmentEnabled()) { + LogUtil.i("MainBottomNavBarBottomNavTabListener.ensureCorrectVoicemailShown", "disabling"); + disableNewVoicemailFragment(); + } + } + boolean newCallLogFragmentActive() { return supportFragmentManager.findFragmentByTag(CALL_LOG_TAG) != null || (fragmentManager.findFragmentByTag(CALL_LOG_TAG) == null @@ -1285,6 +1321,14 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen .isNewCallLogFragmentEnabled()); } + boolean newVoicemailFragmentActive() { + return supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG) != null + || (fragmentManager.findFragmentByTag(VOICEMAIL_TAG) == null + && CallLogConfigComponent.get(activity) + .callLogConfig() + .isNewVoicemailFragmentEnabled()); + } + @Override public void onContactsSelected() { LogUtil.enterBlock("MainBottomNavBarBottomNavTabListener.onContactsSelected"); @@ -1308,15 +1352,22 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } Logger.get(activity).logScreenView(ScreenEvent.Type.MAIN_VOICEMAIL, activity); selectedTab = TabIndex.VOICEMAIL; - VisualVoicemailCallLogFragment fragment = - (VisualVoicemailCallLogFragment) fragmentManager.findFragmentByTag(VOICEMAIL_TAG); - if (fragment == null) { - fragment = new VisualVoicemailCallLogFragment(); - } - showFragment(fragment, VOICEMAIL_TAG); - fragment.setUserVisibleHint(true); - fragment.onVisible(); + if (CallLogConfigComponent.get(activity).callLogConfig().isNewVoicemailFragmentEnabled()) { + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + showSupportFragment( + supportFragment == null ? new NewVoicemailFragment() : supportFragment, VOICEMAIL_TAG); + } else { + VisualVoicemailCallLogFragment fragment = + (VisualVoicemailCallLogFragment) fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (fragment == null) { + fragment = new VisualVoicemailCallLogFragment(); + } + showFragment(fragment, VOICEMAIL_TAG); + fragment.setUserVisibleHint(true); + fragment.onVisible(); + } } private void showFragment(@NonNull Fragment fragment, String tag) { @@ -1342,13 +1393,13 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen Fragment speedDial = fragmentManager.findFragmentByTag(SPEED_DIAL_TAG); Fragment oldCallLog = fragmentManager.findFragmentByTag(CALL_LOG_TAG); Fragment contacts = fragmentManager.findFragmentByTag(CONTACTS_TAG); - Fragment voicemail = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + Fragment oldVoicemail = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); FragmentTransaction transaction = fragmentManager.beginTransaction(); boolean fragmentShown = showIfEqualElseHide(transaction, fragment, speedDial); fragmentShown |= showIfEqualElseHide(transaction, fragment, oldCallLog); fragmentShown |= showIfEqualElseHide(transaction, fragment, contacts); - fragmentShown |= showIfEqualElseHide(transaction, fragment, voicemail); + fragmentShown |= showIfEqualElseHide(transaction, fragment, oldVoicemail); if (!fragmentShown && fragment != null) { LogUtil.i( @@ -1361,11 +1412,16 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen // TODO(calderwoodra): Handle other new fragments. android.support.v4.app.Fragment newCallLog = supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); + android.support.v4.app.Fragment newVoicemail = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); android.support.v4.app.FragmentTransaction supportTransaction = supportFragmentManager.beginTransaction(); boolean supportFragmentShown = showIfEqualElseHideSupport(supportTransaction, supportFragment, newCallLog); + supportFragmentShown |= + showIfEqualElseHideSupport(supportTransaction, supportFragment, newVoicemail); + if (!supportFragmentShown && supportFragment != null) { LogUtil.i( "MainBottomNavBarBottomNavTabListener.showFragment", -- cgit v1.2.3