Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdf40281 authored by Stanley Wang's avatar Stanley Wang
Browse files

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
parent cf4e12bb
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

import com.android.settings.R;
@@ -86,6 +87,12 @@ public class MockLocationAppPreferenceController extends DeveloperOptionsPrefere
        return true;
    }

    @Override
    public void onDeveloperOptionsDisabled() {
        super.onDeveloperOptionsDisabled();
        removeAllMockLocations();
    }

    private void updateMockLocation() {
        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(
                MOCK_LOCATION_APP_OPS);
        if (packageOps != null) {
+10 −3
Original line number Diff line number Diff line
package com.android.settings.development;

import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes
        .REQUEST_MOCK_LOCATION_APP;
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_MOCK_LOCATION_APP;

import static com.google.common.truth.Truth.assertThat;

@@ -20,7 +19,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Pair;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -145,6 +143,15 @@ public class MockLocationAppPreferenceControllerTest {
        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) {
        return new OpEntry(0, opMode, Collections.emptyMap());
    }