diff options
author | 2024-10-24 15:24:27 +0900 | |
---|---|---|
committer | 2024-10-25 16:50:54 +0900 | |
commit | 17b480b50f4d57a6f358bc57cd15cca15ec8072e (patch) | |
tree | bab980292e3800fd92cdd1b8a3ad91187bf6b2bf /WifiDialog/src | |
parent | 0787ad6eb52b956c262cf16efb0f708e8cd8a426 (diff) |
Remove timeout from all dialogs except P2P invitation received
Dialog timeout is generalized to all dialogs, but is only usedfor
the P2P invitation received dialog. Refactor the timeout logic out of
all the non-P2P-invitation-received dialogs to clean up the code and
make it easier for special P2P timeout logic (e.g. changing the message
text to show remaining time).
Flag: EXEMPT non-functional refactor
Bug: 349253691
Test: atest FrameworksWifiTests, manual test with shell command to see
if P2P dialog still shows correctly with timeout.
Change-Id: Id4a6f41073bfc4501c6e33840a40f812f84a163d
Diffstat (limited to 'WifiDialog/src')
-rw-r--r-- | WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 4dab628bbc..8069993b02 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -33,9 +33,6 @@ import android.net.wifi.WifiContext; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.CountDownTimer; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; import android.os.Vibrator; import android.text.Editable; import android.text.SpannableString; @@ -72,12 +69,9 @@ import java.util.Set; public class WifiDialogActivity extends Activity { private static final String TAG = "WifiDialog"; private static final String KEY_DIALOG_INTENTS = "KEY_DIALOG_INTENTS"; - private static final String EXTRA_DIALOG_EXPIRATION_TIME_MS = - "com.android.wifi.dialog.DIALOG_START_TIME_MS"; private static final String EXTRA_DIALOG_P2P_PIN_INPUT = "com.android.wifi.dialog.DIALOG_P2P_PIN_INPUT"; - private @NonNull Handler mHandler = new Handler(Looper.getMainLooper()); private @Nullable WifiContext mWifiContext; private @Nullable WifiManager mWifiManager; private boolean mIsVerboseLoggingEnabled; @@ -354,7 +348,8 @@ public class WifiDialogActivity extends Activity { dialogId, intent.getStringExtra(WifiManager.EXTRA_P2P_DEVICE_NAME), intent.getBooleanExtra(WifiManager.EXTRA_P2P_PIN_REQUESTED, false), - intent.getStringExtra(WifiManager.EXTRA_P2P_DISPLAY_PIN)); + intent.getStringExtra(WifiManager.EXTRA_P2P_DISPLAY_PIN), + intent.getIntExtra(WifiManager.EXTRA_DIALOG_TIMEOUT_MS, 0)); break; default: if (mIsVerboseLoggingEnabled) { @@ -378,50 +373,6 @@ public class WifiDialogActivity extends Activity { dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); } mActiveDialogsPerId.put(dialogId, dialog); - long timeoutMs = intent.getLongExtra(WifiManager.EXTRA_DIALOG_TIMEOUT_MS, 0); - if (timeoutMs > 0) { - // Use the original expiration time in case we've reloaded this dialog after a - // configuration change. - long expirationTimeMs = intent.getLongExtra(EXTRA_DIALOG_EXPIRATION_TIME_MS, 0); - if (expirationTimeMs > 0) { - timeoutMs = expirationTimeMs - SystemClock.uptimeMillis(); - if (timeoutMs < 0) { - timeoutMs = 0; - } - } else { - intent.putExtra( - EXTRA_DIALOG_EXPIRATION_TIME_MS, SystemClock.uptimeMillis() + timeoutMs); - } - CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, 100) { - @Override - public void onTick(long millisUntilFinished) { - if (dialogType == WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED) { - int secondsRemaining = (int) millisUntilFinished / 1000; - if (millisUntilFinished % 1000 != 0) { - // Round up to the nearest whole second. - secondsRemaining++; - } - TextView timeRemaining = dialog.getWindow().findViewById( - getWifiViewId("time_remaining")); - timeRemaining.setText(MessageFormat.format( - getWifiString("wifi_p2p_invitation_seconds_remaining"), - secondsRemaining)); - timeRemaining.setVisibility(View.VISIBLE); - } - } - - @Override - public void onFinish() { - removeIntentAndPossiblyFinish(dialogId); - } - }.start(); - mActiveCountDownTimersPerId.put(dialogId, countDownTimer); - } else { - if (dialogType == WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED) { - // Set the message back to null if we aren't using a timeout. - dialog.setMessage(null); - } - } dialog.show(); if (mIsVerboseLoggingEnabled) { Log.v(TAG, "Showing dialog " + dialogId); @@ -583,12 +534,14 @@ public class WifiDialogActivity extends Activity { final int dialogId, @Nullable final String deviceName, final boolean isPinRequested, - @Nullable final String displayPin) { + @Nullable final String displayPin, + int timeoutMs) { if (TextUtils.isEmpty(deviceName)) { Log.w(TAG, "P2P Invitation Received dialog device name is null or empty." + " id=" + dialogId + " deviceName=" + deviceName - + " displayPin=" + displayPin); + + " displayPin=" + displayPin + + " timeoutMs=" + timeoutMs); } final View textEntryView = getWifiLayoutInflater() .inflate(getWifiLayoutId("wifi_p2p_dialog"), null); @@ -702,6 +655,38 @@ public class WifiDialogActivity extends Activity { return true; }); } + if (timeoutMs > 0) { + CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, 100) { + @Override + public void onTick(long millisUntilFinished) { + Intent intent = mLaunchIntentsPerId.get(dialogId); + if (intent != null) { + // Store the updated timeout to use if we reload this dialog after a + // configuration change + intent.putExtra(WifiManager.EXTRA_DIALOG_TIMEOUT_MS, + (int) millisUntilFinished); + } + + int secondsRemaining = (int) millisUntilFinished / 1000; + if (millisUntilFinished % 1000 != 0) { + // Round up to the nearest whole second. + secondsRemaining++; + } + TextView timeRemaining = textEntryView.findViewById( + getWifiViewId("time_remaining")); + timeRemaining.setText(MessageFormat.format( + getWifiString("wifi_p2p_invitation_seconds_remaining"), + secondsRemaining)); + timeRemaining.setVisibility(View.VISIBLE); + } + + @Override + public void onFinish() { + removeIntentAndPossiblyFinish(dialogId); + } + }.start(); + mActiveCountDownTimersPerId.put(dialogId, countDownTimer); + } if (mIsVerboseLoggingEnabled) { Log.v(TAG, "Created P2P Invitation Received dialog." + " id=" + dialogId |