Search in sources :

Example 11 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by AOSPA.

the class ExternalSharedPermsTest method testRunLocationAndBluetooth.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunLocationAndBluetooth() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 12 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by AOSPA.

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunBluetoothAndFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 13 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by AOSPA.

the class LocationBasedCountryDetector method detectCountry.

/**
     * Start detecting the country.
     * <p>
     * Queries the location from all location providers, then starts a thread to query the
     * country from GeoCoder.
     */
@Override
public synchronized Country detectCountry() {
    if (mLocationListeners != null) {
        throw new IllegalStateException();
    }
    // Request the location from all enabled providers.
    List<String> enabledProviders = getEnabledProviders();
    int totalProviders = enabledProviders.size();
    if (totalProviders > 0) {
        mLocationListeners = new ArrayList<LocationListener>(totalProviders);
        for (int i = 0; i < totalProviders; i++) {
            String provider = enabledProviders.get(i);
            if (isAcceptableProvider(provider)) {
                LocationListener listener = new LocationListener() {

                    @Override
                    public void onLocationChanged(Location location) {
                        if (location != null) {
                            LocationBasedCountryDetector.this.stop();
                            queryCountryCode(location);
                        }
                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                    }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                    }
                };
                mLocationListeners.add(listener);
                registerListener(provider, listener);
            }
        }
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                mTimer = null;
                LocationBasedCountryDetector.this.stop();
                // Looks like no provider could provide the location, let's try the last
                // known location.
                queryCountryCode(getLastKnownLocation());
            }
        }, getQueryLocationTimeout());
    } else {
        // There is no provider enabled.
        queryCountryCode(getLastKnownLocation());
    }
    return mDetectedCountry;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 14 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by ResurrectionRemix.

the class ExternalSharedPermsTest method testRunLocationAndBluetooth.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunLocationAndBluetooth() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 15 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by ResurrectionRemix.

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunBluetoothAndFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Aggregations

LocationListener (android.location.LocationListener)41 Location (android.location.Location)34 Bundle (android.os.Bundle)34 LocationManager (android.location.LocationManager)22 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 Timer (java.util.Timer)6 TimerTask (java.util.TimerTask)6 Criteria (android.location.Criteria)5 IOException (java.io.IOException)3 Intent (android.content.Intent)2 Point (com.esri.core.geometry.Point)2 FacebookException (com.facebook.FacebookException)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 CanceledException (android.app.PendingIntent.CanceledException)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 GpsSatellite (android.location.GpsSatellite)1 GpsStatus (android.location.GpsStatus)1