use of android.database.ContentObserver in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
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 ResurrectionRemix.
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;
}
}
use of android.database.ContentObserver in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class ContactsContentObserver method registerObserver.
public void registerObserver(final ContactsChangedListener listener) {
if (!PermissionsUtil.checkAllPermissionsGranted(mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Not registering the observer.");
// do nothing if we do not have the permission to read contacts.
return;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "registerObserver()");
}
mContactsChangedListener = listener;
mContentObserver = new ContentObserver(null) {
/* handler */
@Override
public void onChange(boolean self) {
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(ContactsContentObserver.this);
}
};
final ContentResolver contentResolver = mContext.getContentResolver();
contentResolver.registerContentObserver(Contacts.CONTENT_URI, true, mContentObserver);
}
use of android.database.ContentObserver in project AndroidTraining by mixi-inc.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.ListView);
// UIにバインドするデータのカラム名
String[] from = { Book.COLUMN_NAME_BOOK_TITLE, Book.COLUMN_NAME_BOOK_PRICE };
// 指定したカラムのデータを表示するViewのIDを指定します。
int[] to = { R.id.Title, R.id.Price };
final Cursor cursor = getContentResolver().query(Book.CONTENT_URI, null, null, null, null);
// Cursorのデータが更新されたことを通知する
// BookContentProviderでsetNotificationUri()をしないと動作しない
cursor.registerContentObserver(new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
cursor.requery();
}
});
mSimpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.list_item_book, cursor, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
listView.setAdapter(mSimpleCursorAdapter);
findViewById(R.id.ADD).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insert();
}
});
}
Aggregations