Created a new activity in settings App.
This activity displays a WifiDppQrCodeGeneratorFragment after unlocking. This will be used by the new "Share Wi-Fi" button in quick settings InternetDialog.
Bug: 294487249
Test: atest com.android.settings.wifi.dpp.WifiDppConfiguratorAuthActivityTest
Change-Id: I58b61f597db67082f23a1acb4fae5a4556238584
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 79a7171..2c61ec6 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4681,6 +4681,16 @@
</activity>
<activity
+ android:name=".wifi.dpp.WifiDppConfiguratorAuthActivity"
+ android:theme="@style/Transparent"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.settings.WIFI_DPP_CONFIGURATOR_AUTH_QR_CODE_GENERATOR"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+
+ <activity
android:name=".wifi.dpp.WifiDppEnrolleeActivity"
android:exported="true">
<intent-filter>
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivity.java
new file mode 100644
index 0000000..aa77dc1
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivity.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import static android.content.Intent.ACTION_CLOSE_SYSTEM_DIALOGS;
+import static android.content.Intent.FLAG_RECEIVER_FOREGROUND;
+
+import android.app.Activity;
+import android.app.KeyguardManager;
+import android.app.settings.SettingsEnums;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.WindowManager;
+
+import androidx.activity.result.ActivityResult;
+import androidx.activity.result.contract.ActivityResultContracts;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+import com.android.settings.core.InstrumentedActivity;
+
+/**
+ * Sharing a Wi-Fi network by QR code after unlocking. Used by {@code InternetDialog} in QS.
+ */
+public class WifiDppConfiguratorAuthActivity extends InstrumentedActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // This is a transparent activity, disable the dim.
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+ Intent authIntent = getSystemService(KeyguardManager.class)
+ .createConfirmDeviceCredentialIntent(
+ getText(R.string.wifi_dpp_lockscreen_title), null, getUserId());
+ if (authIntent == null) {
+ startQrCodeActivity();
+ finish();
+ } else {
+ registerForActivityResult(
+ new ActivityResultContracts.StartActivityForResult(),
+ this::onAuthResult).launch(authIntent);
+ }
+ }
+
+ @VisibleForTesting
+ void onAuthResult(ActivityResult result) {
+ if (result.getResultCode() == Activity.RESULT_OK) {
+ startQrCodeActivity();
+ }
+ finish();
+ }
+
+ private void startQrCodeActivity() {
+ // Close quick settings shade
+ sendBroadcast(
+ new Intent(ACTION_CLOSE_SYSTEM_DIALOGS).setFlags(FLAG_RECEIVER_FOREGROUND));
+ Intent qrCodeIntent = new Intent();
+ qrCodeIntent.setAction(
+ WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
+ qrCodeIntent.putExtras(getIntent());
+ startActivity(qrCodeIntent);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR;
+ }
+}
diff --git a/tests/componenttests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivityTest.java b/tests/componenttests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivityTest.java
new file mode 100644
index 0000000..94b9369
--- /dev/null
+++ b/tests/componenttests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorAuthActivityTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import static android.app.Activity.RESULT_OK;
+
+import static androidx.test.espresso.intent.Intents.intended;
+import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.hamcrest.Matchers.equalTo;
+
+import android.app.KeyguardManager;
+
+import androidx.activity.result.ActivityResult;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.espresso.intent.Intents;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class WifiDppConfiguratorAuthActivityTest {
+
+ @Before
+ public void setup() {
+ Intents.init();
+ }
+
+ @After
+ public void teardown() throws Exception {
+ Intents.release();
+ }
+
+ @Test
+ public void launchActivity_sendAuthIntent() {
+ ActivityScenario<WifiDppConfiguratorAuthActivity> activityScenario =
+ ActivityScenario.launch(WifiDppConfiguratorAuthActivity.class);
+ assertThat(activityScenario).isNotNull();
+ intended(hasAction(equalTo(KeyguardManager.ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER)));
+ }
+
+ @Test
+ public void launchActivity_sendQrCodeIntent() {
+ ActivityScenario.launch(WifiDppConfiguratorAuthActivity.class).onActivity(activity ->
+ activity.onAuthResult(new ActivityResult(RESULT_OK, /* data= */ null))
+ );
+ intended(hasAction(
+ equalTo(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR)));
+ }
+
+ @Test
+ public void launchActivity_shouldFinish() {
+ ActivityScenario.launch(WifiDppConfiguratorAuthActivity.class).onActivity(activity -> {
+ activity.onAuthResult(new ActivityResult(RESULT_OK, /* data= */ null));
+ assertThat(activity.isFinishing()).isTrue();
+ });
+ }
+}