Search in sources :

Example 71 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

the class PagedViewIconCache method retainAllAppWidgets.

/** Removes all the keys to widgets that aren't in the passed in collection */
public void retainAllAppWidgets(List<AppWidgetProviderInfo> keys) {
    HashSet<Key> keysSet = new HashSet<Key>();
    for (AppWidgetProviderInfo info : keys) {
        keysSet.add(new Key(info));
    }
    retainAll(keysSet, Key.Type.AppWidgetProviderInfoKey);
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) HashSet(java.util.HashSet)

Example 72 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.

the class AppWidgetServiceImpl method getInstalledProvidersForProfile.

@Override
public ParceledListSlice<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter, int profileId) {
    final int userId = UserHandle.getCallingUserId();
    if (DEBUG) {
        Slog.i(TAG, "getInstalledProvidersForProfiles() " + userId);
    }
    // Ensure the profile is in the group and enabled.
    if (!mSecurityPolicy.isEnabledGroupProfile(profileId)) {
        return null;
    }
    synchronized (mLock) {
        ensureGroupStateLoadedLocked(userId);
        ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>();
        final int providerCount = mProviders.size();
        for (int i = 0; i < providerCount; i++) {
            Provider provider = mProviders.get(i);
            AppWidgetProviderInfo info = provider.info;
            // Ignore an invalid provider or one not matching the filter.
            if (provider.zombie || (info.widgetCategory & categoryFilter) == 0) {
                continue;
            }
            // Add providers only for the requested profile that are white-listed.
            final int providerProfileId = info.getProfile().getIdentifier();
            if (providerProfileId == profileId && mSecurityPolicy.isProviderInCallerOrInProfileAndWhitelListed(provider.id.componentName.getPackageName(), providerProfileId)) {
                result.add(cloneIfLocalBinder(info));
            }
        }
        return new ParceledListSlice<AppWidgetProviderInfo>(result);
    }
}
Also used : ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice) WidgetBackupProvider(com.android.server.WidgetBackupProvider)

Example 73 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.

the class AppWidgetServiceImpl method parseProviderInfoXml.

@SuppressWarnings("deprecation")
private Provider parseProviderInfoXml(ProviderId providerId, ResolveInfo ri) {
    Provider provider = null;
    ActivityInfo activityInfo = ri.activityInfo;
    XmlResourceParser parser = null;
    try {
        parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(), AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
        if (parser == null) {
            Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " + "AppWidget provider '" + providerId + '\'');
            return null;
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        // drain whitespace, comments, etc.
        }
        String nodeName = parser.getName();
        if (!"appwidget-provider".equals(nodeName)) {
            Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" + " AppWidget provider " + providerId.componentName + " for user " + providerId.uid);
            return null;
        }
        provider = new Provider();
        provider.id = providerId;
        AppWidgetProviderInfo info = provider.info = new AppWidgetProviderInfo();
        info.provider = providerId.componentName;
        info.providerInfo = activityInfo;
        final Resources resources;
        final long identity = Binder.clearCallingIdentity();
        try {
            final PackageManager pm = mContext.getPackageManager();
            final int userId = UserHandle.getUserId(providerId.uid);
            final ApplicationInfo app = pm.getApplicationInfoAsUser(activityInfo.packageName, 0, userId);
            resources = pm.getResourcesForApplication(app);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
        TypedArray sa = resources.obtainAttributes(attrs, com.android.internal.R.styleable.AppWidgetProviderInfo);
        // These dimensions has to be resolved in the application's context.
        // We simply send back the raw complex data, which will be
        // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
        TypedValue value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
        info.minWidth = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
        info.minHeight = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
        info.minResizeWidth = value != null ? value.data : info.minWidth;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
        info.minResizeHeight = value != null ? value.data : info.minHeight;
        info.updatePeriodMillis = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
        info.initialLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
        info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialKeyguardLayout, 0);
        String className = sa.getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
        if (className != null) {
            info.configure = new ComponentName(providerId.componentName.getPackageName(), className);
        }
        info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
        info.icon = ri.getIconResource();
        info.previewImage = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
        info.autoAdvanceViewId = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
        info.resizeMode = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, AppWidgetProviderInfo.RESIZE_NONE);
        info.widgetCategory = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
        sa.recycle();
    } catch (IOException | PackageManager.NameNotFoundException | XmlPullParserException e) {
        // Ok to catch Exception here, because anything going wrong because
        // of what a client process passes to us should not be fatal for the
        // system process.
        Slog.w(TAG, "XML parsing failed for AppWidget provider " + providerId.componentName + " for user " + providerId.uid, e);
        return null;
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
    return provider;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) Point(android.graphics.Point) WidgetBackupProvider(com.android.server.WidgetBackupProvider) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 74 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class AppWidgetServiceImpl method getInstalledProvidersForProfile.

@Override
public ParceledListSlice<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter, int profileId) {
    final int userId = UserHandle.getCallingUserId();
    if (DEBUG) {
        Slog.i(TAG, "getInstalledProvidersForProfiles() " + userId);
    }
    // Ensure the profile is in the group and enabled.
    if (!mSecurityPolicy.isEnabledGroupProfile(profileId)) {
        return null;
    }
    synchronized (mLock) {
        ensureGroupStateLoadedLocked(userId);
        ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>();
        final int providerCount = mProviders.size();
        for (int i = 0; i < providerCount; i++) {
            Provider provider = mProviders.get(i);
            AppWidgetProviderInfo info = provider.info;
            // Ignore an invalid provider or one not matching the filter.
            if (provider.zombie || (info.widgetCategory & categoryFilter) == 0) {
                continue;
            }
            // Add providers only for the requested profile that are white-listed.
            final int providerProfileId = info.getProfile().getIdentifier();
            if (providerProfileId == profileId && mSecurityPolicy.isProviderInCallerOrInProfileAndWhitelListed(provider.id.componentName.getPackageName(), providerProfileId)) {
                result.add(cloneIfLocalBinder(info));
            }
        }
        return new ParceledListSlice<AppWidgetProviderInfo>(result);
    }
}
Also used : ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Point(android.graphics.Point) ParceledListSlice(android.content.pm.ParceledListSlice) WidgetBackupProvider(com.android.server.WidgetBackupProvider)

Example 75 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class AppWidgetHostActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mAppWidgetManager = AppWidgetManager.getInstance(this);
    setContentView(R.layout.appwidget_host);
    mHost = new AppWidgetHost(this, HOST_ID) {

        protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
            return new MyAppWidgetView(appWidgetId);
        }
    };
    findViewById(R.id.add_appwidget).setOnClickListener(mOnClickListener);
    mAppWidgetContainer = (AppWidgetContainerView) findViewById(R.id.appwidget_container);
    if (false) {
        if (false) {
            mHost.deleteHost();
        } else {
            AppWidgetHost.deleteAllHosts();
        }
    }
}
Also used : Context(android.content.Context) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetHost(android.appwidget.AppWidgetHost) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)91 Point (android.graphics.Point)24 ComponentName (android.content.ComponentName)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)18 Bundle (android.os.Bundle)18 WidgetBackupProvider (com.android.server.WidgetBackupProvider)15 ActivityInfo (android.content.pm.ActivityInfo)14 ResolveInfo (android.content.pm.ResolveInfo)14 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)12 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)12 Intent (android.content.Intent)10 PackageManager (android.content.pm.PackageManager)9 Resources (android.content.res.Resources)7 View (android.view.View)7 Context (android.content.Context)6 IPackageManager (android.content.pm.IPackageManager)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 TypedArray (android.content.res.TypedArray)6 XmlResourceParser (android.content.res.XmlResourceParser)6