From 9fbb0d35e8ffe5245ff8b2b4db4dfd7e98b62a90 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Mon, 23 Aug 2021 16:51:27 -0400 Subject: [PATCH] Remove watchdog timer logic in ChooserActivity. This timeout was intended for the deprecated ChooserTargetService, and as of ag/15644659 we no longer rely on it in the new flow. Since we're no longer dependent on CTS connections for our completion conditions, the timeout-handling logic was always fired both on the "min" and the "max" watchdog periods, apparently resulting in a spurious additional logDirectShareTargetReceived call (both with ACTION_DIRECT_SHARE_TARGETS_LOADED_CHOOSER_SERVICE). The new condition added in ag/15644659 results in an *additional* spurious log event when the share targets are finished loading, but as of this CL that load-completion callback will be the sole place that we perform the logging. Test: manual / presubmits Change-Id: Ied1f7c90159d4db42669f0b7e046a9c0a16cb6d0 --- .../android/internal/app/ChooserActivity.java | 59 +------------------ 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 02cd8db8d3e73..c5c7e25da1d0f 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -458,56 +458,19 @@ public class ChooserActivity extends ResolverActivity implements private class ChooserHandler extends Handler { private static final int CHOOSER_TARGET_SERVICE_RESULT = 1; - private static final int CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT = 2; - private static final int CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT = 3; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT = 4; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED = 5; private static final int LIST_VIEW_UPDATE_MESSAGE = 6; - private static final int WATCHDOG_TIMEOUT_MAX_MILLIS = 1000; - private static final int WATCHDOG_TIMEOUT_MIN_MILLIS = 300; - - private boolean mMinTimeoutPassed = false; private boolean mReceivedDirectShareTargets = false; private void removeAllMessages() { removeMessages(LIST_VIEW_UPDATE_MESSAGE); - removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT); - removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT); removeMessages(CHOOSER_TARGET_SERVICE_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED); } - private void restartServiceRequestTimer() { - mMinTimeoutPassed = false; - removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT); - removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT); - - if (DEBUG) { - Log.d(TAG, "queryTargets setting watchdog timer for " - + WATCHDOG_TIMEOUT_MAX_MILLIS + "ms"); - } - - sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT, - WATCHDOG_TIMEOUT_MIN_MILLIS); - sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT, - WATCHDOG_TIMEOUT_MAX_MILLIS); - } - - private void maybeStopServiceRequestTimer() { - // Set a minimum timeout threshold, to ensure both apis, sharing shortcuts - // and older-style direct share services, have had time to load, otherwise - // just checking mServiceConnections could force us to end prematurely - if (mMinTimeoutPassed && mServiceConnections.isEmpty() && mReceivedDirectShareTargets) { - logDirectShareTargetReceived( - MetricsEvent.ACTION_DIRECT_SHARE_TARGETS_LOADED_CHOOSER_SERVICE); - sendVoiceChoicesIfNeeded(); - mChooserMultiProfilePagerAdapter.getActiveListAdapter() - .completeServiceTargetLoading(); - } - } - @Override public void handleMessage(Message msg) { if (mChooserMultiProfilePagerAdapter.getActiveListAdapter() == null || isDestroyed()) { @@ -543,21 +506,6 @@ public class ChooserActivity extends ResolverActivity implements unbindService(sri.connection); sri.connection.destroy(); mServiceConnections.remove(sri.connection); - maybeStopServiceRequestTimer(); - break; - - case CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT: - mMinTimeoutPassed = true; - maybeStopServiceRequestTimer(); - break; - - case CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT: - mMinTimeoutPassed = true; - if (!mServiceConnections.isEmpty()) { - getChooserActivityLogger().logSharesheetDirectLoadTimeout(); - } - unbindRemainingServices(); - maybeStopServiceRequestTimer(); break; case LIST_VIEW_UPDATE_MESSAGE: @@ -586,14 +534,13 @@ public class ChooserActivity extends ResolverActivity implements break; case SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED: - mReceivedDirectShareTargets = true; - logDirectShareTargetReceived( MetricsEvent.ACTION_DIRECT_SHARE_TARGETS_LOADED_SHORTCUT_MANAGER); sendVoiceChoicesIfNeeded(); getChooserActivityLogger().logSharesheetDirectLoadComplete(); - maybeStopServiceRequestTimer(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter() + .completeServiceTargetLoading(); break; default: @@ -2028,8 +1975,6 @@ public class ChooserActivity extends ResolverActivity implements break; } } - - mChooserHandler.restartServiceRequestTimer(); } private IntentFilter getTargetIntentFilter() {