diff options
author | 2022-01-25 17:05:50 -0800 | |
---|---|---|
committer | 2022-02-01 14:04:57 -0800 | |
commit | 2bcd93e1840264aa495dca2832977f8fa92d9822 (patch) | |
tree | a1c7a04591e429394a682da1fcb65bbba56c67dd /WifiDialog/src | |
parent | c2726268ebf3df534fd76328cefe1155c3f44624 (diff) |
Add timeout to P2P invitation received dialog
Implement a timeout for P2P invitation received dialog by creating a
Intent action to cancel a specific dialogId, and posting a
delayed runnable to cancel the dialog after the timeout.
Bug: 203017876
Test: set the timeout overlay to 5000, verify adb shell cmd wifi
launch-dialog-p2p-invitation-received <ssid> is cancelled after 5000 ms,
atest WifiDialogManagerTest
Change-Id: I9871bf4f4435769b06b1d4a03843a13fa94b4eb2
Diffstat (limited to 'WifiDialog/src')
-rw-r--r-- | WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index d02ae0a979..788f8eb8f2 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -60,7 +60,7 @@ public class WifiDialogActivity extends Activity { private boolean mIsVerboseLoggingEnabled; private int mGravity = Gravity.NO_GRAVITY; - private @NonNull SparseArray<Intent> mIntentsPerId = new SparseArray<>(); + private @NonNull SparseArray<Intent> mLaunchIntentsPerId = new SparseArray<>(); private @NonNull SparseArray<Dialog> mActiveDialogsPerId = new SparseArray<>(); // Broadcast receiver for listening to ACTION_CLOSE_SYSTEM_DIALOGS @@ -154,7 +154,7 @@ public class WifiDialogActivity extends Activity { } continue; } - mIntentsPerId.put(dialogId, intent); + mLaunchIntentsPerId.put(dialogId, intent); } } @@ -167,9 +167,9 @@ public class WifiDialogActivity extends Activity { registerReceiver( mCloseSystemDialogsReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ArraySet<Integer> invalidDialogIds = new ArraySet<>(); - for (int i = 0; i < mIntentsPerId.size(); i++) { - int dialogId = mIntentsPerId.keyAt(i); - if (!createAndShowDialogForIntent(dialogId, mIntentsPerId.get(dialogId))) { + for (int i = 0; i < mLaunchIntentsPerId.size(); i++) { + int dialogId = mLaunchIntentsPerId.keyAt(i); + if (!createAndShowDialogForIntent(dialogId, mLaunchIntentsPerId.get(dialogId))) { invalidDialogIds.add(dialogId); } } @@ -192,7 +192,12 @@ public class WifiDialogActivity extends Activity { } return; } - mIntentsPerId.put(dialogId, intent); + String action = intent.getAction(); + if (WifiManager.ACTION_CANCEL_DIALOG.equals(action)) { + removeIntentAndPossiblyFinish(dialogId); + return; + } + mLaunchIntentsPerId.put(dialogId, intent); if (!createAndShowDialogForIntent(dialogId, intent)) { removeIntentAndPossiblyFinish(dialogId); } @@ -214,8 +219,8 @@ public class WifiDialogActivity extends Activity { @Override protected void onSaveInstanceState(Bundle outState) { ArrayList<Intent> intentList = new ArrayList<>(); - for (int i = 0; i < mIntentsPerId.size(); i++) { - intentList.add(mIntentsPerId.valueAt(i)); + for (int i = 0; i < mLaunchIntentsPerId.size(); i++) { + intentList.add(mLaunchIntentsPerId.valueAt(i)); } outState.putParcelableArrayList(KEY_DIALOG_INTENTS, intentList); super.onSaveInstanceState(outState); @@ -226,7 +231,7 @@ public class WifiDialogActivity extends Activity { * there are no dialogs left to show. */ private void removeIntentAndPossiblyFinish(int dialogId) { - mIntentsPerId.remove(dialogId); + mLaunchIntentsPerId.remove(dialogId); Dialog dialog = mActiveDialogsPerId.get(dialogId); mActiveDialogsPerId.remove(dialogId); if (dialog != null && dialog.isShowing()) { @@ -235,7 +240,7 @@ public class WifiDialogActivity extends Activity { if (mIsVerboseLoggingEnabled) { Log.v(TAG, "Dialog id " + dialogId + " removed."); } - if (mIntentsPerId.size() == 0) { + if (mLaunchIntentsPerId.size() == 0) { if (mIsVerboseLoggingEnabled) { Log.v(TAG, "No dialogs left to show, finishing."); } @@ -257,6 +262,10 @@ public class WifiDialogActivity extends Activity { * Returns {@code true} if the dialog was successfully created, {@code false} otherwise. */ private @Nullable boolean createAndShowDialogForIntent(int dialogId, @NonNull Intent intent) { + String action = intent.getAction(); + if (!WifiManager.ACTION_LAUNCH_DIALOG.equals(action)) { + return false; + } Dialog dialog = null; int dialogType = intent.getIntExtra( WifiManager.EXTRA_DIALOG_TYPE, WifiManager.DIALOG_TYPE_UNKNOWN); |