Merge "Use user setting to determine whether or not to show system location accesses."

This commit is contained in:
Kate Montgomery
2022-01-26 15:12:54 +00:00
committed by Android (Google) Code Review
2 changed files with 49 additions and 9 deletions

View File

@@ -30,6 +30,7 @@ import android.content.IntentFilter;
import android.content.PermissionChecker;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.location.LocationManager;
import android.os.Handler;
import android.os.Looper;
@@ -55,6 +56,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.Utils;
import com.android.systemui.util.settings.SecureSettings;
import java.util.ArrayList;
import java.util.List;
@@ -77,17 +79,21 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
private final H mHandler;
private final Handler mBackgroundHandler;
private final PackageManager mPackageManager;
private final ContentObserver mContentObserver;
private final SecureSettings mSecureSettings;
private boolean mAreActiveLocationRequests;
private boolean mShouldDisplayAllAccesses;
private boolean mShowSystemAccesses;
private boolean mShowSystemAccessesFlag;
private boolean mShowSystemAccessesSetting;
@Inject
public LocationControllerImpl(Context context, AppOpsController appOpsController,
DeviceConfigProxy deviceConfigProxy,
@Main Looper mainLooper, @Background Handler backgroundHandler,
BroadcastDispatcher broadcastDispatcher, BootCompleteCache bootCompleteCache,
UserTracker userTracker, PackageManager packageManager, UiEventLogger uiEventLogger) {
UserTracker userTracker, PackageManager packageManager, UiEventLogger uiEventLogger,
SecureSettings secureSettings) {
mContext = context;
mAppOpsController = appOpsController;
mDeviceConfigProxy = deviceConfigProxy;
@@ -95,10 +101,22 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
mHandler = new H(mainLooper);
mUserTracker = userTracker;
mUiEventLogger = uiEventLogger;
mSecureSettings = secureSettings;
mBackgroundHandler = backgroundHandler;
mPackageManager = packageManager;
mShouldDisplayAllAccesses = getAllAccessesSetting();
mShowSystemAccesses = getShowSystemSetting();
mShowSystemAccessesFlag = getShowSystemFlag();
mShowSystemAccessesSetting = getShowSystemSetting();
mContentObserver = new ContentObserver(mBackgroundHandler) {
@Override
public void onChange(boolean selfChange) {
mShowSystemAccessesSetting = getShowSystemSetting();
}
};
// Register to listen for changes in Settings.Secure settings.
mSecureSettings.registerContentObserver(
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, mContentObserver);
// Register to listen for changes in DeviceConfig settings.
mDeviceConfigProxy.addOnPropertiesChangedListener(
@@ -106,7 +124,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
backgroundHandler::post,
properties -> {
mShouldDisplayAllAccesses = getAllAccessesSetting();
mShowSystemAccesses = getShowSystemSetting();
mShowSystemAccessesFlag = getShowSystemSetting();
updateActiveLocationRequests();
});
@@ -195,10 +213,15 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_SMALL_ENABLED, false);
}
private boolean getShowSystemSetting() {
private boolean getShowSystemFlag() {
return mDeviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_SHOW_SYSTEM, false);
}
private boolean getShowSystemSetting() {
return mSecureSettings.getInt(Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
}
/**
* Returns true if there currently exist active high power location requests.
*/
@@ -226,6 +249,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
}
boolean hadActiveLocationRequests = mAreActiveLocationRequests;
boolean shouldDisplay = false;
boolean showSystem = mShowSystemAccessesFlag || mShowSystemAccessesSetting;
boolean systemAppOp = false;
boolean nonSystemAppOp = false;
boolean isSystemApp;
@@ -243,7 +267,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
nonSystemAppOp = true;
}
shouldDisplay = mShowSystemAccesses || shouldDisplay || !isSystemApp;
shouldDisplay = showSystem || shouldDisplay || !isSystemApp;
}
}

View File

@@ -29,6 +29,7 @@ import android.location.LocationManager;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
@@ -46,6 +47,7 @@ import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.DeviceConfigProxyFake;
import com.android.systemui.util.settings.SecureSettings;
import com.google.common.collect.ImmutableList;
@@ -67,6 +69,7 @@ public class LocationControllerImplTest extends SysuiTestCase {
@Mock private AppOpsController mAppOpsController;
@Mock private UserTracker mUserTracker;
@Mock private SecureSettings mSecureSettings;
@Before
public void setup() {
@@ -88,7 +91,8 @@ public class LocationControllerImplTest extends SysuiTestCase {
mock(BootCompleteCache.class),
mUserTracker,
mContext.getPackageManager(),
mUiEventLogger);
mUiEventLogger,
mSecureSettings);
mTestableLooper.processAllMessages();
}
@@ -204,7 +208,7 @@ public class LocationControllerImplTest extends SysuiTestCase {
}
@Test
public void testCallbackNotified_additionalOps_shouldShowSystem() {
public void testCallbackNotified_additionalOps_shouldNotShowSystem() {
LocationChangeCallback callback = mock(LocationChangeCallback.class);
mLocationController.addCallback(callback);
mDeviceConfigProxy.setProperty(
@@ -229,7 +233,9 @@ public class LocationControllerImplTest extends SysuiTestCase {
@Test
public void testCallbackNotified_additionalOps_shouldNotShowSystem() {
public void testCallbackNotified_additionalOps_shouldShowSystem() {
when(mSecureSettings.getInt(Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0))
.thenReturn(1);
LocationChangeCallback callback = mock(LocationChangeCallback.class);
mLocationController.addCallback(callback);
mDeviceConfigProxy.setProperty(
@@ -261,6 +267,16 @@ public class LocationControllerImplTest extends SysuiTestCase {
mTestableLooper.processAllMessages();
verify(callback, times(1)).onLocationActiveChanged(false);
when(mSecureSettings.getInt(Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0))
.thenReturn(0);
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
"com.google.android.gms", true);
mTestableLooper.processAllMessages();
// onLocationActive(true) was not called again because the setting is disabled.
verify(callback, times(1)).onLocationActiveChanged(true);
}
@Test