summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Quang Luong <qal@google.com> 2022-09-07 23:23:32 +0000
committer Quang Luong <qal@google.com> 2022-09-12 18:00:55 +0000
commitaabdce2242a22af99e3433686a28e4df177c616c (patch)
tree1f0abf17e228f39e02caf2eb82f1d84c2406d162
parent1b80f4f1c36050db1652a2e6cdf9384774dc34b1 (diff)
Add countdown message to P2P Invitation Received dialog
Add a countdown message "Accept in XX seconds." to the P2P Invitation Received dialog if a timeout is specified. Updated-Overlayable: TRUE Bug: 242681450 Test: adb shell cmd wifi launch-dialog-p2p-invitation-received with timeout, verify countdown message appears. Change-Id: Ia16d5191f53ba50506985023787701817364c43f
-rw-r--r--WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java33
-rw-r--r--service/ServiceWifiResources/res/values/overlayable.xml1
-rw-r--r--service/ServiceWifiResources/res/values/strings.xml7
3 files changed, 33 insertions, 8 deletions
diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java
index 0489ea28ff..62b7227f03 100644
--- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java
+++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java
@@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.icu.text.MessageFormat;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
@@ -350,7 +351,7 @@ public class WifiDialogActivity extends Activity {
if (!WifiManager.ACTION_LAUNCH_DIALOG.equals(action)) {
return false;
}
- AlertDialog dialog = null;
+ final AlertDialog dialog;
int dialogType = intent.getIntExtra(
WifiManager.EXTRA_DIALOG_TYPE, WifiManager.DIALOG_TYPE_UNKNOWN);
switch (dialogType) {
@@ -383,7 +384,7 @@ public class WifiDialogActivity extends Activity {
Log.v(TAG, "Could not create dialog with id= " + dialogId
+ " for unknown type: " + dialogType);
}
- break;
+ return false;
}
if (dialog == null) {
return false;
@@ -401,10 +402,6 @@ public class WifiDialogActivity extends Activity {
dialog.getWindow().setGravity(mGravity);
}
mActiveDialogsPerId.put(dialogId, dialog);
- dialog.show();
- if (mIsVerboseLoggingEnabled) {
- Log.v(TAG, "Showing dialog " + dialogId);
- }
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
@@ -419,10 +416,19 @@ public class WifiDialogActivity extends Activity {
intent.putExtra(
EXTRA_DIALOG_EXPIRATION_TIME_MS, SystemClock.uptimeMillis() + timeoutMs);
}
- CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, timeoutMs) {
+ CountDownTimer countDownTimer = new CountDownTimer(timeoutMs, 100) {
@Override
public void onTick(long millisUntilFinished) {
- // Do nothing.
+ 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++;
+ }
+ dialog.setMessage(MessageFormat.format(
+ getString(getStringId("wifi_p2p_invitation_seconds_remaining")),
+ secondsRemaining));
+ }
}
@Override
@@ -431,6 +437,15 @@ public class WifiDialogActivity extends Activity {
}
}.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);
}
// Allow message URLs to be clickable.
TextView messageView = dialog.findViewById(android.R.id.message);
@@ -621,6 +636,8 @@ public class WifiDialogActivity extends Activity {
AlertDialog dialog = new AlertDialog.Builder(this,
getStyleId("wifi_p2p_invitation_received_dialog"))
.setTitle(getString(getStringId("wifi_p2p_invitation_to_connect_title")))
+ // Set the message to "" to allow us to modify it after building (b/36913966).
+ .setMessage("")
.setView(textEntryView)
.setPositiveButton(getStringId("accept"), (dialogPositive, which) -> {
String pin = null;
diff --git a/service/ServiceWifiResources/res/values/overlayable.xml b/service/ServiceWifiResources/res/values/overlayable.xml
index f634587f72..8452a27ee5 100644
--- a/service/ServiceWifiResources/res/values/overlayable.xml
+++ b/service/ServiceWifiResources/res/values/overlayable.xml
@@ -287,6 +287,7 @@
<item type="string" name="ok" />
<item type="string" name="wifi_p2p_invitation_sent_title" />
<item type="string" name="wifi_p2p_invitation_to_connect_title" />
+ <item type="string" name="wifi_p2p_invitation_seconds_remaining" />
<item type="string" name="wifi_p2p_from_message" />
<item type="string" name="wifi_p2p_to_message" />
<item type="string" name="wifi_p2p_enter_pin_message" />
diff --git a/service/ServiceWifiResources/res/values/strings.xml b/service/ServiceWifiResources/res/values/strings.xml
index 244636e397..83c4e583af 100644
--- a/service/ServiceWifiResources/res/values/strings.xml
+++ b/service/ServiceWifiResources/res/values/strings.xml
@@ -100,6 +100,13 @@
<string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
<string name="wifi_p2p_invitation_to_connect_title">Invitation to connect</string>
+ <!-- The message of the P2P Invitation Received dialog indicating the seconds left to accept before auto rejection [CHAR_LIMIT=NONE] [ICU SYNTAX] -->
+ <string name="wifi_p2p_invitation_seconds_remaining">
+ {0,plural,
+ one{Accept in # second.}
+ other{Accept in # seconds.}
+ }
+ </string>
<string name="wifi_p2p_from_message">From: </string>
<string name="wifi_p2p_to_message">To: </string>
<string name="wifi_p2p_enter_pin_message">Type the required PIN: </string>