use of android.content.Intent.FilterComparison in project android_frameworks_base by ResurrectionRemix.
the class AppWidgetServiceImpl method unbindRemoteViewsService.
@Override
public void unbindRemoteViewsService(String callingPackage, int appWidgetId, Intent intent) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
Slog.i(TAG, "unbindRemoteViewsService() " + userId);
}
// Make sure the package runs under the caller uid.
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
// Unbind from the RemoteViewsService (which will trigger a callback to the bound
// RemoteViewsAdapter)
Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, new FilterComparison(intent));
if (mBoundRemoteViewsServices.containsKey(key)) {
// We don't need to use the appWidgetId until after we are sure there is something
// to unbind. Note that this may mask certain issues with apps calling unbind()
// more than necessary.
// NOTE: The lookup is enforcing security across users by making
// sure the caller can only access widgets it hosts or provides.
Widget widget = lookupWidgetLocked(appWidgetId, Binder.getCallingUid(), callingPackage);
if (widget == null) {
throw new IllegalArgumentException("Bad widget id " + appWidgetId);
}
ServiceConnectionProxy connection = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
connection.disconnect();
mContext.unbindService(connection);
mBoundRemoteViewsServices.remove(key);
}
}
}
use of android.content.Intent.FilterComparison in project android_frameworks_base by crdroidandroid.
the class AppWidgetServiceImpl method handleNotifyAppWidgetViewDataChanged.
private void handleNotifyAppWidgetViewDataChanged(Host host, IAppWidgetHost callbacks, int appWidgetId, int viewId, long requestId) {
try {
callbacks.viewDataChanged(appWidgetId, viewId);
host.lastWidgetUpdateRequestId = requestId;
} catch (RemoteException re) {
// It failed; remove the callback. No need to prune because
// we know that this host is still referenced by this instance.
callbacks = null;
}
// RemoteViewsFactory.onDataSetChanged() directly
synchronized (mLock) {
if (callbacks == null) {
host.callbacks = null;
Set<Pair<Integer, FilterComparison>> keys = mRemoteViewsServicesAppWidgets.keySet();
for (Pair<Integer, FilterComparison> key : keys) {
if (mRemoteViewsServicesAppWidgets.get(key).contains(appWidgetId)) {
final ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
IRemoteViewsFactory cb = IRemoteViewsFactory.Stub.asInterface(service);
try {
cb.onDataSetChangedAsync();
} catch (RemoteException e) {
Slog.e(TAG, "Error calling onDataSetChangedAsync()", e);
}
mContext.unbindService(this);
}
@Override
public void onServiceDisconnected(android.content.ComponentName name) {
// Do nothing
}
};
final int userId = UserHandle.getUserId(key.first);
Intent intent = key.second.getIntent();
// Bind to the service and call onDataSetChanged()
bindService(intent, connection, new UserHandle(userId));
}
}
}
}
}
use of android.content.Intent.FilterComparison in project android_frameworks_base by crdroidandroid.
the class AppWidgetServiceImpl method unbindRemoteViewsService.
@Override
public void unbindRemoteViewsService(String callingPackage, int appWidgetId, Intent intent) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
Slog.i(TAG, "unbindRemoteViewsService() " + userId);
}
// Make sure the package runs under the caller uid.
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
// Unbind from the RemoteViewsService (which will trigger a callback to the bound
// RemoteViewsAdapter)
Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, new FilterComparison(intent));
if (mBoundRemoteViewsServices.containsKey(key)) {
// We don't need to use the appWidgetId until after we are sure there is something
// to unbind. Note that this may mask certain issues with apps calling unbind()
// more than necessary.
// NOTE: The lookup is enforcing security across users by making
// sure the caller can only access widgets it hosts or provides.
Widget widget = lookupWidgetLocked(appWidgetId, Binder.getCallingUid(), callingPackage);
if (widget == null) {
throw new IllegalArgumentException("Bad widget id " + appWidgetId);
}
ServiceConnectionProxy connection = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
connection.disconnect();
mContext.unbindService(connection);
mBoundRemoteViewsServices.remove(key);
}
}
}
use of android.content.Intent.FilterComparison in project platform_frameworks_base by android.
the class AppWidgetServiceImpl method unbindRemoteViewsService.
@Override
public void unbindRemoteViewsService(String callingPackage, int appWidgetId, Intent intent) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
Slog.i(TAG, "unbindRemoteViewsService() " + userId);
}
// Make sure the package runs under the caller uid.
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
// Unbind from the RemoteViewsService (which will trigger a callback to the bound
// RemoteViewsAdapter)
Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, new FilterComparison(intent));
if (mBoundRemoteViewsServices.containsKey(key)) {
// We don't need to use the appWidgetId until after we are sure there is something
// to unbind. Note that this may mask certain issues with apps calling unbind()
// more than necessary.
// NOTE: The lookup is enforcing security across users by making
// sure the caller can only access widgets it hosts or provides.
Widget widget = lookupWidgetLocked(appWidgetId, Binder.getCallingUid(), callingPackage);
if (widget == null) {
throw new IllegalArgumentException("Bad widget id " + appWidgetId);
}
ServiceConnectionProxy connection = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
connection.disconnect();
mContext.unbindService(connection);
mBoundRemoteViewsServices.remove(key);
}
}
}
use of android.content.Intent.FilterComparison in project platform_frameworks_base by android.
the class AppWidgetServiceImpl method bindRemoteViewsService.
@Override
public void bindRemoteViewsService(String callingPackage, int appWidgetId, Intent intent, IBinder callbacks) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
Slog.i(TAG, "bindRemoteViewsService() " + userId);
}
// Make sure the package runs under the caller uid.
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
// NOTE: The lookup is enforcing security across users by making
// sure the caller can only access widgets it hosts or provides.
Widget widget = lookupWidgetLocked(appWidgetId, Binder.getCallingUid(), callingPackage);
if (widget == null) {
throw new IllegalArgumentException("Bad widget id");
}
// Make sure the widget has a provider.
if (widget.provider == null) {
throw new IllegalArgumentException("No provider for widget " + appWidgetId);
}
ComponentName componentName = intent.getComponent();
// Ensure that the service belongs to the same package as the provider.
// But this is not enough as they may be under different users - see below...
String providerPackage = widget.provider.id.componentName.getPackageName();
String servicePackage = componentName.getPackageName();
if (!servicePackage.equals(providerPackage)) {
throw new SecurityException("The taget service not in the same package" + " as the widget provider");
}
// Make sure this service exists under the same user as the provider and
// requires a permission which allows only the system to bind to it.
mSecurityPolicy.enforceServiceExistsAndRequiresBindRemoteViewsPermission(componentName, widget.provider.getUserId());
// Good to go - the service pakcage is correct, it exists for the correct
// user, and requires the bind permission.
// If there is already a connection made for this service intent, then
// disconnect from that first. (This does not allow multiple connections
// to the same service under the same key).
ServiceConnectionProxy connection = null;
FilterComparison fc = new FilterComparison(intent);
Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, fc);
if (mBoundRemoteViewsServices.containsKey(key)) {
connection = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
connection.disconnect();
unbindService(connection);
mBoundRemoteViewsServices.remove(key);
}
// Bind to the RemoteViewsService (which will trigger a callback to the
// RemoteViewsAdapter.onServiceConnected())
connection = new ServiceConnectionProxy(callbacks);
bindService(intent, connection, widget.provider.info.getProfile());
mBoundRemoteViewsServices.put(key, connection);
// Add it to the mapping of RemoteViewsService to appWidgetIds so that we
// can determine when we can call back to the RemoteViewsService later to
// destroy associated factories.
Pair<Integer, FilterComparison> serviceId = Pair.create(widget.provider.id.uid, fc);
incrementAppWidgetServiceRefCount(appWidgetId, serviceId);
}
}
Aggregations