Make the show/hide system setting for recent location acccesses sticky.
This is in order to align the location indicator with the list of recent accesses shown in Settings. Bug: 191503437 Test: manual Change-Id: I7aaa65390567ca644e7137de15c558cdcdb29935
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.icu.text.RelativeDateTimeFormatter;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -85,11 +86,17 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mCategoryRecentLocationRequests.removeAll();
|
||||
final Context prefContext = mCategoryRecentLocationRequests.getContext();
|
||||
final List<RecentAppOpsAccess.Access> recentLocationAccesses = new ArrayList<>();
|
||||
final UserManager userManager = UserManager.get(mContext);
|
||||
for (RecentAppOpsAccess.Access access : mRecentLocationApps.getAppListSorted(
|
||||
/* showSystemApps= */ false)) {
|
||||
final boolean showSystem = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
|
||||
for (RecentAppOpsAccess.Access access : mRecentLocationApps.getAppListSorted(showSystem)) {
|
||||
if (isRequestMatchesProfileType(userManager, access, mType)) {
|
||||
recentLocationAccesses.add(access);
|
||||
if (recentLocationAccesses.size() == MAX_APPS) {
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -36,7 +37,6 @@ public class RecentLocationAccessSeeAllFragment extends DashboardFragment {
|
||||
|
||||
private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 1;
|
||||
private static final int MENU_HIDE_SYSTEM = Menu.FIRST + 2;
|
||||
private static final String EXTRA_SHOW_SYSTEM = "show_system";
|
||||
|
||||
private boolean mShowSystem = false;
|
||||
private MenuItem mShowSystemMenu;
|
||||
@@ -58,18 +58,8 @@ public class RecentLocationAccessSeeAllFragment extends DashboardFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||
}
|
||||
if (mController != null) {
|
||||
mController.setShowSystem(mShowSystem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||
mShowSystem = Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +78,8 @@ public class RecentLocationAccessSeeAllFragment extends DashboardFragment {
|
||||
case MENU_SHOW_SYSTEM:
|
||||
case MENU_HIDE_SYSTEM:
|
||||
mShowSystem = menuItem.getItemId() == MENU_SHOW_SYSTEM;
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, mShowSystem ? 1 : 0);
|
||||
updateMenu();
|
||||
if (mController != null) {
|
||||
mController.setShowSystem(mShowSystem);
|
||||
|
@@ -20,6 +20,7 @@ import static com.android.settings.location.RecentLocationAccessPreferenceContro
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -43,6 +44,8 @@ public class RecentLocationAccessSeeAllPreferenceController
|
||||
|
||||
public RecentLocationAccessSeeAllPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mShowSystem = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
|
||||
mRecentLocationAccesses = RecentAppOpsAccess.createForLocation(context);
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -83,8 +84,11 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
final Context prefContext = mCategoryRecentLocationRequests.getContext();
|
||||
final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
|
||||
final UserManager userManager = UserManager.get(mContext);
|
||||
final boolean showSystem = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
|
||||
|
||||
for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(
|
||||
false /* systemApps */)) {
|
||||
showSystem)) {
|
||||
if (isRequestMatchesProfileType(userManager, request, mType)) {
|
||||
recentLocationRequests.add(request);
|
||||
if (recentLocationRequests.size() == MAX_APPS) {
|
||||
|
@@ -19,9 +19,12 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@@ -34,12 +37,15 @@ import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settingslib.applications.RecentAppOpsAccess;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -107,4 +113,20 @@ public class RecentLocationAccessPreferenceControllerTest {
|
||||
mContext.getText(R.string.location_recent_location_access_view_details));
|
||||
assertThat(details.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
|
||||
/** Verifies the title text, details text are correct, and the click listener is set. */
|
||||
@Test
|
||||
public void updateState_showSystemAccess() {
|
||||
doReturn(ImmutableList.of(
|
||||
new RecentAppOpsAccess.Access("app", UserHandle.CURRENT, null, "app", "", 0)))
|
||||
.when(mRecentLocationApps).getAppListSorted(false);
|
||||
doReturn(new ArrayList<>()).when(mRecentLocationApps).getAppListSorted(true);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mLayoutPreference);
|
||||
verify(mLayoutPreference).addPreference(Mockito.any());
|
||||
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(), Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 1);
|
||||
verify(mLayoutPreference, Mockito.times(1)).addPreference(Mockito.any());
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -81,6 +82,25 @@ public class RecentLocationRequestPreferenceControllerTest {
|
||||
verify(mCategory, times(3)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_whenAppListMoreThanThree_showSystem() {
|
||||
when(mController.mRecentLocationApps.getAppListSorted(false))
|
||||
.thenReturn(createMockRequest(2));
|
||||
when(mController.mRecentLocationApps.getAppListSorted(true))
|
||||
.thenReturn(createMockRequest(3));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mCategory, times(2)).addPreference(any());
|
||||
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS,
|
||||
1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mCategory, times(5)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_workProfile_shouldShowOnlyWorkProfileApps() {
|
||||
final List<RecentLocationApps.Request> requests = createMockRequest(6);
|
||||
|
Reference in New Issue
Block a user