Search in sources :

Example 6 with LocationFudger

use of com.android.server.location.LocationFudger in project android_frameworks_base by DirtyUnicorns.

the class LocationManagerService method systemRunning.

public void systemRunning() {
    synchronized (mLock) {
        if (D)
            Log.d(TAG, "systemRunning()");
        // fetch package manager
        mPackageManager = mContext.getPackageManager();
        // fetch power manager
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        // prepare worker thread
        mLocationHandler = new LocationWorkerHandler(BackgroundThread.get().getLooper());
        // prepare mLocationHandler's dependents
        mLocationFudger = new LocationFudger(mContext, mLocationHandler);
        mBlacklist = new LocationBlacklist(mContext, mLocationHandler);
        mBlacklist.init();
        mGeofenceManager = new GeofenceManager(mContext, mBlacklist);
        // Monitor for app ops mode changes.
        AppOpsManager.OnOpChangedListener callback = new AppOpsManager.OnOpChangedInternalListener() {

            public void onOpChanged(int op, String packageName) {
                synchronized (mLock) {
                    for (Receiver receiver : mReceivers.values()) {
                        receiver.updateMonitoring(true);
                    }
                    applyAllProviderRequirementsLocked();
                }
            }
        };
        mAppOps.startWatchingMode(AppOpsManager.OP_COARSE_LOCATION, null, callback);
        PackageManager.OnPermissionsChangedListener permissionListener = new PackageManager.OnPermissionsChangedListener() {

            @Override
            public void onPermissionsChanged(final int uid) {
                synchronized (mLock) {
                    applyAllProviderRequirementsLocked();
                }
            }
        };
        mPackageManager.addOnPermissionsChangeListener(permissionListener);
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        updateUserProfiles(mCurrentUserId);
        // prepare providers
        loadProvidersLocked();
        updateProvidersLocked();
    }
    // listen for settings changes
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true, new ContentObserver(mLocationHandler) {

        @Override
        public void onChange(boolean selfChange) {
            synchronized (mLock) {
                updateProvidersLocked();
            }
        }
    }, UserHandle.USER_ALL);
    mPackageMonitor.register(mContext, mLocationHandler.getLooper(), true);
    // listen for user change
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
    intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
    intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
    intentFilter.addAction(Intent.ACTION_SHUTDOWN);
    mContext.registerReceiverAsUser(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
            } else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action) || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
                updateUserProfiles(mCurrentUserId);
            } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
                // shutdown only if UserId indicates whole system, not just one user
                if (D)
                    Log.d(TAG, "Shutdown received with UserId: " + getSendingUserId());
                if (getSendingUserId() == UserHandle.USER_ALL) {
                    shutdownComponents();
                }
            }
        }
    }, UserHandle.ALL, intentFilter, null, mLocationHandler);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) LocationBlacklist(com.android.server.location.LocationBlacklist) GeofenceManager(com.android.server.location.GeofenceManager) BroadcastReceiver(android.content.BroadcastReceiver) LocationFudger(com.android.server.location.LocationFudger) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AppOpsManager(android.app.AppOpsManager) PackageManager(android.content.pm.PackageManager) ContentObserver(android.database.ContentObserver)

Aggregations

AppOpsManager (android.app.AppOpsManager)6 PendingIntent (android.app.PendingIntent)6 BroadcastReceiver (android.content.BroadcastReceiver)6 Context (android.content.Context)6 Intent (android.content.Intent)6 IntentFilter (android.content.IntentFilter)6 ContentObserver (android.database.ContentObserver)6 GeofenceManager (com.android.server.location.GeofenceManager)6 LocationBlacklist (com.android.server.location.LocationBlacklist)6 LocationFudger (com.android.server.location.LocationFudger)6 PackageManager (android.content.pm.PackageManager)5 HandlerThread (android.os.HandlerThread)1