Search in sources :

Example 36 with ContentObserver

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

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)

Example 37 with ContentObserver

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

the class SettingsProviderTest method setSettingAndAssertSuccessfulChange.

private void setSettingAndAssertSuccessfulChange(Runnable setCommand, final int type, final String name, final String value, final int userId) throws Exception {
    ContentResolver contentResolver = getContext().getContentResolver();
    final Uri settingUri = getBaseUriForType(type);
    final AtomicBoolean success = new AtomicBoolean();
    ContentObserver contentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {

        public void onChange(boolean selfChange, Uri changeUri, int changeId) {
            Log.i(LOG_TAG, "onChange(" + selfChange + ", " + changeUri + ", " + changeId + ")");
            assertEquals("Wrong change Uri", changeUri, settingUri);
            assertEquals("Wrong user id", userId, changeId);
            String changeValue = getStringViaFrontEndApiSetting(type, name, userId);
            assertEquals("Wrong setting value", value, changeValue);
            success.set(true);
            synchronized (mLock) {
                mLock.notifyAll();
            }
        }
    };
    contentResolver.registerContentObserver(settingUri, false, contentObserver, userId);
    try {
        setCommand.run();
        final long startTimeMillis = SystemClock.uptimeMillis();
        synchronized (mLock) {
            if (success.get()) {
                return;
            }
            final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
            if (elapsedTimeMillis > WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS) {
                fail("Could not change setting for " + WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS + " ms");
            }
            final long remainingTimeMillis = WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS - elapsedTimeMillis;
            try {
                mLock.wait(remainingTimeMillis);
            } catch (InterruptedException ie) {
            /* ignore */
            }
        }
    } finally {
        contentResolver.unregisterContentObserver(contentObserver);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Handler(android.os.Handler) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) ContentObserver(android.database.ContentObserver)

Example 38 with ContentObserver

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

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

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

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

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

the class NightDisplayService method onUserChanged.

private void onUserChanged(int userHandle) {
    final ContentResolver cr = getContext().getContentResolver();
    if (mCurrentUser != UserHandle.USER_NULL) {
        if (mUserSetupObserver != null) {
            cr.unregisterContentObserver(mUserSetupObserver);
            mUserSetupObserver = null;
        } else if (mBootCompleted) {
            tearDown();
        }
    }
    mCurrentUser = userHandle;
    if (mCurrentUser != UserHandle.USER_NULL) {
        if (!isUserSetupCompleted(cr, mCurrentUser)) {
            mUserSetupObserver = new ContentObserver(mHandler) {

                @Override
                public void onChange(boolean selfChange, Uri uri) {
                    if (isUserSetupCompleted(cr, mCurrentUser)) {
                        cr.unregisterContentObserver(this);
                        mUserSetupObserver = null;
                        if (mBootCompleted) {
                            setUp();
                        }
                    }
                }
            };
            cr.registerContentObserver(Secure.getUriFor(Secure.USER_SETUP_COMPLETE), false, /* notifyForDescendents */
            mUserSetupObserver, mCurrentUser);
        } else if (mBootCompleted) {
            setUp();
        }
    }
}
Also used : Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) 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