Search in sources :

Example 86 with ContentObserver

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

the class PowerUI method start.

public void start() {
    mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mHardwarePropertiesManager = (HardwarePropertiesManager) mContext.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE);
    mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime();
    mWarnings = new PowerNotificationWarnings(mContext, getComponent(PhoneStatusBar.class));
    ContentObserver obs = new ContentObserver(mHandler) {

        @Override
        public void onChange(boolean selfChange) {
            updateBatteryWarningLevels();
        }
    };
    final ContentResolver resolver = mContext.getContentResolver();
    resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), false, obs, UserHandle.USER_ALL);
    updateBatteryWarningLevels();
    mReceiver.init();
    initTemperatureWarning();
}
Also used : ContentObserver(android.database.ContentObserver) ContentResolver(android.content.ContentResolver)

Example 87 with ContentObserver

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

the class DevicePolicyManagerServiceTestable method notifyChangeToContentObserver.

public void notifyChangeToContentObserver(Uri uri, int userHandle) {
    ContentObserver co = mMockInjector.mContentObservers.get(new Pair<Uri, Integer>(uri, userHandle));
    if (co != null) {
        // notify synchronously
        co.onChange(false, uri, userHandle);
    }
    // Notify USER_ALL observer too.
    co = mMockInjector.mContentObservers.get(new Pair<Uri, Integer>(uri, UserHandle.USER_ALL));
    if (co != null) {
        // notify synchronously
        co.onChange(false, uri, userHandle);
    }
}
Also used : Uri(android.net.Uri) ContentObserver(android.database.ContentObserver) Pair(android.util.Pair)

Example 88 with ContentObserver

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

the class ContentQueryMap method setKeepUpdated.

/**
     * Change whether or not the ContentQueryMap will register with the cursor's ContentProvider 
     * for change notifications. If you use a ContentQueryMap in an activity you should call this
     * with false in onPause(), which means you need to call it with true in onResume()
     * if want it to be kept updated.
     * @param keepUpdated if true the ContentQueryMap should be registered with the cursor's
     * ContentProvider, false otherwise
     */
public void setKeepUpdated(boolean keepUpdated) {
    if (keepUpdated == mKeepUpdated)
        return;
    mKeepUpdated = keepUpdated;
    if (!mKeepUpdated) {
        mCursor.unregisterContentObserver(mContentObserver);
        mContentObserver = null;
    } else {
        if (mHandlerForUpdateNotifications == null) {
            mHandlerForUpdateNotifications = new Handler();
        }
        if (mContentObserver == null) {
            mContentObserver = new ContentObserver(mHandlerForUpdateNotifications) {

                @Override
                public void onChange(boolean selfChange) {
                    // let it query lazily when they ask for the values.
                    if (countObservers() != 0) {
                        requery();
                    } else {
                        mDirty = true;
                    }
                }
            };
        }
        mCursor.registerContentObserver(mContentObserver);
        // mark dirty, since it is possible the cursor's backing data had changed before we 
        // registered for changes
        mDirty = true;
    }
}
Also used : Handler(android.os.Handler) ContentObserver(android.database.ContentObserver)

Example 89 with ContentObserver

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

the class DropBoxManagerService method onStart.

@Override
public void onStart() {
    // Set up intent receivers
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    getContext().registerReceiver(mReceiver, filter);
    mContentResolver.registerContentObserver(Settings.Global.CONTENT_URI, true, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            mReceiver.onReceive(getContext(), (Intent) null);
        }
    });
    publishBinderService(Context.DROPBOX_SERVICE, mStub);
// The real work gets done lazily in init() -- that way service creation always
// succeeds, and things like disk problems cause individual method failures.
}
Also used : IntentFilter(android.content.IntentFilter) Handler(android.os.Handler) Intent(android.content.Intent) ContentObserver(android.database.ContentObserver)

Example 90 with ContentObserver

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

the class BluetoothManagerService method registerForBleScanModeChange.

// Monitor change of BLE scan only mode settings.
private void registerForBleScanModeChange() {
    ContentObserver contentObserver = new ContentObserver(null) {

        @Override
        public void onChange(boolean selfChange) {
            if (isBleScanAlwaysAvailable()) {
                // Nothing to do
                return;
            }
            // BLE scan is not available.
            disableBleScanMode();
            clearBleApps();
            try {
                mBluetoothLock.readLock().lock();
                if (mBluetooth != null)
                    mBluetooth.onBrEdrDown();
            } catch (RemoteException e) {
                Slog.e(TAG, "error when disabling bluetooth", e);
            } finally {
                mBluetoothLock.readLock().unlock();
            }
        }
    };
    mContentResolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE), false, contentObserver);
}
Also used : RemoteException(android.os.RemoteException) ContentObserver(android.database.ContentObserver)

Aggregations

ContentObserver (android.database.ContentObserver)94 Handler (android.os.Handler)40 Uri (android.net.Uri)33 ContentResolver (android.content.ContentResolver)28 Intent (android.content.Intent)15 IntentFilter (android.content.IntentFilter)15 BroadcastReceiver (android.content.BroadcastReceiver)8 Context (android.content.Context)8 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