diff options
author | 2024-11-05 01:31:37 +0000 | |
---|---|---|
committer | 2024-11-05 01:31:37 +0000 | |
commit | 5a8c65de6eefd18bdfbf4570082eccd78c0e48bb (patch) | |
tree | e02ca5b42b7169581956cc5337fd29066fe96d13 /WifiDialog | |
parent | b3fab83cab6f26aae8acb4ec2a4f10358f1b1b44 (diff) | |
parent | d3a4cd09e280cf9e2c86adccc87313fcbffe6f54 (diff) |
Merge changes I94a88ccd,Id4a6f410 into main
* changes:
Add overlay to control showing P2P invitation timeout
Remove timeout from all dialogs except P2P invitation received
Diffstat (limited to 'WifiDialog')
-rw-r--r-- | WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java | 94 |
1 files changed, 41 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..043e430d71 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,41 @@ 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); + } + + if (!getWifiBoolean("config_p2pInvitationReceivedDialogShowRemainingTime")) { + return; + } + 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 |