Fix security issue for using mock location without permission.
Remove mock location apps if developer option is disabled. Change-Id: Iad32ea336376eeb923f6d4424fd85c2da2bb5128 Bugs: 145136060 Test: manual
This commit is contained in:
@@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -86,6 +87,12 @@ public class MockLocationAppPreferenceController extends DeveloperOptionsPrefere
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeveloperOptionsDisabled() {
|
||||||
|
super.onDeveloperOptionsDisabled();
|
||||||
|
removeAllMockLocations();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMockLocation() {
|
private void updateMockLocation() {
|
||||||
final String mockLocationApp = getCurrentMockLocationApp();
|
final String mockLocationApp = getCurrentMockLocationApp();
|
||||||
|
|
||||||
@@ -151,7 +158,8 @@ public class MockLocationAppPreferenceController extends DeveloperOptionsPrefere
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCurrentMockLocationApp() {
|
@VisibleForTesting
|
||||||
|
String getCurrentMockLocationApp() {
|
||||||
final List<AppOpsManager.PackageOps> packageOps = mAppsOpsManager.getPackagesForOps(
|
final List<AppOpsManager.PackageOps> packageOps = mAppsOpsManager.getPackagesForOps(
|
||||||
MOCK_LOCATION_APP_OPS);
|
MOCK_LOCATION_APP_OPS);
|
||||||
if (packageOps != null) {
|
if (packageOps != null) {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes
|
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_MOCK_LOCATION_APP;
|
||||||
.REQUEST_MOCK_LOCATION_APP;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -145,6 +143,15 @@ public class MockLocationAppPreferenceControllerTest {
|
|||||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDeveloperOptionsDisabled_currentMockLocationApp_shouldBeNull() {
|
||||||
|
mController.onDeveloperOptionsDisabled();
|
||||||
|
|
||||||
|
final String appName = mController.getCurrentMockLocationApp();
|
||||||
|
|
||||||
|
assertThat(appName).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
private AppOpsManager.OpEntry createOpEntry(int opMode) {
|
private AppOpsManager.OpEntry createOpEntry(int opMode) {
|
||||||
return new OpEntry(0, opMode, Collections.emptyMap());
|
return new OpEntry(0, opMode, Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user