Search in sources :

Example 91 with ContentObserver

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

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 92 with ContentObserver

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

the class BatteryService method onBootPhase.

@Override
public void onBootPhase(int phase) {
    if (phase == PHASE_ACTIVITY_MANAGER_READY) {
        // check our power situation now that it is safe to display the shutdown dialog.
        synchronized (mLock) {
            ContentObserver obs = new ContentObserver(mHandler) {

                @Override
                public void onChange(boolean selfChange) {
                    synchronized (mLock) {
                        updateBatteryWarningLevelLocked();
                    }
                }
            };
            final ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), false, obs, UserHandle.USER_ALL);
            updateBatteryWarningLevelLocked();
        }
    } else if (phase == PHASE_BOOT_COMPLETED) {
        SettingsObserver observer = new SettingsObserver(new Handler());
        observer.observe();
    }
}
Also used : Handler(android.os.Handler) ContentObserver(android.database.ContentObserver) ContentResolver(android.content.ContentResolver)

Example 93 with ContentObserver

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

the class ValidateNotificationPeople method initialize.

public void initialize(Context context, NotificationUsageStats usageStats) {
    if (DEBUG)
        Slog.d(TAG, "Initializing  " + getClass().getSimpleName() + ".");
    mUserToContextMap = new ArrayMap<>();
    mBaseContext = context;
    mUsageStats = usageStats;
    mPeopleCache = new LruCache<String, LookupResult>(PEOPLE_CACHE_SIZE);
    mEnabled = ENABLE_PEOPLE_VALIDATOR && 1 == Settings.Global.getInt(mBaseContext.getContentResolver(), SETTING_ENABLE_PEOPLE_VALIDATOR, 1);
    if (mEnabled) {
        mHandler = new Handler();
        mObserver = new ContentObserver(mHandler) {

            @Override
            public void onChange(boolean selfChange, Uri uri, int userId) {
                super.onChange(selfChange, uri, userId);
                if (DEBUG || mEvictionCount % 100 == 0) {
                    if (VERBOSE)
                        Slog.i(TAG, "mEvictionCount: " + mEvictionCount);
                }
                mPeopleCache.evictAll();
                mEvictionCount++;
            }
        };
        mBaseContext.getContentResolver().registerContentObserver(Contacts.CONTENT_URI, true, mObserver, UserHandle.USER_ALL);
    }
}
Also used : Handler(android.os.Handler) Uri(android.net.Uri) ContentObserver(android.database.ContentObserver)

Example 94 with ContentObserver

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

the class TelecomLoaderService method registerDefaultAppNotifier.

private void registerDefaultAppNotifier() {
    final PackageManagerInternal packageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
    // Notify the package manager on default app changes
    final Uri defaultSmsAppUri = Settings.Secure.getUriFor(Settings.Secure.SMS_DEFAULT_APPLICATION);
    final Uri defaultDialerAppUri = Settings.Secure.getUriFor(Settings.Secure.DIALER_DEFAULT_APPLICATION);
    ContentObserver contentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {

        @Override
        public void onChange(boolean selfChange, Uri uri, int userId) {
            if (defaultSmsAppUri.equals(uri)) {
                ComponentName smsComponent = SmsApplication.getDefaultSmsApplication(mContext, true);
                if (smsComponent != null) {
                    packageManagerInternal.grantDefaultPermissionsToDefaultSmsApp(smsComponent.getPackageName(), userId);
                }
            } else if (defaultDialerAppUri.equals(uri)) {
                String packageName = DefaultDialerManager.getDefaultDialerApplication(mContext);
                if (packageName != null) {
                    packageManagerInternal.grantDefaultPermissionsToDefaultDialerApp(packageName, userId);
                }
                updateSimCallManagerPermissions(packageManagerInternal, userId);
            }
        }
    };
    mContext.getContentResolver().registerContentObserver(defaultSmsAppUri, false, contentObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(defaultDialerAppUri, false, contentObserver, UserHandle.USER_ALL);
}
Also used : PackageManagerInternal(android.content.pm.PackageManagerInternal) Handler(android.os.Handler) ComponentName(android.content.ComponentName) Uri(android.net.Uri) 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