Search in sources :

Example 1 with FilterComparison

use of android.content.Intent.FilterComparison in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method decrementAppWidgetServiceRefCount.

// Subtracts from the ref-count for a given RemoteViewsService intent, prompting a delete if
// the ref-count reaches zero.
private void decrementAppWidgetServiceRefCount(AppWidgetId id) {
    Iterator<FilterComparison> it = mRemoteViewsServicesAppWidgets.keySet().iterator();
    while (it.hasNext()) {
        final FilterComparison key = it.next();
        final HashSet<Integer> ids = mRemoteViewsServicesAppWidgets.get(key);
        if (ids.remove(id.appWidgetId)) {
            // should destroy it and remove it from this set
            if (ids.isEmpty()) {
                destroyRemoteViewsService(key.getIntent(), id);
                it.remove();
            }
        }
    }
}
Also used : FilterComparison(android.content.Intent.FilterComparison)

Example 2 with FilterComparison

use of android.content.Intent.FilterComparison in project platform_frameworks_base by android.

the class AppWidgetServiceImpl method handleNotifyAppWidgetViewDataChanged.

private void handleNotifyAppWidgetViewDataChanged(Host host, IAppWidgetHost callbacks, int appWidgetId, int viewId, long requestTime) {
    try {
        callbacks.viewDataChanged(appWidgetId, viewId);
        host.lastWidgetUpdateTime = requestTime;
    } 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));
                }
            }
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Point(android.graphics.Point) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) FilterComparison(android.content.Intent.FilterComparison) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Example 3 with FilterComparison

use of android.content.Intent.FilterComparison in project android_frameworks_base by DirtyUnicorns.

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);
        }
    }
}
Also used : FilterComparison(android.content.Intent.FilterComparison) Point(android.graphics.Point)

Example 4 with FilterComparison

use of android.content.Intent.FilterComparison in project android_frameworks_base by DirtyUnicorns.

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);
    }
}
Also used : ComponentName(android.content.ComponentName) FilterComparison(android.content.Intent.FilterComparison) Point(android.graphics.Point)

Example 5 with FilterComparison

use of android.content.Intent.FilterComparison in project android_frameworks_base by ResurrectionRemix.

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);
    }
}
Also used : ComponentName(android.content.ComponentName) FilterComparison(android.content.Intent.FilterComparison) Point(android.graphics.Point)

Aggregations

FilterComparison (android.content.Intent.FilterComparison)19 Point (android.graphics.Point)17 ComponentName (android.content.ComponentName)12 RemoteException (android.os.RemoteException)7 UserHandle (android.os.UserHandle)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 ServiceConnection (android.content.ServiceConnection)6 IBinder (android.os.IBinder)6 IRemoteViewsFactory (com.android.internal.widget.IRemoteViewsFactory)6 Pair (android.util.Pair)5 ServiceInfo (android.content.pm.ServiceInfo)1