Merge "Give MANAGE_PROFILE_AND_DEVICE_OWNERS to ManagedProvisioning."
diff --git a/res/values-gu-rIN/strings.xml b/res/values-gu-rIN/strings.xml
new file mode 100644
index 0000000..676e637
--- /dev/null
+++ b/res/values-gu-rIN/strings.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+/**
+ * Copyright (C) 2014 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 xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="provisioning_error_title" msgid="6320515739861578118">"ઊફ્ફ્ફ!"</string>
+    <string name="setup_work_profile" msgid="9164519662954159586">"તમારી પ્રોફાઇલ સેટ કરો"</string>
+    <string name="company_controls_workspace" msgid="2808025277267917221">"તમારી સંસ્થા આ પ્રોફાઇલને નિયંત્રિત કરે છે અને તેને સુરક્ષિત રાખે છે. તમે તમારા ઉપકરણ પર બાકીનું બધું નિયંત્રિત કરો છો."</string>
+    <string name="the_following_is_your_mdm" msgid="6613658218262376404">"નીચેની એપ્લિકેશનને આ પ્રોફાઇલ ઍક્સેસ કરવાની જરૂર પડશે:"</string>
+    <string name="set_up" msgid="7012862095553564169">"સેટ અપ"</string>
+    <string name="setting_up_workspace" msgid="6116976629983614927">"તમારી કાર્ય પ્રોફાઇલ સેટ કરી રહ્યું છે..."</string>
+    <string name="admin_has_ability_to_monitor_profile" msgid="8782160676037188061">"તમારા વ્યવસ્થાપક પાસે નેટવર્ક પ્રવૃત્તિ અને તમારા ઉપકરણની સ્થાન માહિતી સહિત સેટિંગ્સ, કૉર્પોરેટ ઍક્સેસ, એપ્લિકેશન્સ અને પ્રોફાઇલ સાથે સંકળાયેલ ડેટાને મૉનિટર અને સંચાલિત કરવાની ક્ષમતા છે."</string>
+    <string name="admin_has_ability_to_monitor_device" msgid="4534011355086694158">"તમારા વ્યવસ્થાપક પાસે નેટવર્ક પ્રવૃત્તિ અને તમારા ઉપકરણની સ્થાન માહિતી સહિત સેટિંગ્સ, કૉર્પોરેટ ઍક્સેસ, એપ્લિકેશન્સ અને આ ઉપકરણ સાથે સંકળાયેલ ડેટાને મૉનિટર અને સંચાલિત કરવાની ક્ષમતા છે."</string>
+    <string name="contact_your_admin_for_more_info" msgid="6870084889394621288">"તમારી સંસ્થાનું ગોપનીયતા નીતિઓ સહિત વધુ માહિતી માટે તમારા વ્યવસ્થાપકનો સંપર્ક કરો."</string>
+    <string name="learn_more_link" msgid="3012495805919550043">"વધુ જાણો"</string>
+    <string name="cancel_setup" msgid="2949928239276274745">"રદ કરો"</string>
+    <string name="ok_setup" msgid="5148111905838329307">"ઑકે"</string>
+    <string name="default_managed_profile_name" msgid="5370257687074907055">"કાર્ય પ્રોફાઇલ"</string>
+    <string name="delete_profile_title" msgid="3097803266123463699">"કાર્ય પ્રોફાઇલ દૂર કરીએ?"</string>
+    <string name="opening_paragraph_delete_profile_unknown_company" msgid="1132833578783368037">"આ કાર્ય પ્રોફાઇલ આમના દ્વારા સંચાલિત થાય છે:"</string>
+    <string name="opening_paragraph_delete_profile_known_company" msgid="3126629826260821264">"આ કાર્ય પ્રોફાઇલને આની મદદથી %s માટે સંચાલિત કરી છે:"</string>
+    <string name="read_more_delete_profile" msgid="8108077458455321659">"આગળ વધતાં પહેલાં કૃપા કરીને "<a href="#read_this_link">"આ વાંચો"</a>"."</string>
+    <string name="sure_you_want_to_delete_profile" msgid="1336653819166266605">"જો તમે ચાલુ રાખો છો તો આ પ્રોફાઇલમાંની તમામ એપ્લિકેશન્સ અને ડેટા કાઢી નાખવામાં આવશે."</string>
+    <string name="delete_profile" msgid="2299218578684663459">"કાઢી નાખો"</string>
+    <string name="cancel_delete_profile" msgid="5155447537894046036">"રદ કરો"</string>
+    <string name="encrypt_device_text_for_profile_owner_setup" msgid="4325067657681168120">"તમારી કાર્ય પ્રોફાઇલ સેટ કરવાનું ચાલુ રાખવા માટે, તમારે તમારા ઉપકરણને એન્ક્રિપ્ટ કરવાની જરૂર પડશે. આમાં થોડો સમય લાગી શકે છે."</string>
+    <string name="encrypt_device_text_for_device_owner_setup" msgid="7279768314707033707">"તમારા ઉપકરણને સેટ કરવાનું ચાલુ રાખવા માટે, તમારે તમારા ઉપકરણને એન્ક્રિપ્ટ કરવાની જરૂર છે. આમાં થોડો સમય લાગી શકે છે."</string>
+    <string name="encrypt_device_cancel" msgid="5644516574936584926">"રદ કરો"</string>
+    <string name="encrypt_device_launch_settings" msgid="826115154646195837">"એન્ક્રિપ્ટ કરો"</string>
+    <string name="continue_provisioning_notify_title" msgid="5191449100153186648">"એન્ક્રિપ્શન પૂર્ણ"</string>
+    <string name="continue_provisioning_notify_text" msgid="3027317630111909095">"તમારી કાર્ય પ્રોફાઇલ સેટ કરવાનું ચાલુ રાખવા માટે ટચ કરો"</string>
+    <string name="managed_provisioning_error_text" msgid="7063621174570680890">"તમારી કાર્ય પ્રોફાઇલ સેટ કરી શકાઈ નથી. તમારા આઇટી વિભાગનો સંપર્ક કરો અથવા પછી ફરીથી પ્રયાસ કરો."</string>
+    <string name="managed_provisioning_not_supported" msgid="6582227325719911795">"તમારું ઉપકરણ કાર્ય પ્રોફાઇલ્સનું સમર્થન કરતું નથી"</string>
+    <string name="user_is_not_owner" msgid="6193230832887977927">"કાર્ય પ્રોફાઇલો ઉપકરણના પ્રાથમિક વપરાશકર્તા દ્વારા સેટ કરવાની જરૂર છે"</string>
+    <string name="maximum_user_limit_reached" msgid="7267689354022124652">"કાર્ય પ્રોફાઇલ બનાવી શકાઈ નથી કારણ કે તમારા ઉપકરણ પર મહત્તમ સંખ્યામાં વપરાશકર્તાઓ પહોંચી ગયા છે. કૃપા કરીને ઓછામાં ઓછો એક વપરાશકર્તા દૂર કરો અને ફરીથી પ્રયાસ કરો."</string>
+    <string name="managed_provisioning_not_supported_by_launcher" msgid="8710138269807942163">"તમારી કાર્ય પ્રોફાઇલ આ લોન્ચર એપ્લિકેશન દ્વારા સમર્થિત નથી. તમારે તેવા એક લોન્ચર પર સ્વિચ કરવું જોઈએ જે સુસંગત હોય."</string>
+    <string name="cancel_provisioning" msgid="3408069559452653724">"રદ કરો"</string>
+    <string name="pick_launcher" msgid="4257084827403983845">"ઓકે"</string>
+    <string name="default_owned_device_username" msgid="3915120202811807955">"કાર્ય ઉપકરણના વપરાશકર્તા"</string>
+    <string name="setup_work_device" msgid="3028145936574439146">"તમારા ઉપકરણને સેટ કરો"</string>
+    <string name="progress_data_process" msgid="7099462614425874283">"સેટઅપ ડેટા પર પ્રક્રિયા કરી રહ્યું છે..."</string>
+    <string name="progress_start_bluetooth" msgid="3798479957601150661">"Bluetooth પ્રારંભ કરી રહ્યું છે..."</string>
+    <string name="progress_connect_to_wifi" msgid="9214694010080838763">"Wi-Fi સાથે કનેક્ટ કરી રહ્યું છે..."</string>
+    <string name="progress_wipe_frp" msgid="545404730605450346">"ફેક્ટરી રીસેટ સુરક્ષા તપાસી રહ્યું છે..."</string>
+    <string name="progress_download" msgid="4995057798189799156">"વ્યવસ્થાપક એપ્લિકેશન ડાઉનલોડ કરી રહ્યું છે..."</string>
+    <string name="progress_install" msgid="9169411715762296097">"વ્યવસ્થાપક એપ્લિકેશન ઇન્સ્ટોલ કરી રહ્યું છે..."</string>
+    <string name="progress_set_owner" msgid="1292946927202510987">"ઉપકરણ માલિક સેટ કરી રહ્યાં છે..."</string>
+    <string name="device_owner_cancel_title" msgid="7909285135975063120">"સેટ કરવાનું રોકીએ?"</string>
+    <string name="device_owner_cancel_message" msgid="7928007377743469904">"શું તમે ખરેખર સેટ કરવું બંધ કરીને તમારા ઉપકરણના ડેટાને કાઢી નાખવા માગો છો?"</string>
+    <string name="device_owner_cancel_cancel" msgid="1052951540909389275">"રદ કરો"</string>
+    <string name="device_owner_error_ok" msgid="2556654993515978854">"ઑકે"</string>
+    <string name="device_owner_error_reset" msgid="1609782972753569267">"ફરીથી સેટ કરો"</string>
+    <string name="device_owner_error_general" msgid="5962462955470123776">"તમારું ઉપકરણ સેટ કરી શકાયું નથી. તમારા આઇટી વિભાગનો સંપર્ક કરો."</string>
+    <string name="device_owner_error_already_provisioned" msgid="49944866843771627">"આ ઉપકરણ પહેલાંથી જ સેટ કરેલું છે."</string>
+    <string name="device_owner_error_already_provisioned_user" msgid="5861348691161504683">"આ ઉપકરણ પહેલાંથી જ આ વપરાશકર્તા માટે સેટ કરેલું છે."</string>
+    <string name="device_owner_error_bluetooth" msgid="5191084800734703585">"Bluetooth પ્રારંભ કરી શકાતું નથી"</string>
+    <string name="device_owner_error_wifi" msgid="4256310285761332378">"Wi-Fi સાથે કનેક્ટ કરી શકાયું નથી"</string>
+    <string name="device_owner_error_frp" msgid="3998112234006304859">"ઉપકરણ ફેક્ટરી રીસેટ સુરક્ષા પસાર કરી શક્યું નથી"</string>
+    <string name="device_owner_error_hash_mismatch" msgid="184518450016295596">"એક ચેકસમ ભૂલને કારણે વ્યવસ્થાપક એપ્લિકેશનનો ઉપયોગ કરી શકાયો નથી. તમારા IT વિભાગનો સંપર્ક કરો."</string>
+    <string name="device_owner_error_download_failed" msgid="4520111971592657116">"વ્યવસ્થાપક એપ્લિકેશન ડાઉનલોડ કરી શકાઈ નથી"</string>
+    <string name="device_owner_error_package_invalid" msgid="3816725179069202140">"વ્યવસ્થાપક એપ્લિકેશનનો ઉપયોગ કરી શકતાં નથી. તેમાં ઘટકો ખૂટે છે અથવા દૂષિત છે. તમારા IT વિભાગનો સંપર્ક કરો."</string>
+    <string name="device_owner_error_package_name_invalid" msgid="5161432357348636936">"વ્યવસ્થાપક એપ્લિકેશન ઇન્સ્ટોલ કરી શકાતી નથી. પૅકેજ નામ અમાન્ય છે. તમારા IT વિભાગનો સંપર્ક કરો."</string>
+    <string name="device_owner_error_installation_failed" msgid="684566845601079360">"વ્યવસ્થાપક એપ્લિકેશન ઇન્સ્ટોલ કરી શકાઈ નહીં"</string>
+    <string name="device_owner_error_package_not_installed" msgid="6095079346537408556">"તમારા ઉપકરણ પર વ્યવસ્થાપક એપ્લિકેશન ઇન્સ્ટોલ થયેલ નથી"</string>
+    <string name="profile_owner_cancel_title" msgid="1087667875324931402">"સેટ કરવાનું રોકીએ?"</string>
+    <string name="profile_owner_cancel_message" msgid="3397782777804924267">"શું તમે ખરેખર સેટ કરવાનું બંધ કરવા માંગો છો?"</string>
+    <string name="profile_owner_cancel_cancel" msgid="4408725524311574891">"નહીં"</string>
+    <string name="profile_owner_cancel_ok" msgid="5951679183850766029">"હા"</string>
+    <string name="profile_owner_cancelling" msgid="2007485854183176973">"રદ કરી રહ્યુ છે..."</string>
+    <string name="provisioning" msgid="4512493827019163451">"જોગવાઈ કરી રહ્યું છે"</string>
+    <string name="copying_certs" msgid="5697938664953550881">"CA પ્રમાણપત્રો સેટ કરી રહ્યાં છે"</string>
+</resources>
diff --git a/res/values-pa-rIN/strings.xml b/res/values-pa-rIN/strings.xml
new file mode 100644
index 0000000..d8c44b2
--- /dev/null
+++ b/res/values-pa-rIN/strings.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+/**
+ * Copyright (C) 2014 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 xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="provisioning_error_title" msgid="6320515739861578118">"ਓਹ ਹੋ!"</string>
+    <string name="setup_work_profile" msgid="9164519662954159586">"ਆਪਣੀ ਪ੍ਰੋਫਾਈਲ ਸੈਟ ਅਪ ਕਰੋ"</string>
+    <string name="company_controls_workspace" msgid="2808025277267917221">"ਤੁਹਾਡੀ ਕੰਪਨੀ ਇਸ ਪ੍ਰੋਫਾਈਲ ਤੇ ਨਿਯੰਤਰਣ ਪਾਉਂਦੀ ਹੈ ਅਤੇ ਇਸਨੂੰ ਸੁਰੱਖਿਅਤ ਰੱਖਦੀ ਹੈ। ਤੁਸੀਂ ਆਪਣੀ ਡਿਵਾਈਸ ਤੇ ਹੋਰ ਸਭ ਕਿਸੇ ਤੇ ਨਿਯੰਤਰਣ ਪਾ ਸਕਦੇ ਹੋ।"</string>
+    <string name="the_following_is_your_mdm" msgid="6613658218262376404">"ਇਸ ਐਪ ਨੂੰ ਇਸ ਪ੍ਰੋਫਾਈਲ ਤੱਕ ਪਹੁੰਚ ਦੀ ਲੋੜ ਹੋਵੇਗੀ:"</string>
+    <string name="set_up" msgid="7012862095553564169">"ਸੈਟ ਅਪ"</string>
+    <string name="setting_up_workspace" msgid="6116976629983614927">"ਤੁਹਾਡੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਸੈਟ ਅਪ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="admin_has_ability_to_monitor_profile" msgid="8782160676037188061">"ਤੁਹਾਡੇ ਪ੍ਰਬੰਧਕ ਕੋਲ ਸੈਟਿੰਗਾਂ ਦਾ ਨਿਰੀਖਣ ਕਰਨ ਅਤੇ ਉਹਨਾਂ ਨੂੰ ਵਿਵਸਥਿਤ ਕਰਨ, ਐਪਸ ਅਤੇ ਪ੍ਰੋਫਾਈਲ ਨਾਲ ਜੁੜੇ ਡਾਟਾ ਤੱਕ ਕਾਰਪੋਰੇਟ ਪਹੁੰਚ ਦੀ ਸਮਰੱਥਾ ਹੈ, ਨੈਟਵਰਕ ਗਤੀਵਿਧੀ ਅਤੇ ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਦੀ ਨਿਰਧਾਰਿਤ ਸਥਾਨ ਜਾਣਕਾਰੀ ਸਮੇਤ।"</string>
+    <string name="admin_has_ability_to_monitor_device" msgid="4534011355086694158">"ਤੁਹਾਡੇ ਪ੍ਰਬੰਧਕ ਕੋਲ ਸੈਟਿੰਗਾਂ ਦਾ ਨਿਰੀਖਣ ਕਰਨ ਅਤੇ ਉਹਨਾਂ ਨੂੰ ਵਿਵਸਥਿਤ ਕਰਨ, ਐਪਸ ਅਤੇ ਇਸ ਡਿਵਾਈਸ ਨਾਲ ਜੁੜੇ ਡਾਟਾ ਤੱਕ ਕਾਰਪੋਰੇਟ ਪਹੁੰਚ ਦੀ ਸਮਰੱਥਾ ਹੈ, ਨੈਟਵਰਕ ਗਤੀਵਿਧੀ ਅਤੇ ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਦੀ ਨਿਰਧਾਰਿਤ ਸਥਾਨ ਜਾਣਕਾਰੀ ਸਮੇਤ।"</string>
+    <string name="contact_your_admin_for_more_info" msgid="6870084889394621288">"ਹੋਰ ਜਾਣਕਾਰੀ ਲਈ ਆਪਣੇ ਪ੍ਰਬੰਧਕ ਨੂੰ ਸੰਪਰਕ ਕਰੋ, ਤੁਹਾਡੀ ਕੰਪਨੀ ਦੀਆਂ ਪ੍ਰਾਈਵੇਸੀ ਨੀਤੀਆਂ ਸਮੇਤ।"</string>
+    <string name="learn_more_link" msgid="3012495805919550043">"ਹੋਰ ਜਾਣੋ"</string>
+    <string name="cancel_setup" msgid="2949928239276274745">"ਰੱਦ ਕਰੋ"</string>
+    <string name="ok_setup" msgid="5148111905838329307">"ਠੀਕ"</string>
+    <string name="default_managed_profile_name" msgid="5370257687074907055">"ਕੰਮ ਪ੍ਰੋਫਾਈਲ"</string>
+    <string name="delete_profile_title" msgid="3097803266123463699">"ਕੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਹਟਾਉਣੀ ਹੈ?"</string>
+    <string name="opening_paragraph_delete_profile_unknown_company" msgid="1132833578783368037">"ਇਹ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਇਸ ਵੱਲੋਂ ਵਿਵਸਥਿਤ ਕੀਤੀ ਗਈ ਹੈ:"</string>
+    <string name="opening_paragraph_delete_profile_known_company" msgid="3126629826260821264">"ਇਹ ਕੰਮ ਪ੍ਰੋਫਾਈਲ %s ਲਈ ਇਹ ਵਰਤਦੇ ਹੋਏ ਵਿਵਸਥਿਤ ਕੀਤੀ ਗਈ ਹੈ:"</string>
+    <string name="read_more_delete_profile" msgid="8108077458455321659">"ਕਿਰਪਾ ਕਰਕੇ ਅੱਗੇ ਵਧਣ ਤੋਂ ਪਹਿਲਾਂ "<a href="#read_this_link">"ਇਹ"</a>" ਪੜ੍ਹੋ।"</string>
+    <string name="sure_you_want_to_delete_profile" msgid="1336653819166266605">"ਜੇਕਰ ਤੁਸੀਂ ਜਾਰੀ ਰੱਖਦੇ ਹੋ ਤਾਂ ਇਸ ਪ੍ਰੋਫਾਈਲ ਵਿੱਚ ਸਾਰੇ ਐਪਸ ਅਤੇ ਡਾਟਾ ਮਿਟਾ ਦਿੱਤਾ ਜਾਏਗਾ।"</string>
+    <string name="delete_profile" msgid="2299218578684663459">"ਮਿਟਾਓ"</string>
+    <string name="cancel_delete_profile" msgid="5155447537894046036">"ਰੱਦ ਕਰੋ"</string>
+    <string name="encrypt_device_text_for_profile_owner_setup" msgid="4325067657681168120">"ਆਪਣੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਨੂੰ ਸੈਟ ਅਪ ਕਰਨਾ ਜਾਰੀ ਰੱਖਣ ਲਈ, ਤੁਹਾਨੂੰ ਆਪਣੀ ਡਿਵਾਈਸ ਨੂੰ ਐਨਕ੍ਰਿਪਟ ਕਰਨ ਦੀ ਲੋੜ ਹੋਵੇਗੀ। ਇਸ ਵਿੱਚ ਥੋੜ੍ਹੀ ਦੇਰ ਲੱਗ ਸਕਦੀ ਹੈ।"</string>
+    <string name="encrypt_device_text_for_device_owner_setup" msgid="7279768314707033707">"ਆਪਣੀ ਡਿਵਾਈਸ ਨੂੰ ਸੈਟ ਅਪ ਕਰਨਾ ਜਾਰੀ ਰੱਖਣ ਲਈ, ਤੁਹਾਨੂੰ ਆਪਣੀ ਡਿਵਾਈਸ ਨੂੰ ਐਨਕ੍ਰਿਪਟ ਕਰਨ ਦੀ ਲੋੜ ਹੋਵੇਗੀ। ਇਸ ਵਿੱਚ ਥੋੜ੍ਹੀ ਦੇਰ ਲੱਗ ਸਕਦੀ ਹੈ।"</string>
+    <string name="encrypt_device_cancel" msgid="5644516574936584926">"ਰੱਦ ਕਰੋ"</string>
+    <string name="encrypt_device_launch_settings" msgid="826115154646195837">"ਐਨਕ੍ਰਿਪਟ ਕਰੋ"</string>
+    <string name="continue_provisioning_notify_title" msgid="5191449100153186648">"ਐਨਕ੍ਰਿਪਸ਼ਨ ਪੂਰਾ"</string>
+    <string name="continue_provisioning_notify_text" msgid="3027317630111909095">"ਆਪਣੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਸੈਟ ਅਪ ਕਰਨਾ ਜਾਰੀ ਰੱਖਣ ਲਈ ਛੋਹਵੋ"</string>
+    <string name="managed_provisioning_error_text" msgid="7063621174570680890">"ਤੁਹਾਡੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਸੈਟ ਅਪ ਨਹੀਂ ਕਰ ਸਕਿਆ। ਆਪਣੇ IT ਵਿਭਾਗ ਨੂੰ ਸੰਪਰਕ ਕਰੋ ਜਾਂ ਬਾਅਦ ਵਿੱਚ ਦੁਬਾਰਾ ਕੋਸ਼ਿਸ਼ ਕਰੋ।"</string>
+    <string name="managed_provisioning_not_supported" msgid="6582227325719911795">"ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਕੰਮ ਪ੍ਰੋਫਾਈਲਾਂ ਦਾ ਸਮਰਥਨ ਨਹੀਂ ਕਰਦੀ"</string>
+    <string name="user_is_not_owner" msgid="6193230832887977927">"ਕੰਮ ਪ੍ਰੋਫਾਈਲਾਂ ਨੂੰ ਡਿਵਾਈਸ ਦੇ ਮੁੱਖ ਉਪਭੋਗਤਾ ਵੱਲੋਂ ਸੈਟ ਅਪ ਕੀਤੇ ਜਾਣ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ"</string>
+    <string name="maximum_user_limit_reached" msgid="7267689354022124652">"ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਨਹੀਂ ਬਣਾਈ ਜਾ ਸਕੀ ਕਿਉਂਕਿ ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਤੇ ਅਧਿਕਤਮ ਉਪਭੋਗਤਾਵਾਂ ਦੀ ਸੀਮਾ ਪੂਰੀ ਹੋ ਗਈ ਹੈ। ਕਿਰਪਾ ਕਰਕੇ ਘੱਟੋ-ਘੱਟ ਇੱਕ ਉਪਭੋਗਤਾ ਨੂੰ ਹਟਾਓ ਅਤੇ ਦੁਬਾਰਾ ਕੋਸ਼ਿਸ਼ ਕਰੋ।"</string>
+    <string name="managed_provisioning_not_supported_by_launcher" msgid="8710138269807942163">"ਤੁਹਾਡੀ ਕੰਮ ਪ੍ਰੋਫਾਈਲ ਇਸ ਲੌਂਚਰ ਐਪ ਵੱਲੋਂ ਸਮਰਥਿਤ ਨਹੀਂ ਹੈ। ਤੁਹਾਨੂੰ ਇੱਕ ਅਜਿਹੇ ਲੌਂਚਰ ਨਾਲ ਸਵਿਚ ਕਰਨ ਦੀ ਲੋੜ ਹੋਵੇਗੀ ਜੋ ਅਨੁਕੂਲ ਹੋਵੇ।"</string>
+    <string name="cancel_provisioning" msgid="3408069559452653724">"ਰੱਦ ਕਰੋ"</string>
+    <string name="pick_launcher" msgid="4257084827403983845">"ਠੀਕ"</string>
+    <string name="default_owned_device_username" msgid="3915120202811807955">"ਕੰਮ ਡਿਵਾਈਸ ਦਾ ਉਪਭੋਗਤਾ"</string>
+    <string name="setup_work_device" msgid="3028145936574439146">"ਆਪਣੀ ਡਿਵਾਈਸ ਸੈਟ ਅਪ ਕਰੋ"</string>
+    <string name="progress_data_process" msgid="7099462614425874283">"ਸੈਟਅਪ ਡਾਟਾ ਦੀ ਪ੍ਰਕਿਰਿਆ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_start_bluetooth" msgid="3798479957601150661">"ਬਲੂਟੁੱਥ ਅਰੰਭ ਹੋ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_connect_to_wifi" msgid="9214694010080838763">"Wi-Fi ਨਾਲ ਕਨੈਕਟ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_wipe_frp" msgid="545404730605450346">"ਫੈਕਟਰੀ ਰੀਸੈੱਟ ਸੁਰੱਖਿਆ ਦੀ ਜਾਂਚ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_download" msgid="4995057798189799156">"ਐਡਮਿਨ ਐਪ ਡਾਊਨਲੋਡ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_install" msgid="9169411715762296097">"ਐਡਮਿਨ ਐਪ ਇੰਸਟੌਲ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="progress_set_owner" msgid="1292946927202510987">"ਡਿਵਾਈਸ ਮਾਲਕ ਨੂੰ ਸੈਟ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="device_owner_cancel_title" msgid="7909285135975063120">"ਕੀ ਸੈਟ ਅਪ ਕਰਨਾ ਰੋਕਣਾ ਹੈ?"</string>
+    <string name="device_owner_cancel_message" msgid="7928007377743469904">"ਕੀ ਤੁਸੀਂ ਯਕੀਨੀ ਤੌਰ ਤੇ ਸੈਟ ਅਪ ਕਰਨਾ ਬੰਦ ਅਤੇ ਆਪਣੀ ਡਿਵਾਈਸ ਦਾ ਡਾਟਾ ਮਿਟਾਉਣਾ ਚਾਹੁੰਦੇ ਹੋ?"</string>
+    <string name="device_owner_cancel_cancel" msgid="1052951540909389275">"ਰੱਦ ਕਰੋ"</string>
+    <string name="device_owner_error_ok" msgid="2556654993515978854">"ਠੀਕ"</string>
+    <string name="device_owner_error_reset" msgid="1609782972753569267">"ਰੀਸੈਟ ਕਰੋ"</string>
+    <string name="device_owner_error_general" msgid="5962462955470123776">"ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਸੈਟ ਅਪ ਨਹੀਂ ਕਰ ਸਕਿਆ। ਆਪਣੇ IT ਵਿਭਾਗ ਨੂੰ ਸੰਪਰਕ ਕਰੋ।"</string>
+    <string name="device_owner_error_already_provisioned" msgid="49944866843771627">"ਇਹ ਡਿਵਾਈਸ ਪਹਿਲਾਂ ਹੀ ਸੈਟ ਅਪ ਕੀਤੀ ਹੋਈ ਹੈ।"</string>
+    <string name="device_owner_error_already_provisioned_user" msgid="5861348691161504683">"ਇਹ ਡਿਵਾਈਸ ਪਹਿਲਾਂ ਹੀ ਇਸ ਉਪਭੋਗਤਾ ਲਈ ਸੈਟ ਅਪ ਕੀਤੀ ਹੋਈ ਹੈ।"</string>
+    <string name="device_owner_error_bluetooth" msgid="5191084800734703585">"ਬਲੂਟੁੱਥ ਨੂੰ ਅਰੰਭ ਨਹੀਂ ਕੀਤਾ ਜਾ ਸਕਿਆ"</string>
+    <string name="device_owner_error_wifi" msgid="4256310285761332378">"Wi-Fi ਨਾਲ ਕਨੈਕਟ ਨਹੀਂ ਕਰ ਸਕਿਆ"</string>
+    <string name="device_owner_error_frp" msgid="3998112234006304859">"ਡਿਵਾਈਸ ਫੈਕਟਰੀ ਰੀਸੈੱਟ ਸੁਰੱਖਿਆ ਨੂੰ ਪਾਸ ਨਹੀਂ ਕਰ ਸਕਿਆ"</string>
+    <string name="device_owner_error_hash_mismatch" msgid="184518450016295596">"ਇੱਕ checksum ਅਸ਼ੁੱਧੀ ਦੇ ਕਾਰਨ ਐਡਮਿਨ ਐਪ ਨਹੀਂ ਵਰਤ ਸਕਿਆ। ਆਪਣੇ IT ਵਿਭਾਗ ਨੂੰ ਸੰਪਰਕ ਕਰੋ।"</string>
+    <string name="device_owner_error_download_failed" msgid="4520111971592657116">"ਐਡਮਿਨ ਐਪ ਨੂੰ ਡਾਊਨਲੋਡ ਨਹੀਂ ਕਰ ਸਕਿਆ"</string>
+    <string name="device_owner_error_package_invalid" msgid="3816725179069202140">"ਐਡਮਿਨ ਐਪ ਨਹੀਂ ਵਰਤ ਸਕਿਆ। ਇਸਦੇ ਕੰਪੋਨੈਂਟ ਲੁਪਤ ਹਨ ਜਾਂ ਕਰਪਟ ਹਨ। ਆਪਣੇ IT ਵਿਭਾਗ ਨੂੰ ਸੰਪਰਕ ਕਰੋ।"</string>
+    <string name="device_owner_error_package_name_invalid" msgid="5161432357348636936">"ਐਡਮਿਨ ਐਪ ਇੰਸਟੌਲ ਨਹੀਂ ਕਰ ਸਕਦਾ। ਪੈਕੇਜ ਨਾਮ ਅਪ੍ਰਮਾਣਿਕ ਹੈ। ਆਪਣੇ IT ਵਿਭਾਗ ਨੂੰ ਸੰਪਰਕ ਕਰੋ।"</string>
+    <string name="device_owner_error_installation_failed" msgid="684566845601079360">"ਐਡਮਿਨ ਐਪ ਇੰਸਟੌਲ ਨਹੀਂ ਕਰ ਸਕਿਆ"</string>
+    <string name="device_owner_error_package_not_installed" msgid="6095079346537408556">"ਐਡਮਿਨ ਐਪ ਤੁਹਾਡੀ ਡਿਵਾਈਸ ਤੇ ਇੰਸਟੌਲ ਨਹੀਂ ਕੀਤਾ ਹੋਇਆ ਹੈ"</string>
+    <string name="profile_owner_cancel_title" msgid="1087667875324931402">"ਕੀ ਸੈਟ ਅਪ ਕਰਨਾ ਰੋਕਣਾ ਹੈ?"</string>
+    <string name="profile_owner_cancel_message" msgid="3397782777804924267">"ਕੀ ਤੁਸੀਂ ਯਕੀਨੀ ਤੌਰ ਤੇ ਸੈਟ ਅਪ ਕਰਨਾ ਬੰਦ ਕਰਨਾ ਚਾਹੁੰਦੇ ਹੋ?"</string>
+    <string name="profile_owner_cancel_cancel" msgid="4408725524311574891">"ਨਹੀਂ"</string>
+    <string name="profile_owner_cancel_ok" msgid="5951679183850766029">"ਹਾਂ"</string>
+    <string name="profile_owner_cancelling" msgid="2007485854183176973">"ਰੱਦ ਕਰ ਰਿਹਾ ਹੈ..."</string>
+    <string name="provisioning" msgid="4512493827019163451">"ਪ੍ਰੋਵਿਜ਼ਨਿੰਗ"</string>
+    <string name="copying_certs" msgid="5697938664953550881">"CA ਪ੍ਰਮਾਣ-ਪੱਤਰ ਸੈਟ ਕਰ ਰਿਹਾ ਹੈ"</string>
+</resources>
diff --git a/res/values-sq-rAL/strings.xml b/res/values-sq-rAL/strings.xml
new file mode 100644
index 0000000..b0dde07
--- /dev/null
+++ b/res/values-sq-rAL/strings.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+/**
+ * Copyright (C) 2014 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 xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="provisioning_error_title" msgid="6320515739861578118">"Gabim!"</string>
+    <string name="setup_work_profile" msgid="9164519662954159586">"Konfiguro profilin"</string>
+    <string name="company_controls_workspace" msgid="2808025277267917221">"Kontrolli dhe siguria e këtij profili menaxhohet nga organizata jote. Çdo gjë tjetër në pajisje kontrollohet nga ti."</string>
+    <string name="the_following_is_your_mdm" msgid="6613658218262376404">"Aplikacionit të mëposhtëm do i nevojitet qasje në këtë profil:"</string>
+    <string name="set_up" msgid="7012862095553564169">"Organizo"</string>
+    <string name="setting_up_workspace" msgid="6116976629983614927">"Po konfiguron profilin tënd të punës..."</string>
+    <string name="admin_has_ability_to_monitor_profile" msgid="8782160676037188061">"Administratori yt gëzon privilegjet e monitorimit dhe menaxhimit të cilësimeve, qasjen në korporatë, aplikacionet dhe të dhënat që shoqërohen me profilin, përfshi aktivitetin e rrjetit dhe informacionin e vendndodhjes së pajisjes tënde."</string>
+    <string name="admin_has_ability_to_monitor_device" msgid="4534011355086694158">"Administratori yt gëzon privilegjet e monitorimit dhe menaxhimit të cilësimeve, qasjen në korporatë, aplikacionet dhe të dhënat që shoqërohen me këtë pajisje, përfshi aktivitetin e rrjetit dhe informacionin e vendndodhjes së pajisjes tënde."</string>
+    <string name="contact_your_admin_for_more_info" msgid="6870084889394621288">"Kontakto administratorin tënd për më shumë informacion, përfshi politikat e privatësisë së organizatës tënde."</string>
+    <string name="learn_more_link" msgid="3012495805919550043">"Mëso më shumë"</string>
+    <string name="cancel_setup" msgid="2949928239276274745">"Anulo"</string>
+    <string name="ok_setup" msgid="5148111905838329307">"Në rregull!"</string>
+    <string name="default_managed_profile_name" msgid="5370257687074907055">"Profili i punës"</string>
+    <string name="delete_profile_title" msgid="3097803266123463699">"Të hiqet profili i punës?"</string>
+    <string name="opening_paragraph_delete_profile_unknown_company" msgid="1132833578783368037">"Ky profil pune menaxhohet nga:"</string>
+    <string name="opening_paragraph_delete_profile_known_company" msgid="3126629826260821264">"Ky profil pune menaxhohet për %s me:"</string>
+    <string name="read_more_delete_profile" msgid="8108077458455321659"><a href="#read_this_link">"Lexo këtë"</a>" para se të vazhdosh."</string>
+    <string name="sure_you_want_to_delete_profile" msgid="1336653819166266605">"Të gjitha aplikacionet dhe të dhënat në këtë profil do të fshihen nëse vazhdon."</string>
+    <string name="delete_profile" msgid="2299218578684663459">"Fshi"</string>
+    <string name="cancel_delete_profile" msgid="5155447537894046036">"Anulo"</string>
+    <string name="encrypt_device_text_for_profile_owner_setup" msgid="4325067657681168120">"Për të vazhduar konfigurimin e profilit tënd të punës, duhet të enkriptosh pajisjen. Kjo mund të kërkojë pak kohë."</string>
+    <string name="encrypt_device_text_for_device_owner_setup" msgid="7279768314707033707">"Për të vazhduar konfigurimin e pajisjes, do të duhet ta enkriptosh atë. Kjo mund të marrë pak kohë."</string>
+    <string name="encrypt_device_cancel" msgid="5644516574936584926">"Anulo"</string>
+    <string name="encrypt_device_launch_settings" msgid="826115154646195837">"Enkripto"</string>
+    <string name="continue_provisioning_notify_title" msgid="5191449100153186648">"Enkriptimi përfundoi"</string>
+    <string name="continue_provisioning_notify_text" msgid="3027317630111909095">"Prek për të vazhduar konfigurimin e profilit të punës"</string>
+    <string name="managed_provisioning_error_text" msgid="7063621174570680890">"Nuk mundi ta konfiguronte profilin tënd të punës. Kontakto departamentin e informatikës ose provo sërish më vonë."</string>
+    <string name="managed_provisioning_not_supported" msgid="6582227325719911795">"Pajisja nuk mbështet profile pune"</string>
+    <string name="user_is_not_owner" msgid="6193230832887977927">"Profilet e punës duhen konfiguruar nga përdoruesi parësor i pajisjes"</string>
+    <string name="maximum_user_limit_reached" msgid="7267689354022124652">"Profili i punës nuk mundi të krijohej sepse është arritur numri maksimal i përdoruesve në pajisje. Hiq të paktën një përdorues dhe provo sërish."</string>
+    <string name="managed_provisioning_not_supported_by_launcher" msgid="8710138269807942163">"Profili i punës nuk mbështetet nga ky aplikacion nisës. Nevojitet të kalosh në një nisës të pajtueshëm."</string>
+    <string name="cancel_provisioning" msgid="3408069559452653724">"Anulo"</string>
+    <string name="pick_launcher" msgid="4257084827403983845">"Në rregull!"</string>
+    <string name="default_owned_device_username" msgid="3915120202811807955">"Përdorues i pajisjes së punës"</string>
+    <string name="setup_work_device" msgid="3028145936574439146">"Konfiguro pajisjen"</string>
+    <string name="progress_data_process" msgid="7099462614425874283">"Po përpunon të dhënat e konfigurimit..."</string>
+    <string name="progress_start_bluetooth" msgid="3798479957601150661">"Po nis bluetooth-in..."</string>
+    <string name="progress_connect_to_wifi" msgid="9214694010080838763">"Po lidhet me Wi-Fi..."</string>
+    <string name="progress_wipe_frp" msgid="545404730605450346">"Po kontrollon mbrojtjen nga rivendosja në gjendje fabrike..."</string>
+    <string name="progress_download" msgid="4995057798189799156">"Po shkarkon aplikacionin e administratorit..."</string>
+    <string name="progress_install" msgid="9169411715762296097">"Po instalon aplikacionin e administratorit..."</string>
+    <string name="progress_set_owner" msgid="1292946927202510987">"Po cakton zotëruesin e pajisjes..."</string>
+    <string name="device_owner_cancel_title" msgid="7909285135975063120">"Të ndalohet konfigurimi?"</string>
+    <string name="device_owner_cancel_message" msgid="7928007377743469904">"I sigurt që dëshiron ta ndalosh konfigurimin dhe t\'i fshish të dhënat e pajisjes tënde?"</string>
+    <string name="device_owner_cancel_cancel" msgid="1052951540909389275">"Anulo"</string>
+    <string name="device_owner_error_ok" msgid="2556654993515978854">"Në rregull!"</string>
+    <string name="device_owner_error_reset" msgid="1609782972753569267">"Rivendos"</string>
+    <string name="device_owner_error_general" msgid="5962462955470123776">"Pajisja jote nuk mund të konfigurohej. Kontakto me departamentin e informatikës."</string>
+    <string name="device_owner_error_already_provisioned" msgid="49944866843771627">"Kjo pajisje është e konfiguruar tashmë."</string>
+    <string name="device_owner_error_already_provisioned_user" msgid="5861348691161504683">"Kjo pajisje është e konfiguruar tashmë për këtë përdorues."</string>
+    <string name="device_owner_error_bluetooth" msgid="5191084800734703585">"Bluetooth-i nuk mund të nisej"</string>
+    <string name="device_owner_error_wifi" msgid="4256310285761332378">"Nuk mundi të lidhej me Wi-Fi"</string>
+    <string name="device_owner_error_frp" msgid="3998112234006304859">"Nuk mund ta kapërcente mbrojtjen e pajisjes nga rivendosja në gjendje fabrike"</string>
+    <string name="device_owner_error_hash_mismatch" msgid="184518450016295596">"Aplikacioni i administratorit nuk mund të përdorej për shkak të gabimit të shumës së kontrollit. Kontakto me departamentin e informatikës."</string>
+    <string name="device_owner_error_download_failed" msgid="4520111971592657116">"Aplikacioni i administratorit nuk mund të shkarkohej"</string>
+    <string name="device_owner_error_package_invalid" msgid="3816725179069202140">"Aplikacioni i administratorit nuk mund të përdoret pasi i mungojnë përbërësit ose është i dëmtuar. Kontakto departamentin e informatikës."</string>
+    <string name="device_owner_error_package_name_invalid" msgid="5161432357348636936">"Aplikacioni i administratorit nuk mund të instalohet. Emri i paketës është i pavlefshëm. Kontakto me departamentin e teknologjisë së informacionit."</string>
+    <string name="device_owner_error_installation_failed" msgid="684566845601079360">"Nuk mundi ta instalonte aplikacionin e administratorit"</string>
+    <string name="device_owner_error_package_not_installed" msgid="6095079346537408556">"Aplikacioni i administratorit nuk është i instaluar në pajisjen tënde."</string>
+    <string name="profile_owner_cancel_title" msgid="1087667875324931402">"Të ndalohet konfigurimi?"</string>
+    <string name="profile_owner_cancel_message" msgid="3397782777804924267">"I sigurt që do ta ndalosh konfigurimin?"</string>
+    <string name="profile_owner_cancel_cancel" msgid="4408725524311574891">"Jo"</string>
+    <string name="profile_owner_cancel_ok" msgid="5951679183850766029">"Po"</string>
+    <string name="profile_owner_cancelling" msgid="2007485854183176973">"Po anulohet..."</string>
+    <string name="provisioning" msgid="4512493827019163451">"Përgatitja"</string>
+    <string name="copying_certs" msgid="5697938664953550881">"Po konfiguron certifikatat CA"</string>
+</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2d24065..c9b6ae5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -93,6 +93,8 @@
   <string name="managed_provisioning_not_supported">Your device doesn\'t support work profiles</string>
   <!-- Error string displayed if the user that initiated the provisioning is not the user owner. -->
   <string name="user_is_not_owner">Work profiles need to be set up by the primary user of the device</string>
+  <!-- Error string displayed if provisioning was initiated on a device with a Device Owner -->
+  <string name="device_owner_exists">Work profiles can not be setup on a managed device</string>
   <!-- Error string displayed if maximum user limit is reached -->
   <string name="maximum_user_limit_reached">Work profile could not be created as the maximum number of users on your device has been reached. Please remove at least one user and try again.</string>
   <!-- Error string displayed if the selected launcher doesn't support work profiles. -->
diff --git a/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java b/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
index c77777c..37ad912 100644
--- a/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
+++ b/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
@@ -116,6 +116,10 @@
                     "Exiting managed profile provisioning, calling user is not owner.");
             return;
         }
+        if (Utils.hasDeviceOwner(this)) {
+            showErrorAndClose(R.string.device_owner_exists,
+                    "Exiting managed profile provisioning, a device owner exists");
+        }
 
         // Initialize member variables from the intent, stop if the intent wasn't valid.
         try {
@@ -148,19 +152,12 @@
             }
         }
 
-        DevicePolicyManager dpm =
-                (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
-        String deviceOwner = dpm.getDeviceOwner();
-        if (deviceOwner != null && !deviceOwner.equals(mMdmPackageName)) {
-            showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, "
-                    + "profile owner must be in the same package as device owner.");
-            return;
-        }
-
         // If there is already a managed profile, setup the profile deletion dialog.
         // Otherwise, check whether system has reached maximum user limit.
         int existingManagedProfileUserId = alreadyHasManagedProfile();
         if (existingManagedProfileUserId != -1) {
+            DevicePolicyManager dpm =
+                    (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
             createDeleteManagedProfileDialog(dpm, existingManagedProfileUserId);
         } else if (isMaximumUserLimitReached()) {
             showErrorAndClose(R.string.maximum_user_limit_reached,
diff --git a/src/com/android/managedprovisioning/proxy/BluetoothConnectionService.java b/src/com/android/managedprovisioning/proxy/BluetoothConnectionService.java
index 2a3da54..7b4e6a4 100644
--- a/src/com/android/managedprovisioning/proxy/BluetoothConnectionService.java
+++ b/src/com/android/managedprovisioning/proxy/BluetoothConnectionService.java
@@ -24,7 +24,10 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.os.Handler;
+import android.os.HandlerThread;
 import android.os.IBinder;
+import android.os.Looper;
 import android.support.v4.content.LocalBroadcastManager;
 
 import com.android.managedprovisioning.NetworkMonitor;
@@ -57,6 +60,13 @@
     private static final String ACTION_LOCAL_SHUTDOWN_BLUETOOTH =
             "com.android.managedprovisioning.action.LOCAL_SHUTDOWN_BLUETOOTH";
 
+    /**
+     * Local broadcast sent when the Bluetooth connection has been set up.
+     * @see #setUpBluetoothProxyIfNeeded()
+     */
+    public static final String ACTION_LOCAL_BLUETOOTH_SETUP =
+            "com.android.managedprovisioning.action.LOCAL_BLUETOOTH_SETUP";
+
     public static final String EXTRA_BLUETOOTH_MAC = "BluetoothMac";
     public static final String EXTRA_BLUETOOTH_UUID = "BluetoothUuid";
     public static final String EXTRA_BLUETOOTH_DEVICE_ID = "BluetoothDeviceId";
@@ -64,9 +74,6 @@
 
     private static final AtomicBoolean sBluetoothConnectionStarted = new AtomicBoolean(false);
 
-    private String mBluetoothMac;
-    private String mBluetoothUuid;
-    private String mBluetoothDeviceId;
     private boolean mBluetoothUseProxy;
 
     /** Receives status updates sent by ManagedProvisioning. */
@@ -81,6 +88,9 @@
     private NetworkMonitor mNetworkMonitor;
     private ClientTetherConnection mBluetoothClient;
 
+    /** Used to run potentially long setup tasks. */
+    private Handler mHandler;
+
     /**
      * Send a status update broadcast to the local receiver.
      * @param context Android context used to send update
@@ -104,17 +114,26 @@
     }
 
     @Override
+    public void onCreate() {
+        HandlerThread thread = new HandlerThread(this.getClass().getSimpleName(),
+                android.os.Process.THREAD_PRIORITY_BACKGROUND);
+        thread.start();
+        Looper looper = thread.getLooper();
+        mHandler = new Handler(looper);
+    }
+
+    @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
         ProvisionLogger.logd("BluetoothConnectionService.onStartCommand");
         if (sBluetoothConnectionStarted.compareAndSet(false, true)) {
-            mBluetoothMac = intent.getStringExtra(EXTRA_BLUETOOTH_MAC);
-            mBluetoothUuid = intent.getStringExtra(EXTRA_BLUETOOTH_UUID);
-            mBluetoothDeviceId = intent.getStringExtra(EXTRA_BLUETOOTH_DEVICE_ID);
+            String bluetoothMac = intent.getStringExtra(EXTRA_BLUETOOTH_MAC);
+            String bluetoothUuid = intent.getStringExtra(EXTRA_BLUETOOTH_UUID);
+            String bluetoothDeviceId = intent.getStringExtra(EXTRA_BLUETOOTH_DEVICE_ID);
             mBluetoothUseProxy = intent.getBooleanExtra(EXTRA_BLUETOOTH_USE_PROXY, false);
             // Setup Bluetooth connection
             mBluetoothClient = new BluetoothTetherClient(this,
                     BluetoothAdapter.getDefaultAdapter(),
-                    mBluetoothDeviceId, mBluetoothMac, mBluetoothUuid);
+                    bluetoothDeviceId, bluetoothMac, bluetoothUuid);
             // Receives local broadcasts
             mLocalStatusReceiver = createLocalStatusReceiver();
             IntentFilter filter = new IntentFilter(ACTION_LOCAL_PROVISIONING_STATUS);
@@ -124,11 +143,7 @@
             mStatusReceiver = createStatusReceiver();
             registerReceiver(mStatusReceiver, new IntentFilter(
                     DevicePolicyManager.ACTION_SEND_DEVICE_INITIALIZER_STATUS));
-            if (mBluetoothUseProxy) {
-                startProxy();
-            } else {
-                ProvisionLogger.logd("BluetoothConnectionService: No proxy.");
-            }
+            setUpBluetoothProxyIfNeeded();
         } else {
             ProvisionLogger.logd("BluetoothConnectionService: Bluetooth aleady started");
             return Service.START_NOT_STICKY;
@@ -137,6 +152,32 @@
     }
 
     /**
+     * If the Bluetooth network proxy is needed, start the proxy in a background thread. A
+     * {@linkplain #ACTION_LOCAL_BLUETOOTH_SETUP} broadcast will be sent when the proxy has been
+     * set up. This method may be called from the main thread.
+     */
+    private void setUpBluetoothProxyIfNeeded() {
+        if (mBluetoothUseProxy) {
+            ProvisionLogger.logv("BluetoothConnectionService.setUpBluetooth");
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    if (startProxy()) {
+                        sendProxySetupBroadcast();
+                    }
+                }
+            });
+        } else {
+            ProvisionLogger.logd("BluetoothConnectionService: No proxy.");
+        }
+    }
+
+    private void sendProxySetupBroadcast() {
+        Intent intent = new Intent(ACTION_LOCAL_BLUETOOTH_SETUP);
+        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
+    }
+
+    /**
      * @return a receiver that listens for status update broadcasts.
      */
     private BroadcastReceiver createStatusReceiver() {
@@ -204,18 +245,23 @@
     /**
      * Start Bluetooth network proxy. Network requests will be proxied over Bluetooth to the
      * remote device.
+     *
+     * <p>This method must be called from a background thread.
+     * @return {@code true} if the proxy started
      */
-    private void startProxy() {
+    private boolean startProxy() {
         ProvisionLogger.logd("BluetoothConnectionService: Start proxy.");
         // Start listening
         try {
             mBluetoothClient.startGlobalProxy();
         } catch (IOException e) {
             ProvisionLogger.loge("Failure to set proxy.", e);
+            return false;
         }
         mBluetoothClient.sendStatusUpdate(
                 DeviceInitializerStatus.STATUS_STATE_CONNECT_BLUETOOTH_PROXY, "Started proxy.");
         mNetworkMonitor = new NetworkMonitor(this, this);
+        return true;
     }
 
     @Override
@@ -259,6 +305,8 @@
             unregisterReceiver(mStatusReceiver);
             mStatusReceiver = null;
         }
+        mHandler.removeCallbacksAndMessages(null);
+        sBluetoothConnectionStarted.set(false);
     }
 
     @Override
diff --git a/src/com/android/managedprovisioning/task/BluetoothConnectTask.java b/src/com/android/managedprovisioning/task/BluetoothConnectTask.java
index 44144b1..d57498b 100644
--- a/src/com/android/managedprovisioning/task/BluetoothConnectTask.java
+++ b/src/com/android/managedprovisioning/task/BluetoothConnectTask.java
@@ -8,10 +8,12 @@
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
+import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
 
 import com.android.managedprovisioning.ProvisionLogger;
 import com.android.managedprovisioning.ProvisioningParams;
+import com.android.managedprovisioning.comm.ProvisionCommLogger;
 import com.android.managedprovisioning.proxy.BluetoothConnectionService;
 
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -25,7 +27,7 @@
  */
 public class BluetoothConnectTask {
     /** Time to wait (in milliseconds) for the Bluetooth adapter to be enabled. */
-    private static final int BT_ENABLE_TIMEOUT_MS = 30000;
+    private static final int BT_ENABLE_TIMEOUT_MS = 45000;
 
     private final Context mContext;
     private final Callback mCallback;
@@ -51,6 +53,13 @@
      */
     private BroadcastReceiver mBtStateChangeReceiver;
 
+    /**
+     * Receives notification when the Bluetooth network proxy is set up. If the Bluetooth network
+     * proxy is required, this task will wait for the proxy to be enabled and for network access to
+     * be available.
+     */
+    private BroadcastReceiver mBtNetworkProxyReceiver;
+
     public BluetoothConnectTask(Context context, ProvisioningParams params, Callback callback) {
         mCallback = callback;
         mContext = context;
@@ -130,10 +139,6 @@
                     int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                             BluetoothAdapter.STATE_OFF);
                     if (state == BluetoothAdapter.STATE_ON && !mHasBeenEnabled) {
-                        if (mTaskDone.getAndSet(true)) {
-                            ProvisionLogger.logd("Bluetooth enabled but already timed out.");
-                            return;
-                        }
                         mHasBeenEnabled = true;
                         ProvisionLogger.logd("Received bluetooth enabled status.");
                         mHandler.post(new Runnable() {
@@ -166,12 +171,42 @@
         boolean useProxy = mUseBluetoothProxy && !mHasWifiSsid &&
                 !AddWifiNetworkTask.isConnectedToWifi(mContext);
         // Start Bluetooth Service
+        if (useProxy) {
+            // This task won't succeed until the network proxy is enabled. Other tasks may require
+            // the network connection provided by this proxy. This receiver will be notified
+            // by the BluetoothConnectionService.
+            mBtNetworkProxyReceiver = new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    ProvisionCommLogger.logd("Bluetooth proxy; Setup complete");
+                    onBluetoothSetUp();
+                }
+            };
+            LocalBroadcastManager.getInstance(mContext).registerReceiver(
+                    mBtNetworkProxyReceiver,
+                    new IntentFilter(BluetoothConnectionService.ACTION_LOCAL_BLUETOOTH_SETUP));
+        }
         Intent intent = new Intent(mContext, BluetoothConnectionService.class);
         intent.putExtra(BluetoothConnectionService.EXTRA_BLUETOOTH_MAC, mBluetoothMac);
         intent.putExtra(BluetoothConnectionService.EXTRA_BLUETOOTH_UUID, mBluetoothUuid);
         intent.putExtra(BluetoothConnectionService.EXTRA_BLUETOOTH_DEVICE_ID, mBluetoothDeviceId);
         intent.putExtra(BluetoothConnectionService.EXTRA_BLUETOOTH_USE_PROXY, useProxy);
         mContext.startService(intent);
+        if (!useProxy) {
+            // A network connection will be established some other way.
+            onBluetoothSetUp();
+        }
+    }
+
+    /**
+     * Called when the Bluetooth connection has been enabled.
+     */
+    private void onBluetoothSetUp() {
+        // Clean up receivers and call on success.
+        if (mTaskDone.getAndSet(true)) {
+            ProvisionLogger.logd("Bluetooth enabled but already timed out.");
+            return;
+        }
         cleanUp();
         mCallback.onSuccess();
     }
@@ -184,6 +219,10 @@
             mContext.unregisterReceiver(mBtStateChangeReceiver);
             mBtStateChangeReceiver = null;
         }
+        if (mBtNetworkProxyReceiver != null) {
+            LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mBtNetworkProxyReceiver);
+            mBtNetworkProxyReceiver = null;
+        }
         mHandler.removeCallbacksAndMessages(null);
     }