NfcProvisioning: Add a new sample

This sample demonstrates NFC provisioning feature of Android for Work.
If installed on a programmer device, the app can send an NFC bump to a
client device to set it up as an owned device.

Change-Id: Iee629b531a3cbe6871d5bce117f56c22ba7356fa
diff --git a/admin/NfcProvisioning/Application/.gitignore b/admin/NfcProvisioning/Application/.gitignore
new file mode 100644
index 0000000..1bac3a5
--- /dev/null
+++ b/admin/NfcProvisioning/Application/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 2015 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.
+src/template/
+src/common/
+build.gradle
diff --git a/admin/NfcProvisioning/Application/README-fragmentview.txt b/admin/NfcProvisioning/Application/README-fragmentview.txt
new file mode 100644
index 0000000..b346a5f
--- /dev/null
+++ b/admin/NfcProvisioning/Application/README-fragmentview.txt
@@ -0,0 +1,37 @@
+<!--
+        Copyright 2015 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.
+-->
+
+Steps to implement FragmentView template:
+-in template-params.xml.ftl:
+    -add the following line to common imports
+        <common src="activities"/>
+
+-Add a Fragment to show behavior.  In your MainActivity.java class, it will reference a Fragment
+ called (yourProjectName)Fragment.java.  Create that file in your project, using the "main" source
+ folder instead of "common" or "templates".
+   For instance, if your package name is com.example.foo, create the file
+   src/main/java/com/example/foo/FooFragment.java
+
+
+-Within this fragment, make sure that the onCreate method has the line
+ "setHasOptionsMenu(true);", to enable the fragment to handle menu events.
+
+-In order to override menu events, override onOptionsItemSelected.
+
+-refer to sampleSamples/fragmentViewSample for a reference implementation of a
+project built on this template.
+
+
diff --git a/admin/NfcProvisioning/Application/README-singleview.txt b/admin/NfcProvisioning/Application/README-singleview.txt
new file mode 100644
index 0000000..57fa134
--- /dev/null
+++ b/admin/NfcProvisioning/Application/README-singleview.txt
@@ -0,0 +1,47 @@
+<#--
+        Copyright 2015 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.
+-->
+
+Steps to implement SingleView template:
+-in template-params.xml.ftl:
+    -add the following line to common imports
+        <common src="activities"/>
+
+    -add a string for the action button's text using the element name "sample_action".
+    This element should be a child of <strings>:
+        <strings>
+        ...
+        <sample_action>ButtonText</sample_action>
+        ...
+        </strings>
+
+
+
+-Add a Fragment to handle behavior.  In your MainActivity.java class, it will reference a Fragment
+ called (yourProjectName)Fragment.java.  Create that file in your project, using the "main" source
+ folder instead of "common" or "templates".
+   For instance, if your package name is com.example.foo, create the file
+   src/main/java/com/example/foo/FooFragment.java
+
+
+-Within this fragment, make sure that the onCreate method has the line
+ "setHasOptionsMenu(true);", to enable the fragment to handle menu events.
+
+-In order to override menu events, override onOptionsItemSelected.
+
+-refer to sampleSamples/singleViewSample for a reference implementation of a
+project built on this template.
+
+
diff --git a/admin/NfcProvisioning/Application/proguard-project.txt b/admin/NfcProvisioning/Application/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/admin/NfcProvisioning/Application/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/admin/NfcProvisioning/Application/src/main/AndroidManifest.xml b/admin/NfcProvisioning/Application/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..1db70d7
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 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.
+-->
+<manifest
+    package="com.example.android.nfcprovisioning"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:versionCode="1"
+    android:versionName="1.0">
+
+    <uses-permission android:name="android.permission.NFC"/>
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme">
+
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name"
+            android:windowSoftInputMode="stateHidden">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/NfcProvisioningFragment.java b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/NfcProvisioningFragment.java
new file mode 100644
index 0000000..e3b14c6
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/NfcProvisioningFragment.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2015 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.example.android.nfcprovisioning;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+import android.nfc.NfcEvent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.LoaderManager;
+import android.support.v4.content.Loader;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Provides UI and logic for NFC provisioning.
+ * <p>
+ * This fragment creates an intent, which sends parameters to a second device via an Nfc bump. If
+ * the second device is factory reset, this will start provisioning the second device to set it up
+ * as an owned device.
+ * </p>
+ */
+public class NfcProvisioningFragment extends Fragment implements
+        NfcAdapter.CreateNdefMessageCallback,
+        TextWatcherWrapper.OnTextChangedListener,
+        LoaderManager.LoaderCallbacks<Map<String, String>> {
+
+    private static final int LOADER_PROVISIONING_VALUES = 1;
+
+    // View references
+    private EditText mEditPackageName;
+    private EditText mEditLocale;
+    private EditText mEditTimezone;
+    private EditText mEditWifiSsid;
+    private EditText mEditWifiSecurityType;
+    private EditText mEditWifiPassword;
+
+    // Values to be set via NFC bump
+    private Map<String, String> mProvisioningValues;
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+                             @Nullable Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.fragment_nfc_provisioning, container, false);
+    }
+
+    @Override
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+        // Retrieve view references
+        mEditPackageName = (EditText) view.findViewById(R.id.package_name);
+        mEditLocale = (EditText) view.findViewById(R.id.locale);
+        mEditTimezone = (EditText) view.findViewById(R.id.timezone);
+        mEditWifiSsid = (EditText) view.findViewById(R.id.wifi_ssid);
+        mEditWifiSecurityType = (EditText) view.findViewById(R.id.wifi_security_type);
+        mEditWifiPassword = (EditText) view.findViewById(R.id.wifi_password);
+        // Bind event handlers
+        mEditPackageName.addTextChangedListener(new TextWatcherWrapper(R.id.package_name, this));
+        mEditLocale.addTextChangedListener(new TextWatcherWrapper(R.id.locale, this));
+        mEditTimezone.addTextChangedListener(new TextWatcherWrapper(R.id.timezone, this));
+        mEditWifiSsid.addTextChangedListener(new TextWatcherWrapper(R.id.wifi_ssid, this));
+        mEditWifiSecurityType.addTextChangedListener(
+                new TextWatcherWrapper(R.id.wifi_security_type, this));
+        mEditWifiPassword.addTextChangedListener(new TextWatcherWrapper(R.id.wifi_password, this));
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        Activity activity = getActivity();
+        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
+        adapter.setNdefPushMessageCallback(this, activity);
+        getLoaderManager().initLoader(LOADER_PROVISIONING_VALUES, null, this);
+    }
+
+    @Override
+    public NdefMessage createNdefMessage(NfcEvent event) {
+        if (mProvisioningValues == null) {
+            return null;
+        }
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        Properties properties = new Properties();
+        // Store all the values into the Properties object
+        for (Map.Entry<String, String> e : mProvisioningValues.entrySet()) {
+            if (!TextUtils.isEmpty(e.getValue())) {
+                String value;
+                if (e.getKey().equals(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID)) {
+                    // Make sure to surround SSID with double quotes
+                    value = e.getValue();
+                    if (!value.startsWith("\"") || !value.endsWith("\"")) {
+                        value = "\"" + value + "\"";
+                    }
+                } else {
+                    value = e.getValue();
+                }
+                properties.put(e.getKey(), value);
+            }
+        }
+        try {
+            properties.store(stream, getString(R.string.nfc_comment));
+            NdefRecord record = NdefRecord.createMime(
+                    DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, stream.toByteArray());
+            return new NdefMessage(new NdefRecord[]{record});
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    @Override
+    public void onTextChanged(int id, String s) {
+        if (mProvisioningValues == null) {
+            return;
+        }
+        switch (id) {
+            case R.id.package_name:
+                mProvisioningValues.put(
+                        DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, s);
+                break;
+            case R.id.locale:
+                mProvisioningValues.put(DevicePolicyManager.EXTRA_PROVISIONING_LOCALE, s);
+                break;
+            case R.id.timezone:
+                mProvisioningValues.put(DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE, s);
+                break;
+            case R.id.wifi_ssid:
+                mProvisioningValues.put(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, s);
+                break;
+            case R.id.wifi_security_type:
+                mProvisioningValues.put(
+                        DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, s);
+                break;
+            case R.id.wifi_password:
+                mProvisioningValues.put(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD, s);
+                break;
+        }
+    }
+
+    @Override
+    public Loader<Map<String, String>> onCreateLoader(int id, Bundle args) {
+        if (id == LOADER_PROVISIONING_VALUES) {
+            return new ProvisioningValuesLoader(getActivity());
+        }
+        return null;
+    }
+
+    @Override
+    public void onLoadFinished(Loader<Map<String, String>> loader, Map<String, String> values) {
+        if (loader.getId() == LOADER_PROVISIONING_VALUES) {
+            mProvisioningValues = values;
+            mEditPackageName.setText(values.get(
+                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME));
+            mEditLocale.setText(values.get(DevicePolicyManager.EXTRA_PROVISIONING_LOCALE));
+            mEditTimezone.setText(values.get(DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE));
+            mEditWifiSsid.setText(values.get(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID));
+            mEditWifiSecurityType.setText(values.get(
+                    DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE));
+            mEditWifiPassword.setText(null);
+        }
+    }
+
+    @Override
+    public void onLoaderReset(Loader<Map<String, String>> loader) {
+        // Do nothing
+    }
+
+}
diff --git a/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/ProvisioningValuesLoader.java b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/ProvisioningValuesLoader.java
new file mode 100644
index 0000000..2203c30
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/ProvisioningValuesLoader.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2015 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.example.android.nfcprovisioning;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Environment;
+import android.support.v4.content.AsyncTaskLoader;
+
+import com.example.android.common.logger.Log;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+/**
+ * Loads default values for NFC provisioning.
+ * <p/>
+ * This loader first tries to load values from a config file in SD card. Then it fills in missing
+ * values using constants and settings on the programming device.
+ */
+public class ProvisioningValuesLoader extends AsyncTaskLoader<Map<String, String>> {
+
+    private static final String FILENAME = "nfcprovisioning.txt";
+    private static final String TAG = "LoadProvisioningValuesTask";
+
+    private Map<String, String> mValues;
+
+    public ProvisioningValuesLoader(Context context) {
+        super(context);
+    }
+
+    @Override
+    public Map<String, String> loadInBackground() {
+        HashMap<String, String> values = new HashMap<>();
+        loadFromDisk(values);
+        loadSystemValues(values);
+        return values;
+    }
+
+    @Override
+    public void deliverResult(Map<String, String> values) {
+        if (isReset()) {
+            return;
+        }
+        mValues = values;
+        super.deliverResult(values);
+    }
+
+    @Override
+    protected void onStartLoading() {
+        if (mValues != null) {
+            deliverResult(mValues);
+        }
+        if (takeContentChanged() || mValues == null) {
+            forceLoad();
+        }
+    }
+
+    @Override
+    protected void onStopLoading() {
+        cancelLoad();
+    }
+
+    @Override
+    protected void onReset() {
+        super.onReset();
+        onStopLoading();
+        mValues = null;
+    }
+
+    private void loadFromDisk(HashMap<String, String> values) {
+        File directory = Environment.getExternalStorageDirectory();
+        File file = new File(directory, FILENAME);
+        if (!file.exists()) {
+            return;
+        }
+        Log.d(TAG, "Loading the config file...");
+        try {
+            loadFromFile(values, file);
+        } catch (IOException e) {
+            e.printStackTrace();
+            Log.e(TAG, "Error loading data from " + file, e);
+        }
+    }
+
+    private void loadFromFile(HashMap<String, String> values, File file) throws IOException {
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new FileReader(file));
+            String line;
+            while (null != (line = reader.readLine())) {
+                if (line.startsWith("#")) {
+                    continue;
+                }
+                int position = line.indexOf("=");
+                if (position < 0) { // Not found
+                    continue;
+                }
+                String key = line.substring(0, position);
+                String value = line.substring(position + 1);
+                values.put(key, value);
+                Log.d(TAG, key + "=" + value);
+            }
+        } finally {
+            if (reader != null) {
+                reader.close();
+            }
+        }
+    }
+
+    private void loadSystemValues(HashMap<String, String> values) {
+        Context context = getContext();
+        putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
+                "com.example.android.deviceowner");
+        putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_LOCALE,
+                context.getResources().getConfiguration().locale.toString());
+        putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE,
+                TimeZone.getDefault().getID());
+        if (!values.containsKey(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID)) {
+            WifiManager wifiManager = (WifiManager) context
+                    .getSystemService(Activity.WIFI_SERVICE);
+            WifiInfo info = wifiManager.getConnectionInfo();
+            values.put(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, trimSsid(info.getSSID()));
+        }
+    }
+
+    /**
+     * {@link WifiInfo#getSSID} returns the WiFi SSID surrounded by double quotation marks. This
+     * method removes them if wifiSsid contains them.
+     */
+    private static String trimSsid(String wifiSsid) {
+        int head = wifiSsid.startsWith("\"") ? 1 : 0;
+        int tail = wifiSsid.endsWith("\"") ? 1 : 0;
+        return wifiSsid.substring(head, wifiSsid.length() - tail);
+    }
+
+    private static <Key, Value> void putIfMissing(HashMap<Key, Value> map, Key key, Value value) {
+        if (!map.containsKey(key)) {
+            map.put(key, value);
+        }
+    }
+
+}
diff --git a/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/TextWatcherWrapper.java b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/TextWatcherWrapper.java
new file mode 100644
index 0000000..d36936e
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/java/com/example/android/nfcprovisioning/TextWatcherWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 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.example.android.nfcprovisioning;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+
+/**
+ * This class wraps {@link TextWatcher} and delegates {@link TextWatcher#afterTextChanged} event to
+ * {@link OnTextChangedListener} while hiding all other unnecessary events.
+ */
+public class TextWatcherWrapper implements TextWatcher {
+
+    private final int mId;
+    private final OnTextChangedListener mListener;
+
+    public TextWatcherWrapper(int id, OnTextChangedListener listener) {
+        mId = id;
+        mListener = listener;
+    }
+
+    @Override
+    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+        // Ignore
+    }
+
+    @Override
+    public void onTextChanged(CharSequence s, int start, int before, int count) {
+        // Ignore
+    }
+
+    @Override
+    public void afterTextChanged(Editable s) {
+        mListener.onTextChanged(mId, s.toString());
+    }
+
+    public interface OnTextChangedListener {
+        public void onTextChanged(int id, String s);
+    }
+
+}
diff --git a/admin/NfcProvisioning/Application/src/main/res/drawable-hdpi/ic_launcher.png b/admin/NfcProvisioning/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..638a88d
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/admin/NfcProvisioning/Application/src/main/res/drawable-mdpi/ic_launcher.png b/admin/NfcProvisioning/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..cd128c9
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/admin/NfcProvisioning/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/admin/NfcProvisioning/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..824541a
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/admin/NfcProvisioning/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/admin/NfcProvisioning/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..5fe9f2e
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/admin/NfcProvisioning/Application/src/main/res/layout/fragment_nfc_provisioning.xml b/admin/NfcProvisioning/Application/src/main/res/layout/fragment_nfc_provisioning.xml
new file mode 100644
index 0000000..ee79e7a
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/layout/fragment_nfc_provisioning.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright 2015 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.
+-->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:padding="@dimen/margin_small">
+
+        <EditText
+            android:id="@+id/package_name"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_package_name"
+            android:inputType="textNoSuggestions"/>
+
+        <EditText
+            android:id="@+id/locale"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_locale"
+            android:inputType="textNoSuggestions"/>
+
+        <EditText
+            android:id="@+id/timezone"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_timezone"
+            android:inputType="textNoSuggestions"/>
+
+        <EditText
+            android:id="@+id/wifi_ssid"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_wifi_ssid"
+            android:inputType="textNoSuggestions"/>
+
+        <EditText
+            android:id="@+id/wifi_security_type"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_wifi_security_type"
+            android:inputType="textNoSuggestions"/>
+
+        <EditText
+            android:id="@+id/wifi_password"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="@dimen/margin_small"
+            android:hint="@string/hint_wifi_password"
+            android:inputType="textPassword"/>
+
+    </LinearLayout>
+
+</ScrollView>
diff --git a/admin/NfcProvisioning/Application/src/main/res/values/strings.xml b/admin/NfcProvisioning/Application/src/main/res/values/strings.xml
new file mode 100644
index 0000000..67de389
--- /dev/null
+++ b/admin/NfcProvisioning/Application/src/main/res/values/strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright 2015 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.
+-->
+<resources>
+
+    <string name="nfc_comment">NFC provisioning sample</string>
+
+    <string name="hint_package_name">Package name of device owner</string>
+    <string name="hint_locale">Locale</string>
+    <string name="hint_timezone">Timezone</string>
+    <string name="hint_wifi_ssid">WiFi SSID</string>
+    <string name="hint_wifi_security_type">WiFi security type</string>
+    <string name="hint_wifi_password">WiFi password</string>
+
+</resources>
diff --git a/admin/NfcProvisioning/Application/tests/src/com/example/android/nfcprovisioning/tests/SampleTests.java b/admin/NfcProvisioning/Application/tests/src/com/example/android/nfcprovisioning/tests/SampleTests.java
new file mode 100644
index 0000000..57876db
--- /dev/null
+++ b/admin/NfcProvisioning/Application/tests/src/com/example/android/nfcprovisioning/tests/SampleTests.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 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.example.android.nfcprovisioning.tests;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.EditText;
+
+import com.example.android.nfcprovisioning.MainActivity;
+import com.example.android.nfcprovisioning.NfcProvisioningFragment;
+import com.example.android.nfcprovisioning.R;
+
+/**
+ * Tests for NfcProvisioning sample.
+ */
+public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> {
+
+    private MainActivity mTestActivity;
+    private NfcProvisioningFragment mTestFragment;
+
+    public SampleTests() {
+        super(MainActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // Starts the activity under test using the default Intent with:
+        // action = {@link Intent#ACTION_MAIN}
+        // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
+        // All other fields are null or empty.
+        mTestActivity = getActivity();
+        mTestFragment = (NfcProvisioningFragment)
+                mTestActivity.getSupportFragmentManager().getFragments().get(1);
+    }
+
+    /**
+     * Test if the test fixture has been set up correctly.
+     */
+    public void testPreconditions() {
+        //Try to add a message to add context to your assertions. These messages will be shown if
+        //a tests fails and make it easy to understand why a test failed
+        assertNotNull("mTestActivity is null", mTestActivity);
+        assertNotNull("mTestFragment is null", mTestFragment);
+    }
+
+    public void testEditTexts() {
+        View view = mTestFragment.getView();
+        assertNotNull(view);
+        // Check that we have all the EditTexts on the Fragment
+        EditText locale = (EditText) view.findViewById(R.id.locale);
+        assertNotNull(locale);
+        EditText timezone = (EditText) view.findViewById(R.id.timezone);
+        assertNotNull(timezone);
+        EditText wifiSsid = (EditText) view.findViewById(R.id.wifi_ssid);
+        assertNotNull(wifiSsid);
+        EditText wifiPassword = (EditText) view.findViewById(R.id.wifi_password);
+        assertNotNull(wifiPassword);
+        // These EditTexts should be filled with some default values
+        assertFalse(TextUtils.isEmpty(locale.getText().toString()));
+        assertFalse(TextUtils.isEmpty(timezone.getText().toString()));
+    }
+
+}
diff --git a/admin/NfcProvisioning/build.gradle b/admin/NfcProvisioning/build.gradle
new file mode 100644
index 0000000..2b8d1ef
--- /dev/null
+++ b/admin/NfcProvisioning/build.gradle
@@ -0,0 +1,11 @@
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+  pathToBuild "../../../../build"
+  pathToSamplesCommon "../../common"
+}
+apply from: "../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/admin/NfcProvisioning/buildSrc/build.gradle b/admin/NfcProvisioning/buildSrc/build.gradle
new file mode 100644
index 0000000..8c294c2
--- /dev/null
+++ b/admin/NfcProvisioning/buildSrc/build.gradle
@@ -0,0 +1,15 @@
+repositories {
+    mavenCentral()
+}
+dependencies {
+    compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+    main {
+        groovy {
+            srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy")
+        }
+    }
+}
+
diff --git a/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.jar b/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..8c0fb64
--- /dev/null
+++ b/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.properties b/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..23e8e21
--- /dev/null
+++ b/admin/NfcProvisioning/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Jan 05 15:04:16 JST 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/admin/NfcProvisioning/gradlew b/admin/NfcProvisioning/gradlew
new file mode 100755
index 0000000..91a7e26
--- /dev/null
+++ b/admin/NfcProvisioning/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/admin/NfcProvisioning/gradlew.bat b/admin/NfcProvisioning/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/admin/NfcProvisioning/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off

+@rem ##########################################################################

+@rem

+@rem  Gradle startup script for Windows

+@rem

+@rem ##########################################################################

+

+@rem Set local scope for the variables with windows NT shell

+if "%OS%"=="Windows_NT" setlocal

+

+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.

+set DEFAULT_JVM_OPTS=

+

+set DIRNAME=%~dp0

+if "%DIRNAME%" == "" set DIRNAME=.

+set APP_BASE_NAME=%~n0

+set APP_HOME=%DIRNAME%

+

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

+

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:init

+@rem Get command-line arguments, handling Windowz variants

+

+if not "%OS%" == "Windows_NT" goto win9xME_args

+if "%@eval[2+2]" == "4" goto 4NT_args

+

+:win9xME_args

+@rem Slurp the command line arguments.

+set CMD_LINE_ARGS=

+set _SKIP=2

+

+:win9xME_args_slurp

+if "x%~1" == "x" goto execute

+

+set CMD_LINE_ARGS=%*

+goto execute

+

+:4NT_args

+@rem Get arguments from the 4NT Shell from JP Software

+set CMD_LINE_ARGS=%$

+

+:execute

+@rem Setup the command line

+

+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

+

+@rem Execute Gradle

+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

+

+:end

+@rem End local scope for the variables with windows NT shell

+if "%ERRORLEVEL%"=="0" goto mainEnd

+

+:fail

+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of

+rem the _cmd.exe /c_ return code!

+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1

+exit /b 1

+

+:mainEnd

+if "%OS%"=="Windows_NT" endlocal

+

+:omega

diff --git a/admin/NfcProvisioning/nfcprovisioning.txt b/admin/NfcProvisioning/nfcprovisioning.txt
new file mode 100644
index 0000000..0bbf926
--- /dev/null
+++ b/admin/NfcProvisioning/nfcprovisioning.txt
@@ -0,0 +1,7 @@
+# Sample configuration file for NfcProvisioning
+# Place this file in the SD card:
+#   $ adb push nfcprovisioning.txt /sdcard/
+
+android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME=packagename.of.your.deviceowner
+android.app.extra.PROVISIONING_LOCALE=en_GB
+android.app.extra.PROVISIONING_TIME_ZONE=America/New_York
diff --git a/admin/NfcProvisioning/screenshots/1-main.png b/admin/NfcProvisioning/screenshots/1-main.png
new file mode 100644
index 0000000..031742e
--- /dev/null
+++ b/admin/NfcProvisioning/screenshots/1-main.png
Binary files differ
diff --git a/admin/NfcProvisioning/screenshots/icon-web.png b/admin/NfcProvisioning/screenshots/icon-web.png
new file mode 100644
index 0000000..3570fee
--- /dev/null
+++ b/admin/NfcProvisioning/screenshots/icon-web.png
Binary files differ
diff --git a/admin/NfcProvisioning/settings.gradle b/admin/NfcProvisioning/settings.gradle
new file mode 100644
index 0000000..9464a35
--- /dev/null
+++ b/admin/NfcProvisioning/settings.gradle
@@ -0,0 +1 @@
+include 'Application'
diff --git a/admin/NfcProvisioning/template-params.xml b/admin/NfcProvisioning/template-params.xml
new file mode 100644
index 0000000..e5fc074
--- /dev/null
+++ b/admin/NfcProvisioning/template-params.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 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.
+-->
+<sample>
+    <name>NfcProvisioning</name>
+    <group>Device Admin</group>
+    <package>com.example.android.nfcprovisioning</package>
+
+    <minSdk>21</minSdk>
+
+    <strings>
+        <intro>
+            <![CDATA[
+This sample demonstrates how to provision other devices with a specified device owner using NFC.
+Install the DeviceOwner sample to an unprovisioned device. Fill in the values below, and bump the
+two devices, and tap this side to initiate the provisioning process.
+            ]]>
+        </intro>
+    </strings>
+
+    <template src="base"/>
+    <template src="FragmentView"/>
+
+    <common src="logger"/>
+    <common src="activities"/>
+
+    <metadata>
+        <status>PUBLISHED</status>
+        <categories>Device Admin</categories>
+        <technologies>Android</technologies>
+        <languages>Java</languages>
+        <solutions>Mobile</solutions>
+        <level>ADVANCED</level>
+        <icon>screenshots/icon-web.png</icon>
+        <screenshots>
+            <img>screenshots/1-main.png</img>
+        </screenshots>
+        <api_refs>
+            <android>android.app.admin.DevicePolicyManager</android>
+            <android>android.nfc.NfcAdapter</android>
+        </api_refs>
+
+        <description>
+            <![CDATA[
+This sample demonstrates how to use NFC to provision a new device with a device owner. Device owner
+is a specialized type of device administrator that can control device security and configuration.
+This sample itself is not a device owner, but it is a programming app that sends NFC message to an
+unprovisioned peer device and tells it to set up the specified device owner app.
+            ]]>
+        </description>
+
+        <intro>
+            <![CDATA[
+NFC Provisioning app is nothing but an ordinary Android Beam app that just sends out provisioning
+values to the peer device. This sample uses the values below.
+
+* [EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME] - The package name of the mobile device management
+  application that will be set as the profile owner or device owner.
+* [EXTRA_PROVISIONING_LOCALE] - The Locale that the device will be set to.
+* [EXTRA_PROVISIONING_TIME_ZONE] - The time zone AlarmManager that the device will be set to.
+* [EXTRA_PROVISIONING_WIFI_SSID] - The ssid of the wifi network that should be used during nfc
+  device owner provisioning for downloading the mobile device management application.
+* [EXTRA_PROVISIONING_WIFI_PASSWORD] - The password of the wifi network in
+  EXTRA_PROVISIONING_WIFI_SSID.
+
+Store values in an instance of Properties. Get a byte array representation of the Properties using
+ByteArrayOutputStream. Create an NdefRecord with the MIME type of
+[DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC][1]. Use [NfcAdapter#setNdefPushMessage][2] to set
+the NdefMessage as the message to be sent.
+
+[1]: https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#MIME_TYPE_PROVISIONING_NFC
+[2]: http://developer.android.com/reference/android/nfc/NfcAdapter.html#setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...)
+            ]]>
+        </intro>
+    </metadata>
+</sample>