Search in sources :

Example 61 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class LocationManagerService method systemReady.

public void systemReady() {
    synchronized (mLock) {
        if (D)
            Log.d(TAG, "systemReady()");
        // fetch package manager
        mPackageManager = mContext.getPackageManager();
        // fetch power manager
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        // prepare worker thread
        mHandlerThread = new HandlerThread(THREAD_NAME, Process.THREAD_PRIORITY_BACKGROUND);
        mHandlerThread.start();
        mLocationHandler = new LocationWorkerHandler(mHandlerThread.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.Callback callback = new AppOpsManager.Callback() {

            public void opChanged(int op, String packageName) {
                synchronized (mLock) {
                    applyAllProviderRequirementsLocked();
                }
            }
        };
        mAppOps.startWatchingMode(AppOpsManager.OP_COARSE_LOCATION, null, callback);
        // 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);
    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));
            }
        }
    }, 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) LocationFudger(com.android.server.location.LocationFudger) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AppOpsManager(android.app.AppOpsManager) HandlerThread(android.os.HandlerThread) ContentObserver(android.database.ContentObserver)

Example 62 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class WifiService method registerForScanModeChange.

/**
     * Observes settings changes to scan always mode.
     */
private void registerForScanModeChange() {
    ContentObserver contentObserver = new ContentObserver(null) {

        @Override
        public void onChange(boolean selfChange) {
            mSettingsStore.handleWifiScanAlwaysAvailableToggled();
            mWifiController.sendMessage(CMD_SCAN_ALWAYS_MODE_CHANGED);
        }
    };
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE), false, contentObserver);
}
Also used : ContentObserver(android.database.ContentObserver)

Example 63 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class WifiController method registerForStayAwakeModeChange.

/**
     * Observes settings changes to scan always mode.
     */
private void registerForStayAwakeModeChange(Handler handler) {
    ContentObserver contentObserver = new ContentObserver(handler) {

        @Override
        public void onChange(boolean selfChange) {
            readStayAwakeConditions();
        }
    };
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.STAY_ON_WHILE_PLUGGED_IN), false, contentObserver);
}
Also used : ContentObserver(android.database.ContentObserver)

Example 64 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class WifiController method registerForWifiSleepPolicyChange.

/**
     * Observes changes to wifi sleep policy
     */
private void registerForWifiSleepPolicyChange(Handler handler) {
    ContentObserver contentObserver = new ContentObserver(handler) {

        @Override
        public void onChange(boolean selfChange) {
            readWifiSleepPolicy();
        }
    };
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.WIFI_SLEEP_POLICY), false, contentObserver);
}
Also used : ContentObserver(android.database.ContentObserver)

Example 65 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class WifiWatchdogStateMachine method registerForWatchdogToggle.

/**
     * Observes the watchdog on/off setting, and takes action when changed.
     */
private void registerForWatchdogToggle() {
    ContentObserver contentObserver = new ContentObserver(this.getHandler()) {

        @Override
        public void onChange(boolean selfChange) {
            sendMessage(EVENT_WATCHDOG_TOGGLED);
        }
    };
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.WIFI_WATCHDOG_ON), false, contentObserver);
}
Also used : ContentObserver(android.database.ContentObserver)

Aggregations

ContentObserver (android.database.ContentObserver)96 Handler (android.os.Handler)41 Uri (android.net.Uri)35 ContentResolver (android.content.ContentResolver)28 Intent (android.content.Intent)16 IntentFilter (android.content.IntentFilter)16 BroadcastReceiver (android.content.BroadcastReceiver)9 Context (android.content.Context)9 PendingIntent (android.app.PendingIntent)7 RemoteException (android.os.RemoteException)7 Test (org.junit.Test)7 AppOpsManager (android.app.AppOpsManager)6 GeofenceManager (com.android.server.location.GeofenceManager)6 LocationBlacklist (com.android.server.location.LocationBlacklist)6 LocationFudger (com.android.server.location.LocationFudger)6 HashSet (java.util.HashSet)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Mockito.doAnswer (org.mockito.Mockito.doAnswer)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Answer (org.mockito.stubbing.Answer)6