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);
}
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);
}
}
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.
}
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);
}
}
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();
}
}
}
Aggregations