diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1bd458a66e8..2d2f5843cf3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3018,6 +3018,9 @@
+
+
diff --git a/res/layout/wifi_dpp_activity.xml b/res/layout/wifi_dpp_activity.xml
new file mode 100644
index 00000000000..a833dcc757c
--- /dev/null
+++ b/res/layout/wifi_dpp_activity.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/wifi_dpp_fragment_footer.xml b/res/layout/wifi_dpp_fragment_footer.xml
new file mode 100644
index 00000000000..98c6485236b
--- /dev/null
+++ b/res/layout/wifi_dpp_fragment_footer.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/wifi_dpp_fragment_header.xml b/res/layout/wifi_dpp_fragment_header.xml
new file mode 100644
index 00000000000..99b246fe683
--- /dev/null
+++ b/res/layout/wifi_dpp_fragment_header.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/wifi_dpp_qrcode_scanner_fragment.xml b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
new file mode 100644
index 00000000000..130bb6d847b
--- /dev/null
+++ b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 151ea149952..e93e06f87af 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2050,6 +2050,10 @@
IP settings
Privacy
+
+ Add a device to this network
+
+ Center the device\u2019s QR code below to add device to \u201c%1$s\u201d
Share with other device users
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
new file mode 100644
index 00000000000..bccb53aa670
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 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 android.app.ActionBar;
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+
+import com.android.internal.logging.nano.MetricsProto;
+
+import com.android.settings.core.InstrumentedActivity;
+import com.android.settings.R;
+
+public class WifiDppConfiguratorActivity extends InstrumentedActivity {
+ private static final String TAG = "WifiDppConfiguratorActivity";
+
+ private FragmentManager mFragmentManager;
+ private FragmentTransaction mFragmentTransaction;
+
+ public static final String EXTRA_LAUNCH_MODE =
+ "com.android.settings.wifi.dpp.EXTRA_LAUNCH_MODE";
+ public static final String EXTRA_SSID = "com.android.settings.wifi.dpp.EXTRA_SSID";
+
+ public enum LaunchMode {
+ LAUNCH_MODE_QR_CODE_SCANNER(1),
+ LAUNCH_MODE_QR_CODE_GENERATOR(2),
+ LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK(3),
+ LAUNCH_MODE_NOT_DEFINED(-1);
+
+ private int mMode;
+
+ LaunchMode(int mode) {
+ this.mMode = mode;
+ }
+
+ public int getMode() {
+ return mMode;
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO:Should we use a new metrics category for Wi-Fi DPP?
+ return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.wifi_dpp_activity);
+
+ // Hide action bar
+ ActionBar action = getActionBar();
+ if (action != null) {
+ action.hide();
+ }
+
+ mFragmentManager = getSupportFragmentManager();
+ mFragmentTransaction = getSupportFragmentManager().beginTransaction();
+
+ final int launchMode = getIntent().getIntExtra(EXTRA_LAUNCH_MODE,
+ LaunchMode.LAUNCH_MODE_NOT_DEFINED.getMode());
+ if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode()) {
+ WifiDppQrCodeScannerFragment scanFragment = new WifiDppQrCodeScannerFragment();
+ mFragmentTransaction.add(R.id.fragment_container, scanFragment);
+ mFragmentTransaction.commit();
+ } else {
+ Log.e(TAG, "Launch with an invalid mode extra");
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ }
+ }
+}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java
new file mode 100644
index 00000000000..004cb18500a
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2018 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 android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.android.internal.logging.nano.MetricsProto;
+
+import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.R;
+
+public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
+ private TextView mTitle;
+ private TextView mDescription;
+ private SurfaceView mPreviewView;
+ private TextView mErrorMessage; //optional, view used to surface connectivity errors to the user
+ private Button mButtonLeft;
+ private Button mButtonRight;
+
+ abstract protected int getLayout();
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO:Should we use a new metrics category for Wi-Fi DPP?
+ return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
+ }
+
+ @Override
+ public final void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public final View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(getLayout(), container, false);
+ initView(view);
+ return view;
+ }
+
+ private void initView(View view) {
+ mTitle = view.findViewById(R.id.title);
+ mDescription = view.findViewById(R.id.description);
+ mPreviewView = view.findViewById(R.id.preview_view);
+ mErrorMessage = view.findViewById(R.id.error_message);
+ mButtonLeft = view.findViewById(R.id.button_left);
+ mButtonRight = view.findViewById(R.id.button_right);
+ }
+
+ protected void setTitle(String title) {
+ mTitle.setText(title);
+ }
+
+ protected void setDescription(String description) {
+ mDescription.setText(description);
+ }
+
+ protected void setErrorMessage(String errorMessage) {
+ if (mErrorMessage != null) {
+ mErrorMessage.setText(errorMessage);
+ }
+ }
+
+ protected void setLeftButtonText(String text) {
+ mButtonLeft.setText(text);
+ }
+
+ protected void setRightButtonText(String text) {
+ mButtonRight.setText(text);
+ }
+
+ protected void hideLeftButton() {
+ mButtonLeft.setVisibility(View.INVISIBLE);
+ }
+
+ protected void hideRightButton() {
+ mButtonRight.setVisibility(View.INVISIBLE);
+ }
+
+ protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
+ mButtonLeft.setOnClickListener(listener);
+ }
+
+ protected void setRightButtonOnClickListener(View.OnClickListener listener) {
+ mButtonRight.setOnClickListener(listener);
+ }
+}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
new file mode 100644
index 00000000000..0ee8434e6de
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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 android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import android.view.ViewGroup;
+import com.android.settings.R;
+
+public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment {
+ @Override
+ protected int getLayout() {
+ return R.layout.wifi_dpp_qrcode_scanner_fragment;
+ }
+
+ @Override
+ public void onActivityCreated (Bundle savedInstanceState) {
+ super.onActivityCreated (savedInstanceState);
+
+ setTitle(getString(R.string.wifi_dpp_add_device_to_network));
+
+ String ssid = "";
+ Intent intent = getActivity().getIntent();
+ if (intent != null)
+ ssid = intent.getStringExtra(WifiDppConfiguratorActivity.EXTRA_SSID);
+ String description = getString(R.string.wifi_dpp_center_qr_code, ssid);
+ setDescription(description);
+
+ hideRightButton();
+
+ setLeftButtonText(getString(android.R.string.cancel));
+
+ setLeftButtonOnClickListener((view) -> {
+ getActivity().setResult(Activity.RESULT_CANCELED);
+ getActivity().finish();});
+ }
+}
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
new file mode 100644
index 00000000000..d101c923c2f
--- /dev/null
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2018 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 com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class WifiDppConfiguratorActivityTest {
+ @Rule
+ public final ActivityTestRule mActivityRule =
+ new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
+
+ @Test
+ public void testLaunchModeQrCodeScanner_shouldNotAutoFinish() {
+ Intent intent = new Intent();
+ intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
+ WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
+ mActivityRule.launchActivity(intent);
+
+ assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
+ mActivityRule.finishActivity();
+ }
+
+ @Test
+ public void testNoLaunchMode_shouldFinishActivityWithResultCodeCanceled() {
+ // If we do not specify launch mode, the activity will finish itself right away
+ Intent intent = new Intent();
+ mActivityRule.launchActivity(intent);
+
+ assertThat(mActivityRule.getActivityResult().getResultCode()).
+ isEqualTo(Activity.RESULT_CANCELED);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
new file mode 100644
index 00000000000..58fa61fcf6f
--- /dev/null
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static android.support.test.espresso.Espresso.onView;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class WifiDppQrCodeScannerFragmentTest {
+ @Rule
+ public final ActivityTestRule mActivityRule =
+ new ActivityTestRule<>(WifiDppConfiguratorActivity.class, true);
+
+ @Before
+ public void setUp() {
+ Intent intent = new Intent();
+ intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
+ WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
+ mActivityRule.launchActivity(intent);
+ }
+
+ @Test
+ public void testLeftButton_shouldFinishActivityWithResultCodeCanceled() {
+ onView(withText("Cancel")).perform(click());
+ assertThat(mActivityRule.getActivityResult().getResultCode()).
+ isEqualTo(Activity.RESULT_CANCELED);
+ }
+}