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

Commit b53efae0 authored by Stanley Wang's avatar Stanley Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix security issue for using mock location without permission."

parents 5a5ca79a cdf40281
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -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) {
+10 −3
Original line number Original line Diff line number Diff line
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());
    }
    }