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
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
|
||||
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 @@ public class LocationPersonalSettings extends DashboardFragment {
|
||||
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
|
||||
|
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
|
||||
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 @@ public class LocationWorkProfileSettings extends DashboardFragment {
|
||||
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
|
||||
|
@@ -16,6 +16,7 @@ package com.android.settings.location;
|
||||
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.R;
|
||||
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 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
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 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import android.view.MenuItem;
|
||||
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 @@ public class RecentLocationRequestSeeAllFragment extends DashboardFragment {
|
||||
@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
|
||||
|
@@ -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 android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
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 @@ public class RecentLocationRequestSeeAllPreferenceController
|
||||
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 class RecentLocationRequestSeeAllPreferenceController
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user