diff options
author | 2022-02-28 13:32:50 -0800 | |
---|---|---|
committer | 2022-03-02 15:56:38 -0800 | |
commit | 2103b9ffde75e5f37060e5d60436b44d1cb02204 (patch) | |
tree | 2ca079d89b7f985585b661fe6144e72aa6ee30cf | |
parent | 950c3273a1f1a1e922c683534427e0ba8c490aa6 (diff) |
Use WifiDialogManager for P2P Invitation Sent dialog
Replace usage of FrameworkFacade.makeAlertDialogBuilder(...) with the
new WifiDialogManager for the P2P Invitation Sent dialog.
Bug: 209032090
Test: atest WifiP2pServiceImplTest, manually verify dialog is shown for
CtsVerifier->Wi-Fi Direct Test->Group Client Test
->Join p2p group test (PIN)
Change-Id: I3e4b89d26c89037059614e4ba97b13a73f123d69
6 files changed, 144 insertions, 21 deletions
diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 035ad8be51..1c8ddf3c23 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -305,6 +305,12 @@ public class WifiDialogActivity extends Activity { intent.getStringExtra(WifiManager.EXTRA_DIALOG_NEGATIVE_BUTTON_TEXT), intent.getStringExtra(WifiManager.EXTRA_DIALOG_NEUTRAL_BUTTON_TEXT)); break; + case WifiManager.DIALOG_TYPE_P2P_INVITATION_SENT: + dialog = createP2pInvitationSentDialog( + dialogId, + intent.getStringExtra(WifiManager.EXTRA_P2P_DEVICE_NAME), + intent.getStringExtra(WifiManager.EXTRA_P2P_DISPLAY_PIN)); + break; case WifiManager.DIALOG_TYPE_P2P_INVITATION_RECEIVED: dialog = createP2pInvitationReceivedDialog( dialogId, @@ -436,6 +442,54 @@ public class WifiDialogActivity extends Activity { } /** + * Returns a P2P Invitation Sent Dialog for the given Intent, or {@code null} if no Dialog + * could be created. + */ + private @Nullable Dialog createP2pInvitationSentDialog( + final int dialogId, + final @NonNull String deviceName, + @Nullable String displayPin) { + if (TextUtils.isEmpty(deviceName)) { + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "Could not create P2P Invitation Sent dialog with null or empty" + + " device name." + + " id=" + dialogId + + " deviceName=" + deviceName + + " displayPin=" + displayPin); + } + return null; + } + + final View textEntryView = LayoutInflater.from(this) + .inflate(getLayoutId("wifi_p2p_dialog"), null); + ViewGroup group = textEntryView.findViewById(getViewId("info")); + addRowToP2pDialog(group, getStringId("wifi_p2p_to_message"), deviceName); + + if (displayPin != null) { + addRowToP2pDialog(group, getStringId("wifi_p2p_show_pin_message"), displayPin); + } + + AlertDialog dialog = new AlertDialog.Builder(this) + .setTitle(getString(getStringId("wifi_p2p_invitation_sent_title"))) + .setView(textEntryView) + .setPositiveButton(getStringId("ok"), (dialogPositive, which) -> { + // No-op + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "P2P Invitation Sent Dialog id=" + dialogId + + " accepted."); + } + }) + .create(); + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "Created P2P Invitation Sent dialog." + + " id=" + dialogId + + " deviceName=" + deviceName + + " displayPin=" + displayPin); + } + return dialog; + } + + /** * Returns a P2P Invitation Received Dialog for the given Intent, or {@code null} if no Dialog * could be created. */ diff --git a/framework/java/android/net/wifi/WifiManager.java b/framework/java/android/net/wifi/WifiManager.java index f383d58d00..0f140eb1df 100644 --- a/framework/java/android/net/wifi/WifiManager.java +++ b/framework/java/android/net/wifi/WifiManager.java @@ -9303,16 +9303,24 @@ public class WifiManager { public static final int DIALOG_TYPE_SIMPLE = 1; /** + * DialogType for a P2P Invitation Sent dialog. + * @see {@link com.android.server.wifi.WifiDialogManager#createP2pInvitationSentDialog} + * @hide + */ + public static final int DIALOG_TYPE_P2P_INVITATION_SENT = 2; + + /** * DialogType for a P2P Invitation Received dialog. * @see {@link com.android.server.wifi.WifiDialogManager#createP2pInvitationReceivedDialog} * @hide */ - public static final int DIALOG_TYPE_P2P_INVITATION_RECEIVED = 2; + public static final int DIALOG_TYPE_P2P_INVITATION_RECEIVED = 3; /** @hide */ @IntDef(prefix = { "DIALOG_TYPE_" }, value = { DIALOG_TYPE_UNKNOWN, DIALOG_TYPE_SIMPLE, + DIALOG_TYPE_P2P_INVITATION_SENT, DIALOG_TYPE_P2P_INVITATION_RECEIVED, }) @Retention(RetentionPolicy.SOURCE) diff --git a/service/java/com/android/server/wifi/WifiDialogManager.java b/service/java/com/android/server/wifi/WifiDialogManager.java index 4cb72eaaea..accd9412f2 100644 --- a/service/java/com/android/server/wifi/WifiDialogManager.java +++ b/service/java/com/android/server/wifi/WifiDialogManager.java @@ -623,4 +623,40 @@ public class WifiDialogManager { ((P2pInvitationReceivedDialogHandle) internalHandle).notifyOnDeclined(); } } + + private class P2pInvitationSentDialogHandle extends DialogHandleInternal { + P2pInvitationSentDialogHandle( + final @NonNull String deviceName, + final @NonNull String displayPin) throws IllegalArgumentException { + super(getBaseLaunchIntent(WifiManager.DIALOG_TYPE_P2P_INVITATION_SENT) + .putExtra(WifiManager.EXTRA_P2P_DEVICE_NAME, deviceName) + .putExtra(WifiManager.EXTRA_P2P_DISPLAY_PIN, displayPin)); + if (deviceName == null) { + throw new IllegalArgumentException("Device name cannot be null!"); + } + if (displayPin == null) { + throw new IllegalArgumentException("Display PIN cannot be null!"); + } + } + } + + /** + * Creates a P2P Invitation Sent dialog. + * + * @param deviceName Name of the device the invitation was sent to. + * @param displayPin display PIN + * @return DialogHandle Handle for the dialog, or {@code null} if no dialog could + * be created. + */ + @AnyThread + public DialogHandle createP2pInvitationSentDialog( + @NonNull String deviceName, + @Nullable String displayPin) { + try { + return new DialogHandle(new P2pInvitationSentDialogHandle(deviceName, displayPin)); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Could not create DialogHandle for P2P Invitation Sent dialog: " + e); + return null; + } + } } diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java index 1eaff836f1..34693f0c45 100644 --- a/service/java/com/android/server/wifi/WifiShellCommand.java +++ b/service/java/com/android/server/wifi/WifiShellCommand.java @@ -1269,6 +1269,11 @@ public class WifiShellCommand extends BasicShellCommandHandler { } } return 0; + case "launch-dialog-p2p-invitation-sent": + mWifiDialogManager.createP2pInvitationSentDialog( + getNextArgRequired(), getNextArgRequired()).launchDialog(); + pw.println("Launched dialog."); + return 0; case "launch-dialog-p2p-invitation-received": { String deviceName = getNextArgRequired(); boolean isPinRequested = false; @@ -2110,6 +2115,10 @@ public class WifiShellCommand extends BasicShellCommandHandler { pw.println(" -n - Negative Button Text"); pw.println(" -x - Neutral Button Text"); pw.println(" -c - Optional timeout in milliseconds"); + pw.println(" launch-dialog-p2p-invitation-sent <device_name> <pin>"); + pw.println(" Launches a P2P Invitation Sent dialog."); + pw.println(" <device_name> - Name of the device the invitation was sent to"); + pw.println(" <pin> - PIN for the invited device to input"); pw.println(" launch-dialog-p2p-invitation-received <device_name> [-p] [-d <pin>] " + "[-i <display_id>] [-c <timeout_millis>]"); pw.println(" Launches a P2P Invitation Received dialog and waits up to 15 seconds to" diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index f4e88c1f2b..8ba2ee4272 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -4358,26 +4358,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { extras); return; } - - Resources r = mContext.getResources(); - - final View textEntryView = LayoutInflater.from(mContext).cloneInContext(mContext) - .inflate(R.layout.wifi_p2p_dialog, null); - - ViewGroup group = (ViewGroup) textEntryView.findViewById(R.id.info); - addRowToDialog(group, R.string.wifi_p2p_to_message, getDeviceName(peerAddress)); - addRowToDialog(group, R.string.wifi_p2p_show_pin_message, pin); - - AlertDialog dialog = mFrameworkFacade.makeAlertDialogBuilder(mContext) - .setTitle(r.getString(R.string.wifi_p2p_invitation_sent_title)) - .setView(textEntryView) - .setPositiveButton(r.getString(R.string.ok), null) - .create(); - dialog.setCanceledOnTouchOutside(false); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - dialog.getWindow().addSystemFlags( - WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS); - dialog.show(); + WifiDialogManager.DialogHandle dialogHandle = mWifiInjector.getWifiDialogManager() + .createP2pInvitationSentDialog(getDeviceName(peerAddress), pin); + if (dialogHandle == null) { + loge("Could not create invitation sent dialog!"); + return; + } + dialogHandle.launchDialog(); } private void notifyP2pProvDiscShowPinRequest(String pin, String peerAddress) { diff --git a/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java index bec1002b5c..c65132a88e 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java @@ -1121,6 +1121,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { when(mWifiInjector.getWifiDialogManager()).thenReturn(mWifiDialogManager); when(mWifiDialogManager.createP2pInvitationReceivedDialog(any(), anyBoolean(), any(), anyInt(), any(), any())).thenReturn(mDialogHandle); + when(mWifiDialogManager.createP2pInvitationSentDialog(any(), any())) + .thenReturn(mDialogHandle); when(mWifiInjector.getClock()).thenReturn(mClock); when(mWifiInjector.getInterfaceConflictManager()).thenReturn(mInterfaceConflictManager); // enable all permissions, disable specific permissions in tests @@ -5094,6 +5096,33 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { } /** + * Verify that a P2P_PROV_DISC_SHOW_PIN_EVENT for config method DISPLAY triggers an invitation + * sent dialog with the correct PIN. + */ + @Test + public void testProvisionDiscoveryShowPinEventLaunchesInvitationSentDialog() throws Exception { + when(mWifiInfo.getNetworkId()).thenReturn(WifiConfiguration.INVALID_NETWORK_ID); + when(mWifiInfo.getFrequency()).thenReturn(2412); + mTestWifiP2pPeerConfig.wps.setup = WpsInfo.DISPLAY; + forceP2pEnabled(mClient1); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); + + mockEnterProvisionDiscoveryState(); + + WifiP2pProvDiscEvent pdEvent = new WifiP2pProvDiscEvent(); + pdEvent.device = mTestWifiP2pDevice; + pdEvent.pin = "pin"; + sendSimpleMsg(null, + WifiP2pMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT, + pdEvent); + + verify(mWifiNative).p2pConnect(any(), anyBoolean()); + verify(mWifiDialogManager).createP2pInvitationSentDialog( + pdEvent.device.deviceName, pdEvent.pin); + verify(mDialogHandle).launchDialog(); + } + + /** * Verify the group owner intent value is selected correctly when 2.4GHz STA connection. */ @Test |