Fix UI issue in LocationSettings
- Add WorkPreferenceController to support directly use work profile
related feature in xml
- Get only work/personal infos in RecentLocationRequestPreferenceController
and RecentLocationRequestSeeAllPreferenceController
- Remove ProfileSelectStorageFragment
Bug: 141601408
Fixes: 146080649
Test: manual, robolectric
Change-Id: Ide39c7a3796e16421f3a5690309c3d746a956de8
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index bef4f1b..4144914 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -192,19 +192,6 @@
}
/**
- * Returns the UserManager for a given context
- *
- * @throws IllegalStateException if no UserManager could be retrieved.
- */
- public static UserManager getUserManager(Context context) {
- final UserManager um = UserManager.get(context);
- if (um == null) {
- throw new IllegalStateException("Unable to load UserManager");
- }
- return um;
- }
-
- /**
* Returns true if Monkey is running.
*/
public static boolean isMonkeyRunning() {
@@ -679,7 +666,7 @@
* @throws SecurityException if the given userId does not belong to the current user group.
*/
public static int enforceSameOwner(Context context, int userId) {
- final UserManager um = getUserManager(context);
+ final UserManager um = UserManager.get(context);
final int[] profileIds = um.getProfileIdsWithDisabled(UserHandle.myUserId());
if (ArrayUtils.contains(profileIds, userId)) {
return userId;
@@ -699,7 +686,7 @@
* Returns the user id of the credential owner of the given user id.
*/
public static int getCredentialOwnerUserId(Context context, int userId) {
- final UserManager um = getUserManager(context);
+ final UserManager um = UserManager.get(context);
return um.getCredentialOwnerProfile(userId);
}
@@ -836,7 +823,7 @@
}
public static boolean isDemoUser(Context context) {
- return UserManager.isDeviceInDemoMode(context) && getUserManager(context).isDemoUser();
+ return UserManager.isDeviceInDemoMode(context) && UserManager.get(context).isDemoUser();
}
public static ComponentName getDeviceOwnerComponent(Context context) {
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 7215bb7..1985a99 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -13,6 +13,8 @@
*/
package com.android.settings.core;
+import static android.content.Intent.EXTRA_USER_ID;
+
import static com.android.settings.dashboard.DashboardFragment.CATEGORY;
import android.annotation.IntDef;
@@ -20,6 +22,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
+import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SettingsSlicesContract;
@@ -204,7 +207,7 @@
* The status is used for the convenience methods: {@link #isAvailable()},
* {@link #isSupported()}
* </p>
- * The inherited class doesn't need to check work profile is existed or not if
+ * The inherited class doesn't need to check work profile if
* android:forWork="true" is set in preference xml.
*/
@AvailabilityStatus
@@ -337,6 +340,8 @@
if (!mIsForWork || mWorkProfileUser == null) {
return super.handlePreferenceTreeClick(preference);
}
+ final Bundle extra = preference.getExtras();
+ extra.putInt(EXTRA_USER_ID, mWorkProfileUser.getIdentifier());
new SubSettingLauncher(preference.getContext())
.setDestination(preference.getFragment())
.setSourceMetricsCategory(preference.getExtras().getInt(CATEGORY,
diff --git a/src/com/android/settings/core/WorkPreferenceController.java b/src/com/android/settings/core/WorkPreferenceController.java
new file mode 100644
index 0000000..5fdc476
--- /dev/null
+++ b/src/com/android/settings/core/WorkPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 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.core;
+
+import android.content.Context;
+
+import androidx.annotation.CallSuper;
+
+/**
+ * Base class to be used directly in Xml with settings:forWork="true" attribute.
+ * It is used specifically for work profile only preference
+ */
+public class WorkPreferenceController extends BasePreferenceController {
+
+ public WorkPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ /**
+ * Only available when work profile user is existed
+ */
+ @CallSuper
+ public int getAvailabilityStatus() {
+ return getWorkProfileUser() != null ? AVAILABLE : DISABLED_FOR_USER;
+ }
+}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
index 816deca..04fccb3 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
@@ -20,8 +20,8 @@
import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.applications.manageapplications.ManageApplications;
-import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.location.LocationSettings;
+import com.android.settings.location.RecentLocationRequestSeeAllFragment;
import java.util.Map;
@@ -42,9 +42,9 @@
ProfileSelectAccountFragment.class.getName());
FRAGMENT_MAP.put(ManageApplications.class.getName(),
ProfileSelectManageApplications.class.getName());
- FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
- ProfileSelectStorageFragment.class.getName());
FRAGMENT_MAP.put(LocationSettings.class.getName(),
ProfileSelectLocationFragment.class.getName());
+ FRAGMENT_MAP.put(RecentLocationRequestSeeAllFragment.class.getName(),
+ ProfileSelectRecentLocationRequestFragment.class.getName());
}
}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
index 79228c2..9ae8284 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
@@ -16,10 +16,13 @@
package com.android.settings.dashboard.profileselector;
+import static android.content.Intent.EXTRA_USER_ID;
+
import android.annotation.IntDef;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
+import android.os.UserHandle;
import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
@@ -27,6 +30,7 @@
import android.widget.FrameLayout;
import android.widget.LinearLayout;
+import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.recyclerview.widget.RecyclerView;
@@ -97,21 +101,7 @@
Bundle savedInstanceState) {
mContentView = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
final Activity activity = getActivity();
- final int intentUser = activity.getIntent().getContentUserHint();
- int selectedTab = 0;
-
- // Start intent from a specific user eg: adb shell --user 10
- if (intentUser > 0 && Utils.getManagedProfile(UserManager.get(activity)).getIdentifier()
- == intentUser) {
- selectedTab = WORK_TAB;
- }
-
- // Set selected tab using fragment argument
- final int extraTab = getArguments() != null ? getArguments().getInt(
- SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, -1) : -1;
- if (extraTab != -1) {
- selectedTab = extraTab;
- }
+ final int selectedTab = getTabId(activity, getArguments());
final View tabContainer = mContentView.findViewById(R.id.tab_container);
final ViewPager viewPager = tabContainer.findViewById(R.id.view_pager);
@@ -155,6 +145,28 @@
return TAG;
}
+ @VisibleForTesting
+ int getTabId(Activity activity, Bundle bundle) {
+ if (bundle != null) {
+ final int extraTab = bundle.getInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, -1);
+ if (extraTab != -1) {
+ return WORK_TAB;
+ }
+ final int userId = bundle.getInt(EXTRA_USER_ID, UserHandle.SYSTEM.getIdentifier());
+ final boolean isWorkProfile = UserManager.get(activity).isManagedProfile(userId);
+ if (isWorkProfile) {
+ return WORK_TAB;
+ }
+ }
+ // Start intent from a specific user eg: adb shell --user 10
+ final int intentUser = activity.getIntent().getContentUserHint();
+ if (UserManager.get(activity).isManagedProfile(intentUser)) {
+ return WORK_TAB;
+ }
+
+ return PERSONAL_TAB;
+ }
+
static class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final Fragment[] mChildFragments;
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java
index b256157..0d7c4d0 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java
@@ -46,9 +46,19 @@
@Override
public Fragment[] getFragments() {
+
+ final Bundle workOnly = new Bundle();
+ workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.WORK);
+ final Fragment workFragment = new LocationWorkProfileSettings();
+ workFragment.setArguments(workOnly);
+
+ final Bundle personalOnly = new Bundle();
+ personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
+ final Fragment personalFragment = new LocationPersonalSettings();
+ personalFragment.setArguments(personalOnly);
return new Fragment[]{
- new LocationPersonalSettings(),
- new LocationWorkProfileSettings()
+ personalFragment,
+ workFragment
};
}
}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java
new file mode 100644
index 0000000..058ffe4
--- /dev/null
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2019 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.RecentLocationRequestSeeAllFragment;
+
+/**
+ * Recent location request page for personal/managed profile.
+ */
+public class ProfileSelectRecentLocationRequestFragment extends ProfileSelectFragment {
+
+ @Override
+ public Fragment[] getFragments() {
+ final Bundle workOnly = new Bundle();
+ workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.WORK);
+ final Fragment workFragment = new RecentLocationRequestSeeAllFragment();
+ workFragment.setArguments(workOnly);
+
+ final Bundle personalOnly = new Bundle();
+ personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
+ final Fragment personalFragment = new RecentLocationRequestSeeAllFragment();
+ personalFragment.setArguments(personalOnly);
+ return new Fragment[]{
+ personalFragment, //0
+ workFragment
+ };
+ }
+}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
deleted file mode 100644
index bb39cdb..0000000
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2019 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 android.os.UserHandle;
-import android.os.UserManager;
-import android.os.storage.VolumeInfo;
-
-import androidx.fragment.app.Fragment;
-
-import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.deviceinfo.StorageDashboardFragment;
-import com.android.settings.deviceinfo.StorageProfileFragment;
-
-/**
- * Storage Setting page for personal/managed profile.
- */
-public class ProfileSelectStorageFragment extends ProfileSelectFragment {
- @Override
- public Fragment[] getFragments() {
-
- final Bundle storageBundle = new Bundle();
- storageBundle.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
- storageBundle.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
-
- final Fragment storageDashboardFragment = new StorageDashboardFragment();
- storageDashboardFragment.setArguments(storageBundle);
-
- final UserHandle userHandle = Utils.getManagedProfile(UserManager.get(getActivity()));
- if (userHandle != null) {
- storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, userHandle.getIdentifier());
- }
-
- final Fragment storageProfileFragment = new StorageProfileFragment();
- storageProfileFragment.setArguments(storageBundle);
-
- return new Fragment[]{
- storageDashboardFragment,
- storageProfileFragment
- };
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.storage_summary_donut;
- }
-}
-
diff --git a/src/com/android/settings/language/UserDictionaryForWorkPreferenceController.java b/src/com/android/settings/language/UserDictionaryForWorkPreferenceController.java
deleted file mode 100644
index 99d1c2f..0000000
--- a/src/com/android/settings/language/UserDictionaryForWorkPreferenceController.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2019 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.language;
-
-import android.content.Context;
-
-import com.android.settings.core.BasePreferenceController;
-
-/**
- * Preference controller for "UserDictionary for work".
- *
- * @see UserDictionaryPreferenceController
- */
-public final class UserDictionaryForWorkPreferenceController
- extends BasePreferenceController {
-
- public UserDictionaryForWorkPreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
- }
-
- @AvailabilityStatus
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-}
diff --git a/src/com/android/settings/location/LocationPersonalSettings.java b/src/com/android/settings/location/LocationPersonalSettings.java
index 503937e..92796a4 100644
--- a/src/com/android/settings/location/LocationPersonalSettings.java
+++ b/src/com/android/settings/location/LocationPersonalSettings.java
@@ -21,6 +21,7 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
/**
* Location Setting page for personal profile.
@@ -49,9 +50,14 @@
super.onAttach(context);
use(AppLocationPermissionPreferenceController.class).init(this);
- use(RecentLocationRequestPreferenceController.class).init(this);
use(LocationServicePreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
+
+ final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
+ final RecentLocationRequestPreferenceController controller = use(
+ RecentLocationRequestPreferenceController.class);
+ controller.init(this);
+ controller.setProfileType(profileType);
}
@Override
diff --git a/src/com/android/settings/location/LocationWorkProfileSettings.java b/src/com/android/settings/location/LocationWorkProfileSettings.java
index 2c52211..2bf5f98 100644
--- a/src/com/android/settings/location/LocationWorkProfileSettings.java
+++ b/src/com/android/settings/location/LocationWorkProfileSettings.java
@@ -21,6 +21,7 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
/**
* Location Setting page for managed profile.
@@ -49,10 +50,15 @@
super.onAttach(context);
use(AppLocationPermissionPreferenceController.class).init(this);
- use(RecentLocationRequestPreferenceController.class).init(this);
use(LocationServiceForWorkPreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
+
+ final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
+ final RecentLocationRequestPreferenceController controller = use(
+ RecentLocationRequestPreferenceController.class);
+ controller.init(this);
+ controller.setProfileType(profileType);
}
@Override
diff --git a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
index 515df46..d647826 100644
--- a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
@@ -16,6 +16,7 @@
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
+import android.os.UserManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -26,15 +27,20 @@
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.widget.apppreference.AppPreference;
+import java.util.ArrayList;
import java.util.List;
public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController {
- private final RecentLocationApps mRecentLocationApps;
+ public static final int MAX_APPS = 3;
+ @VisibleForTesting
+ RecentLocationApps mRecentLocationApps;
private PreferenceCategory mCategoryRecentLocationRequests;
+ private int mType = ProfileSelectFragment.ProfileType.ALL;
/** Used in this class and {@link RecentLocationRequestSeeAllPreferenceController} */
static class PackageEntryClickedListener implements Preference.OnPreferenceClickListener {
@@ -75,23 +81,27 @@
super.displayPreference(screen);
mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
final Context prefContext = mCategoryRecentLocationRequests.getContext();
- final List<RecentLocationApps.Request> recentLocationRequests =
- mRecentLocationApps.getAppListSorted(false);
- if (recentLocationRequests.size() > 3) {
- // Display the top 3 preferences to container in original order.
- for (int i = 0; i < 3; i++) {
- mCategoryRecentLocationRequests.addPreference(
- createAppPreference(prefContext, recentLocationRequests.get(i)));
+ final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
+ final UserManager userManager = UserManager.get(mContext);
+ for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(
+ false /* systemApps */)) {
+ if (isRequestMatchesProfileType(userManager, request, mType)) {
+ recentLocationRequests.add(request);
+ if (recentLocationRequests.size() == MAX_APPS) {
+ break;
+ }
}
- } else if (recentLocationRequests.size() > 0) {
+ }
+
+ if (recentLocationRequests.size() > 0) {
// Add preferences to container in original order (already sorted by recency).
for (RecentLocationApps.Request request : recentLocationRequests) {
mCategoryRecentLocationRequests.addPreference(
- createAppPreference(prefContext, request));
+ createAppPreference(prefContext, request, mFragment));
}
} else {
// If there's no item to display, add a "No recent apps" item.
- final Preference banner = createAppPreference(prefContext);
+ final Preference banner = new AppPreference(prefContext);
banner.setTitle(R.string.location_no_recent_apps);
banner.setSelectable(false);
mCategoryRecentLocationRequests.addPreference(banner);
@@ -103,19 +113,42 @@
mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode));
}
- @VisibleForTesting
- AppPreference createAppPreference(Context prefContext) {
- return new AppPreference(prefContext);
+ /**
+ * Initialize {@link ProfileSelectFragment.ProfileType} of the controller
+ *
+ * @param type {@link ProfileSelectFragment.ProfileType} of the controller.
+ */
+ public void setProfileType(@ProfileSelectFragment.ProfileType int type) {
+ mType = type;
}
- @VisibleForTesting
- AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request) {
- final AppPreference pref = createAppPreference(prefContext);
- pref.setSummary(request.contentDescription);
+ /**
+ * Create a {@link AppPreference}
+ */
+ public static AppPreference createAppPreference(Context prefContext,
+ RecentLocationApps.Request request, DashboardFragment fragment) {
+ final AppPreference pref = new AppPreference(prefContext);
pref.setIcon(request.icon);
pref.setTitle(request.label);
pref.setOnPreferenceClickListener(new PackageEntryClickedListener(
- mFragment, request.packageName, request.userHandle));
+ fragment, request.packageName, request.userHandle));
return pref;
}
+
+ /**
+ * Return if the {@link RecentLocationApps.Request} matches current UI
+ * {@ProfileSelectFragment.ProfileType}
+ */
+ public static boolean isRequestMatchesProfileType(UserManager userManager,
+ RecentLocationApps.Request request, @ProfileSelectFragment.ProfileType int type) {
+ final boolean isWorkProfile = userManager.isManagedProfile(
+ request.userHandle.getIdentifier());
+ if (isWorkProfile && (type & ProfileSelectFragment.ProfileType.WORK) != 0) {
+ return true;
+ }
+ if (!isWorkProfile && (type & ProfileSelectFragment.ProfileType.PERSONAL) != 0) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java b/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java
index fc2a5fe..48a6aec 100644
--- a/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java
+++ b/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java
@@ -23,6 +23,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@@ -49,9 +50,11 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
mController = use(RecentLocationRequestSeeAllPreferenceController.class);
mController.init(this);
+ mController.setProfileType(profileType);
}
@Override
diff --git a/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java
index 4ed9d13..df0fa40 100644
--- a/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java
@@ -15,16 +15,21 @@
*/
package com.android.settings.location;
-import android.content.Context;
+import static com.android.settings.location.RecentLocationRequestPreferenceController.createAppPreference;
+import static com.android.settings.location.RecentLocationRequestPreferenceController.isRequestMatchesProfileType;
-import androidx.annotation.VisibleForTesting;
+import android.content.Context;
+import android.os.UserManager;
+
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.widget.apppreference.AppPreference;
+import java.util.ArrayList;
import java.util.List;
/** Preference controller for preference category displaying all recent location requests. */
@@ -35,6 +40,7 @@
private RecentLocationApps mRecentLocationApps;
private boolean mShowSystem = false;
private Preference mPreference;
+ private int mType = ProfileSelectFragment.ProfileType.ALL;
public RecentLocationRequestSeeAllPreferenceController(Context context, String key) {
super(context, key);
@@ -56,33 +62,39 @@
public void updateState(Preference preference) {
mCategoryAllRecentLocationRequests.removeAll();
mPreference = preference;
- List<RecentLocationApps.Request> requests = mRecentLocationApps.getAppListSorted(
- mShowSystem);
- if (requests.isEmpty()) {
+
+ final UserManager userManager = UserManager.get(mContext);
+ final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
+ for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(
+ mShowSystem)) {
+ if (isRequestMatchesProfileType(userManager, request, mType)) {
+ recentLocationRequests.add(request);
+ }
+ }
+
+ if (recentLocationRequests.isEmpty()) {
// If there's no item to display, add a "No recent apps" item.
final Preference banner = new AppPreference(mContext);
banner.setTitle(R.string.location_no_recent_apps);
banner.setSelectable(false);
mCategoryAllRecentLocationRequests.addPreference(banner);
} else {
- for (RecentLocationApps.Request request : requests) {
- Preference appPreference = createAppPreference(preference.getContext(), request);
+ for (RecentLocationApps.Request request : recentLocationRequests) {
+ final Preference appPreference = createAppPreference(
+ preference.getContext(),
+ request, mFragment);
mCategoryAllRecentLocationRequests.addPreference(appPreference);
}
}
}
- @VisibleForTesting
- AppPreference createAppPreference(
- Context prefContext, RecentLocationApps.Request request) {
- final AppPreference pref = new AppPreference(prefContext);
- pref.setSummary(request.contentDescription);
- pref.setIcon(request.icon);
- pref.setTitle(request.label);
- pref.setOnPreferenceClickListener(
- new RecentLocationRequestPreferenceController.PackageEntryClickedListener(
- mFragment, request.packageName, request.userHandle));
- return pref;
+ /**
+ * Initialize {@link ProfileSelectFragment.ProfileType} of the controller
+ *
+ * @param type {@link ProfileSelectFragment.ProfileType} of the controller.
+ */
+ public void setProfileType(@ProfileSelectFragment.ProfileType int type) {
+ mType = type;
}
public void setShowSystem(boolean showSystem) {