Search in sources :

Example 16 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory 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));
                }
            }
        }
    }
}
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 17 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project android_frameworks_base by ParanoidAndroid.

the class RemoteViewsAdapter method updateTemporaryMetaData.

private void updateTemporaryMetaData() {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    try {
        // get the properties/first view (so that we can use it to
        // measure our dummy views)
        boolean hasStableIds = factory.hasStableIds();
        int viewTypeCount = factory.getViewTypeCount();
        int count = factory.getCount();
        RemoteViews loadingView = factory.getLoadingView();
        RemoteViews firstView = null;
        if ((count > 0) && (loadingView == null)) {
            firstView = factory.getViewAt(0);
        }
        final RemoteViewsMetaData tmpMetaData = mCache.getTemporaryMetaData();
        synchronized (tmpMetaData) {
            tmpMetaData.hasStableIds = hasStableIds;
            // We +1 because the base view type is the loading view
            tmpMetaData.viewTypeCount = viewTypeCount + 1;
            tmpMetaData.count = count;
            tmpMetaData.setLoadingViewTemplates(loadingView, firstView);
        }
    } catch (RemoteException e) {
        processException("updateMetaData", e);
    } catch (RuntimeException e) {
        processException("updateMetaData", e);
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Example 18 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method destroyRemoteViewsService.

// Destroys the cached factory on the RemoteViewsService's side related to the specified intent
private void destroyRemoteViewsService(final Intent intent, AppWidgetId id) {
    final ServiceConnection conn = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            final IRemoteViewsFactory cb = IRemoteViewsFactory.Stub.asInterface(service);
            try {
                cb.onDestroy(intent);
            } 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 remove the static intent->factory mapping in the
    // RemoteViewsService.
    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) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 19 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory 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 20 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory 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

RemoteException (android.os.RemoteException)33 IRemoteViewsFactory (com.android.internal.widget.IRemoteViewsFactory)33 ComponentName (android.content.ComponentName)12 ServiceConnection (android.content.ServiceConnection)12 IBinder (android.os.IBinder)12 UserHandle (android.os.UserHandle)8 Point (android.graphics.Point)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 FilterComparison (android.content.Intent.FilterComparison)6 Pair (android.util.Pair)5