Upload basic UI files for Wi-Fi DPP Settings development.

WifiDppQrCodeScannerActivity is the activity for user to scan
QR code and add device to a saved network.

Bug: 118797380
Test: manual
Change-Id: If2c8c5ba1620e5584fb47ba7b0ea2bc2d7acb641
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1bd458a..2d2f584 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3018,6 +3018,9 @@
                 <action android:name="android.content.action.SETTINGS_HOMEPAGE_DATA"/>
             </intent-filter>
         </provider>
+
+        <activity
+            android:name=".wifi.dpp.WifiDppConfiguratorActivity"/>
         <!-- This is the longest AndroidManifest.xml ever. -->
     </application>
 </manifest>
diff --git a/res/layout/wifi_dpp_activity.xml b/res/layout/wifi_dpp_activity.xml
new file mode 100644
index 0000000..a833dcc
--- /dev/null
+++ b/res/layout/wifi_dpp_activity.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:src="@drawable/ic_wifi_signal_4"
+        android:layout_gravity="center"/>
+
+    <LinearLayout
+        android:id="@+id/fragment_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"/>
+
+</LinearLayout>
diff --git a/res/layout/wifi_dpp_fragment_footer.xml b/res/layout/wifi_dpp_fragment_footer.xml
new file mode 100644
index 0000000..98c6485
--- /dev/null
+++ b/res/layout/wifi_dpp_fragment_footer.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal">
+
+    <Button
+        android:id="@+id/button_left"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|start"
+        android:text="left"
+        style="?android:attr/borderlessButtonStyle"/>
+
+    <Space
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_weight="1"/>
+
+    <Button
+        android:id="@+id/button_right"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|end"
+        android:text="right"/>
+
+</LinearLayout>
diff --git a/res/layout/wifi_dpp_fragment_header.xml b/res/layout/wifi_dpp_fragment_header.xml
new file mode 100644
index 0000000..99b246f
--- /dev/null
+++ b/res/layout/wifi_dpp_fragment_header.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+
+    <TextView android:id="@+id/title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"/>
+
+    <TextView android:id="@+id/description"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"/>
+
+</LinearLayout>
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 0000000..130bb6d
--- /dev/null
+++ b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include layout="@layout/wifi_dpp_fragment_header"/>
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+        <SurfaceView
+            android:id="@+id/preview_view"
+            android:layout_width="320dp"
+            android:layout_height="426dp"
+            android:layout_gravity="center"/>
+        <ImageView
+            android:id="@+id/decorate_view"
+            android:layout_width="320dp"
+            android:layout_height="426dp"
+            android:layout_gravity="center"/>
+    </FrameLayout>
+
+    <TextView android:id="@+id/error_message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"/>
+
+    <include layout="@layout/wifi_dpp_fragment_footer"
+        android:gravity="center|bottom"/>
+
+</LinearLayout>
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 151ea14..e93e06f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2050,6 +2050,10 @@
     <string name="wifi_ip_settings">IP settings</string>
     <!-- Label for the spinner to show Wifi MAC randomization [CHAR LIMIT=25] -->
     <string name="wifi_privacy_settings">Privacy</string>
+    <!-- Title for the fragment to add a device into the wifi network [CHAR LIMIT=50]  -->
+    <string name="wifi_dpp_add_device_to_network">Add a device to this network</string>
+    <!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=120] -->
+    <string name="wifi_dpp_center_qr_code">Center the device\u2019s QR code below to add device to \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
     <!-- Label for the check box to share a network with other users on the same device -->
     <string name="wifi_shared">Share with other device users</string>
     <!-- Hint for unchanged fields -->
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 0000000..bccb53a
--- /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 0000000..004cb18
--- /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 0000000..0ee8434
--- /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 0000000..d101c92
--- /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<WifiDppConfiguratorActivity> 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 0000000..58fa61f
--- /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<WifiDppConfiguratorActivity> 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);
+    }
+}