use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
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);
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
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(Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), false, /* notifyForDescendents */
mUserSetupObserver, mCurrentUser);
} else if (mBootCompleted) {
setUp();
}
}
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method systemRunning.
public void systemRunning() {
synchronized (mLock) {
if (D)
Log.d(TAG, "systemRunning()");
// fetch package manager
mPackageManager = mContext.getPackageManager();
// fetch power manager
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
// prepare worker thread
mLocationHandler = new LocationWorkerHandler(BackgroundThread.get().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.OnOpChangedListener callback = new AppOpsManager.OnOpChangedInternalListener() {
public void onOpChanged(int op, String packageName) {
synchronized (mLock) {
for (Receiver receiver : mReceivers.values()) {
receiver.updateMonitoring(true);
}
applyAllProviderRequirementsLocked();
}
}
};
mAppOps.startWatchingMode(AppOpsManager.OP_COARSE_LOCATION, null, callback);
PackageManager.OnPermissionsChangedListener permissionListener = new PackageManager.OnPermissionsChangedListener() {
@Override
public void onPermissionsChanged(final int uid) {
synchronized (mLock) {
applyAllProviderRequirementsLocked();
}
}
};
mPackageManager.addOnPermissionsChangeListener(permissionListener);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
updateUserProfiles(mCurrentUserId);
// 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);
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
intentFilter.addAction(Intent.ACTION_SHUTDOWN);
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));
} else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action) || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
updateUserProfiles(mCurrentUserId);
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
// shutdown only if UserId indicates whole system, not just one user
if (D)
Log.d(TAG, "Shutdown received with UserId: " + getSendingUserId());
if (getSendingUserId() == UserHandle.USER_ALL) {
shutdownComponents();
}
}
}
}, UserHandle.ALL, intentFilter, null, mLocationHandler);
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
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);
}
}
Aggregations