Search in sources :

Example 11 with FilterComparison

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

the class AppWidgetServiceImpl method bindRemoteViewsService.

// Binds to a specific RemoteViewsService
public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection) {
    synchronized (mAppWidgetIds) {
        if (!mHasFeature) {
            return;
        }
        ensureStateLoadedLocked();
        AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
        if (id == null) {
            throw new IllegalArgumentException("bad appWidgetId");
        }
        final ComponentName componentName = intent.getComponent();
        try {
            final ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(componentName, PackageManager.GET_PERMISSIONS, mUserId);
            if (!android.Manifest.permission.BIND_REMOTEVIEWS.equals(si.permission)) {
                throw new SecurityException("Selected service does not require " + android.Manifest.permission.BIND_REMOTEVIEWS + ": " + componentName);
            }
        } catch (RemoteException e) {
            throw new IllegalArgumentException("Unknown component " + componentName);
        }
        // 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 conn = null;
        FilterComparison fc = new FilterComparison(intent);
        Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, fc);
        if (mBoundRemoteViewsServices.containsKey(key)) {
            conn = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
            conn.disconnect();
            mContext.unbindService(conn);
            mBoundRemoteViewsServices.remove(key);
        }
        int userId = UserHandle.getUserId(id.provider.uid);
        if (userId != mUserId) {
            Slog.w(TAG, "AppWidgetServiceImpl of user " + mUserId + " binding to provider on user " + userId);
        }
        // Bind to the RemoteViewsService (which will trigger a callback to the
        // RemoteViewsAdapter.onServiceConnected())
        final long token = Binder.clearCallingIdentity();
        try {
            conn = new ServiceConnectionProxy(key, connection);
            mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(userId));
            mBoundRemoteViewsServices.put(key, conn);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        // 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.
        incrementAppWidgetServiceRefCount(appWidgetId, fc);
    }
}
Also used : Point(android.graphics.Point) ServiceInfo(android.content.pm.ServiceInfo) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) FilterComparison(android.content.Intent.FilterComparison) RemoteException(android.os.RemoteException)

Example 12 with FilterComparison

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

the class AppWidgetServiceImpl method unbindRemoteViewsService.

// Unbinds from a specific RemoteViewsService
public void unbindRemoteViewsService(int appWidgetId, Intent intent) {
    synchronized (mAppWidgetIds) {
        if (!mHasFeature) {
            return;
        }
        ensureStateLoadedLocked();
        // 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.
            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
            if (id == null) {
                throw new IllegalArgumentException("bad appWidgetId");
            }
            ServiceConnectionProxy conn = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
            conn.disconnect();
            mContext.unbindService(conn);
            mBoundRemoteViewsServices.remove(key);
        }
    }
}
Also used : FilterComparison(android.content.Intent.FilterComparison)

Example 13 with FilterComparison

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

the class AppWidgetServiceImpl method notifyAppWidgetViewDataChangedInstanceLocked.

void notifyAppWidgetViewDataChangedInstanceLocked(AppWidgetId id, int viewId) {
    // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
    if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
        // is anyone listening?
        if (id.host.callbacks != null) {
            try {
                // the lock is held, but this is a oneway call
                id.host.callbacks.viewDataChanged(id.appWidgetId, viewId, mUserId);
            } catch (RemoteException e) {
                // It failed; remove the callback. No need to prune because
                // we know that this host is still referenced by this instance.
                id.host.callbacks = null;
            }
        }
        // RemoteViewsFactory.onDataSetChanged() directly
        if (id.host.callbacks == null) {
            Set<FilterComparison> keys = mRemoteViewsServicesAppWidgets.keySet();
            for (FilterComparison key : keys) {
                if (mRemoteViewsServicesAppWidgets.get(key).contains(id.appWidgetId)) {
                    Intent intent = key.getIntent();
                    final ServiceConnection conn = new ServiceConnection() {

                        @Override
                        public void onServiceConnected(ComponentName name, IBinder service) {
                            IRemoteViewsFactory cb = IRemoteViewsFactory.Stub.asInterface(service);
                            try {
                                cb.onDataSetChangedAsync();
                            } catch (RemoteException e) {
                                e.printStackTrace();
                            } catch (RuntimeException e) {
                                e.printStackTrace();
                            }
                            mContext.unbindService(this);
                        }

                        @Override
                        public void onServiceDisconnected(android.content.ComponentName name) {
                        // Do nothing
                        }
                    };
                    int userId = UserHandle.getUserId(id.provider.uid);
                    // Bind to the service and call onDataSetChanged()
                    final long token = Binder.clearCallingIdentity();
                    try {
                        mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(userId));
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
                }
            }
        }
    }
}
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)

Example 14 with FilterComparison

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

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

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

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)

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