Example usage for android.app AppOpsManager OPSTR_MOCK_LOCATION

List of usage examples for android.app AppOpsManager OPSTR_MOCK_LOCATION

Introduction

In this page you can find the example usage for android.app AppOpsManager OPSTR_MOCK_LOCATION.

Prototype

String OPSTR_MOCK_LOCATION

To view the source code for android.app AppOpsManager OPSTR_MOCK_LOCATION.

Click Source Link

Document

Inject mock location into the system.

Usage

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

public boolean isMockLocationEnabled() {
    // Checks if mock location is enabled in settings

    boolean isMockLocation;

    try {//  w  w  w  . ja va 2  s  .c o m
        //If marshmallow or higher then we need to check that this app is set as the provider
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            AppOpsManager opsManager = (AppOpsManager) appContext.getSystemService(Context.APP_OPS_SERVICE);
            isMockLocation = opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(),
                    BuildConfig.APPLICATION_ID) == AppOpsManager.MODE_ALLOWED;

        } else {
            // Anything below it then we just need to check the tickbox is checked.
            isMockLocation = !android.provider.Settings.Secure
                    .getString(appContext.getContentResolver(), "mock_location").equals("0");
        }

    } catch (Exception e) {
        return false;
    }

    return isMockLocation;
}