Search in sources :

Example 16 with FilterComparison

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

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 17 with FilterComparison

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

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));
                }
            }
        }
    }
}
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 18 with FilterComparison

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

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));
                }
            }
        }
    }
}
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 19 with FilterComparison

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

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