Untab Location Settings and tab Location Services

Bug: 180533061
Test: on device
Change-Id: I1f096ffe1028dbf46816bbac5d514e3cb48d9e2c
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index 93f30e5..0ac7d1a 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -38,7 +38,17 @@
     <PreferenceCategory
         android:key="location_advanced_settings"
         android:layout="@layout/preference_category_no_label"
-        settings:initialExpandedChildrenCount="2">
+        settings:initialExpandedChildrenCount="3">
+
+        <!-- This preference gets removed if there is no managed profile -->
+        <com.android.settingslib.RestrictedSwitchPreference
+            android:enabled="false"
+            android:key="managed_profile_location_switch"
+            android:selectable="true"
+            android:title="@string/managed_profile_location_switch_title"
+            settings:controller="com.android.settings.location.LocationForWorkPreferenceController"
+            settings:forWork="true"
+            settings:useAdminDisabledSummary="true"/>
 
         <!-- This preference category gets removed if new_recent_location_ui is disabled -->
         <Preference
@@ -57,23 +67,6 @@
             android:title="@string/location_services_screen_title"
             settings:controller="com.android.settings.location.LocationServicesPreferenceController"/>
 
-        <!-- This preference gets removed if there is no managed profile -->
-        <com.android.settingslib.RestrictedSwitchPreference
-            android:enabled="false"
-            android:key="managed_profile_location_switch"
-            android:selectable="true"
-            android:title="@string/managed_profile_location_switch_title"
-            settings:controller="com.android.settings.location.LocationForWorkPreferenceController"
-            settings:forWork="true"
-            settings:useAdminDisabledSummary="true"/>
-
-        <!-- This preference gets removed if there is no managed profile -->
-        <PreferenceCategory
-            android:key="location_services_managed_profile"
-            android:title="@string/managed_profile_location_services"
-            settings:forWork="true"
-            settings:controller="com.android.settings.location.LocationInjectedServicesForWorkPreferenceController"/>
-
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
index 2891e3a..c324aca 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
@@ -20,7 +20,7 @@
 
 import com.android.settings.accounts.AccountDashboardFragment;
 import com.android.settings.applications.manageapplications.ManageApplications;
-import com.android.settings.location.LocationSettings;
+import com.android.settings.location.LocationServices;
 import com.android.settings.location.RecentLocationAccessSeeAllFragment;
 
 import java.util.Map;
@@ -42,9 +42,9 @@
                 ProfileSelectAccountFragment.class.getName());
         FRAGMENT_MAP.put(ManageApplications.class.getName(),
                 ProfileSelectManageApplications.class.getName());
-        FRAGMENT_MAP.put(LocationSettings.class.getName(),
-                ProfileSelectLocationFragment.class.getName());
         FRAGMENT_MAP.put(RecentLocationAccessSeeAllFragment.class.getName(),
                 ProfileSelectRecentLocationAccessFragment.class.getName());
+        FRAGMENT_MAP.put(LocationServices.class.getName(),
+                ProfileSelectLocationServicesFragment.class.getName());
     }
 }
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java
new file mode 100644
index 0000000..b6f03d6
--- /dev/null
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.dashboard.profileselector;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.location.LocationServices;
+import com.android.settings.location.LocationServicesForWork;
+
+/**
+ * Location Services page for personal/managed profile.
+ */
+public class ProfileSelectLocationServicesFragment extends ProfileSelectFragment {
+
+    @Override
+    public Fragment[] getFragments() {
+        final Bundle workOnly = new Bundle();
+        workOnly.putInt(EXTRA_PROFILE, ProfileType.WORK);
+        final Fragment workFragment = new LocationServicesForWork();
+        workFragment.setArguments(workOnly);
+
+        final Bundle personalOnly = new Bundle();
+        personalOnly.putInt(EXTRA_PROFILE, ProfileType.PERSONAL);
+        final Fragment personalFragment = new LocationServices();
+        personalFragment.setArguments(personalOnly);
+        return new Fragment[]{
+                personalFragment, // 0
+                workFragment
+        };
+    }
+}
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index bb971bf..54e38d8 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -86,7 +86,6 @@
         use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this);
         use(LocationFooterPreferenceController.class).init(this);
         use(LocationForWorkPreferenceController.class).init(this);
-        use(LocationInjectedServicesForWorkPreferenceController.class).init(this);
     }
 
     @Override