use of com.android.internal.content.PackageMonitor in project android_frameworks_base by ResurrectionRemix.
the class SettingsProvider method registerBroadcastReceivers.
private void registerBroadcastReceivers() {
IntentFilter userFilter = new IntentFilter();
userFilter.addAction(Intent.ACTION_USER_REMOVED);
userFilter.addAction(Intent.ACTION_USER_STOPPED);
getContext().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM);
switch(intent.getAction()) {
case Intent.ACTION_USER_REMOVED:
{
synchronized (mLock) {
mSettingsRegistry.removeUserStateLocked(userId, true);
}
}
break;
case Intent.ACTION_USER_STOPPED:
{
synchronized (mLock) {
mSettingsRegistry.removeUserStateLocked(userId, false);
}
}
break;
}
}
}, userFilter);
PackageMonitor monitor = new PackageMonitor() {
@Override
public void onPackageRemoved(String packageName, int uid) {
synchronized (mLock) {
mSettingsRegistry.onPackageRemovedLocked(packageName, UserHandle.getUserId(uid));
}
}
};
// package changes
monitor.register(getContext(), BackgroundThread.getHandler().getLooper(), UserHandle.ALL, true);
}
use of com.android.internal.content.PackageMonitor in project android_frameworks_base by ResurrectionRemix.
the class TvInputManagerService method registerBroadcastReceivers.
private void registerBroadcastReceivers() {
PackageMonitor monitor = new PackageMonitor() {
private void buildTvInputList(String[] packages) {
synchronized (mLock) {
if (mCurrentUserId == getChangingUserId()) {
buildTvInputListLocked(mCurrentUserId, packages);
buildTvContentRatingSystemListLocked(mCurrentUserId);
}
}
}
@Override
public void onPackageUpdateFinished(String packageName, int uid) {
if (DEBUG)
Slog.d(TAG, "onPackageUpdateFinished(packageName=" + packageName + ")");
// This callback is invoked when the TV input is reinstalled.
// In this case, isReplacing() always returns true.
buildTvInputList(new String[] { packageName });
}
@Override
public void onPackagesAvailable(String[] packages) {
if (DEBUG) {
Slog.d(TAG, "onPackagesAvailable(packages=" + Arrays.toString(packages) + ")");
}
// available.
if (isReplacing()) {
buildTvInputList(packages);
}
}
@Override
public void onPackagesUnavailable(String[] packages) {
// unavailable.
if (DEBUG) {
Slog.d(TAG, "onPackagesUnavailable(packages=" + Arrays.toString(packages) + ")");
}
if (isReplacing()) {
buildTvInputList(packages);
}
}
@Override
public void onSomePackagesChanged() {
// the TV inputs.
if (DEBUG)
Slog.d(TAG, "onSomePackagesChanged()");
if (isReplacing()) {
if (DEBUG)
Slog.d(TAG, "Skipped building TV input list due to replacing");
// methods instead.
return;
}
buildTvInputList(null);
}
@Override
public boolean onPackageChanged(String packageName, int uid, String[] components) {
// the update can be handled in {@link #onSomePackagesChanged}.
return true;
}
@Override
public void onPackageRemoved(String packageName, int uid) {
synchronized (mLock) {
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
if (!userState.packageSet.contains(packageName)) {
// Not a TV input package.
return;
}
}
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
String selection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?";
String[] selectionArgs = { packageName };
operations.add(ContentProviderOperation.newDelete(TvContract.Channels.CONTENT_URI).withSelection(selection, selectionArgs).build());
operations.add(ContentProviderOperation.newDelete(TvContract.Programs.CONTENT_URI).withSelection(selection, selectionArgs).build());
operations.add(ContentProviderOperation.newDelete(TvContract.WatchedPrograms.CONTENT_URI).withSelection(selection, selectionArgs).build());
ContentProviderResult[] results = null;
try {
ContentResolver cr = getContentResolverForUser(getChangingUserId());
results = cr.applyBatch(TvContract.AUTHORITY, operations);
} catch (RemoteException | OperationApplicationException e) {
Slog.e(TAG, "error in applyBatch", e);
}
if (DEBUG) {
Slog.d(TAG, "onPackageRemoved(packageName=" + packageName + ", uid=" + uid + ")");
Slog.d(TAG, "results=" + results);
}
}
};
monitor.register(mContext, null, UserHandle.ALL, true);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
intentFilter.addAction(Intent.ACTION_USER_REMOVED);
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_USER_REMOVED.equals(action)) {
removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
}
}
}, UserHandle.ALL, intentFilter, null, null);
}
use of com.android.internal.content.PackageMonitor in project android_frameworks_base by ResurrectionRemix.
the class EnabledComponentsObserver method build.
/**
* Create a EnabledComponentObserver instance.
*
* @param context the context to query for changes.
* @param handler a handler to receive lifecycle events from system services on.
* @param settingName the name of a setting to monitor for a list of enabled components.
* @param looper a {@link Looper} to use for receiving package callbacks.
* @param servicePermission the permission required by the components to be bound.
* @param serviceName the intent action implemented by the tracked components.
* @param lock a lock object used to guard instance state in all callbacks and method calls.
* @return an EnableComponentObserver instance.
*/
public static EnabledComponentsObserver build(@NonNull Context context, @NonNull Handler handler, @NonNull String settingName, @NonNull Looper looper, @NonNull String servicePermission, @NonNull String serviceName, @NonNull final Object lock, @NonNull Collection<EnabledComponentChangeListener> listeners) {
SettingsObserver s = SettingsObserver.build(context, handler, settingName);
final EnabledComponentsObserver o = new EnabledComponentsObserver(context, settingName, servicePermission, serviceName, lock, listeners);
PackageMonitor packageMonitor = new PackageMonitor() {
@Override
public void onSomePackagesChanged() {
o.onPackagesChanged();
}
@Override
public void onPackageDisappeared(String packageName, int reason) {
o.onPackagesChanged();
}
@Override
public void onPackageModified(String packageName) {
o.onPackagesChanged();
}
@Override
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
o.onPackagesChanged();
return super.onHandleForceStop(intent, packages, uid, doit);
}
};
packageMonitor.register(context, looper, UserHandle.ALL, true);
s.addListener(o);
return o;
}
use of com.android.internal.content.PackageMonitor in project android_frameworks_base by crdroidandroid.
the class AccessibilityManagerService method registerBroadcastReceivers.
private void registerBroadcastReceivers() {
PackageMonitor monitor = new PackageMonitor() {
@Override
public void onSomePackagesChanged() {
synchronized (mLock) {
// Therefore we ignore packages from linked profiles.
if (getChangingUserId() != mCurrentUserId) {
return;
}
// We will update when the automation service dies.
UserState userState = getCurrentUserStateLocked();
// We have to reload the installed services since some services may
// have different attributes, resolve info (does not support equals),
// etc. Remove them then to force reload.
userState.mInstalledServices.clear();
if (!userState.isUiAutomationSuppressingOtherServices()) {
if (readConfigurationForUserStateLocked(userState)) {
onUserStateChangedLocked(userState);
}
}
}
}
@Override
public void onPackageUpdateFinished(String packageName, int uid) {
// re-bind new versions of them.
synchronized (mLock) {
final int userId = getChangingUserId();
if (userId != mCurrentUserId) {
return;
}
UserState userState = getUserStateLocked(userId);
boolean unboundAService = false;
for (int i = userState.mBoundServices.size() - 1; i >= 0; i--) {
Service boundService = userState.mBoundServices.get(i);
String servicePkg = boundService.mComponentName.getPackageName();
if (servicePkg.equals(packageName)) {
boundService.unbindLocked();
unboundAService = true;
}
}
if (unboundAService) {
onUserStateChangedLocked(userState);
}
}
}
@Override
public void onPackageRemoved(String packageName, int uid) {
synchronized (mLock) {
final int userId = getChangingUserId();
// Therefore we ignore packages from linked profiles.
if (userId != mCurrentUserId) {
return;
}
UserState userState = getUserStateLocked(userId);
Iterator<ComponentName> it = userState.mEnabledServices.iterator();
while (it.hasNext()) {
ComponentName comp = it.next();
String compPkg = comp.getPackageName();
if (compPkg.equals(packageName)) {
it.remove();
// Update the enabled services setting.
persistComponentNamesToSettingLocked(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, userState.mEnabledServices, userId);
// Update the touch exploration granted services setting.
userState.mTouchExplorationGrantedServices.remove(comp);
persistComponentNamesToSettingLocked(Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, userState.mTouchExplorationGrantedServices, userId);
// We will update when the automation service dies.
if (!userState.isUiAutomationSuppressingOtherServices()) {
onUserStateChangedLocked(userState);
}
return;
}
}
}
}
@Override
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
synchronized (mLock) {
final int userId = getChangingUserId();
// Therefore we ignore packages from linked profiles.
if (userId != mCurrentUserId) {
return false;
}
UserState userState = getUserStateLocked(userId);
Iterator<ComponentName> it = userState.mEnabledServices.iterator();
while (it.hasNext()) {
ComponentName comp = it.next();
String compPkg = comp.getPackageName();
for (String pkg : packages) {
if (compPkg.equals(pkg)) {
if (!doit) {
return true;
}
it.remove();
persistComponentNamesToSettingLocked(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, userState.mEnabledServices, userId);
// We will update when the automation service dies.
if (!userState.isUiAutomationSuppressingOtherServices()) {
onUserStateChangedLocked(userState);
}
}
}
}
return false;
}
}
};
// package changes
monitor.register(mContext, null, UserHandle.ALL, true);
// user change and unlock
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
intentFilter.addAction(Intent.ACTION_USER_REMOVED);
intentFilter.addAction(Intent.ACTION_USER_PRESENT);
intentFilter.addAction(Intent.ACTION_SETTING_RESTORED);
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_USER_UNLOCKED.equals(action)) {
unlockUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
// We will update when the automation service dies.
UserState userState = getCurrentUserStateLocked();
if (!userState.isUiAutomationSuppressingOtherServices()) {
if (readConfigurationForUserStateLocked(userState)) {
onUserStateChangedLocked(userState);
}
}
} else if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
final String which = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
if (Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES.equals(which)) {
synchronized (mLock) {
restoreEnabledAccessibilityServicesLocked(intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE), intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE));
}
}
}
}
}, UserHandle.ALL, intentFilter, null, null);
}
use of com.android.internal.content.PackageMonitor in project android_frameworks_base by crdroidandroid.
the class EnabledComponentsObserver method build.
/**
* Create a EnabledComponentObserver instance.
*
* @param context the context to query for changes.
* @param handler a handler to receive lifecycle events from system services on.
* @param settingName the name of a setting to monitor for a list of enabled components.
* @param looper a {@link Looper} to use for receiving package callbacks.
* @param servicePermission the permission required by the components to be bound.
* @param serviceName the intent action implemented by the tracked components.
* @param lock a lock object used to guard instance state in all callbacks and method calls.
* @return an EnableComponentObserver instance.
*/
public static EnabledComponentsObserver build(@NonNull Context context, @NonNull Handler handler, @NonNull String settingName, @NonNull Looper looper, @NonNull String servicePermission, @NonNull String serviceName, @NonNull final Object lock, @NonNull Collection<EnabledComponentChangeListener> listeners) {
SettingsObserver s = SettingsObserver.build(context, handler, settingName);
final EnabledComponentsObserver o = new EnabledComponentsObserver(context, settingName, servicePermission, serviceName, lock, listeners);
PackageMonitor packageMonitor = new PackageMonitor() {
@Override
public void onSomePackagesChanged() {
o.onPackagesChanged();
}
@Override
public void onPackageDisappeared(String packageName, int reason) {
o.onPackagesChanged();
}
@Override
public void onPackageModified(String packageName) {
o.onPackagesChanged();
}
@Override
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
o.onPackagesChanged();
return super.onHandleForceStop(intent, packages, uid, doit);
}
};
packageMonitor.register(context, looper, UserHandle.ALL, true);
s.addListener(o);
return o;
}
Aggregations