Search in sources :

Example 76 with AppWidgetProviderInfo

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

the class AppWidgetHostActivity method handleAppWidgetConfigureResult.

void handleAppWidgetConfigureResult(int resultCode, Intent data) {
    int appWidgetId = getPreferences(0).getInt(PENDING_APPWIDGET_ID, -1);
    Log.d(TAG, "resultCode=" + resultCode + " appWidgetId=" + appWidgetId);
    if (appWidgetId < 0) {
        Log.w(TAG, "was no preference for PENDING_APPWIDGET_ID");
        return;
    }
    if (resultCode == RESULT_OK) {
        AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        addAppWidgetView(appWidgetId, appWidget);
    } else {
        mHost.deleteAppWidgetId(appWidgetId);
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 77 with AppWidgetProviderInfo

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

the class AppWidgetServiceImpl method dumpProvider.

private static void dumpProvider(Provider provider, int index, PrintWriter pw) {
    AppWidgetProviderInfo info = provider.info;
    pw.print("  [");
    pw.print(index);
    pw.print("] provider ");
    pw.println(provider.id);
    pw.print("    min=(");
    pw.print(info.minWidth);
    pw.print("x");
    pw.print(info.minHeight);
    pw.print(")   minResize=(");
    pw.print(info.minResizeWidth);
    pw.print("x");
    pw.print(info.minResizeHeight);
    pw.print(") updatePeriodMillis=");
    pw.print(info.updatePeriodMillis);
    pw.print(" resizeMode=");
    pw.print(info.resizeMode);
    pw.print(" widgetCategory=");
    pw.print(info.widgetCategory);
    pw.print(" autoAdvanceViewId=");
    pw.print(info.autoAdvanceViewId);
    pw.print(" initialLayout=#");
    pw.print(Integer.toHexString(info.initialLayout));
    pw.print(" initialKeyguardLayout=#");
    pw.print(Integer.toHexString(info.initialKeyguardLayout));
    pw.print(" zombie=");
    pw.println(provider.zombie);
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 78 with AppWidgetProviderInfo

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

the class AppWidgetServiceImpl method readProfileStateFromFileLocked.

private int readProfileStateFromFileLocked(FileInputStream stream, int userId, List<LoadedWidgetState> outLoadedWidgets) {
    int version = -1;
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(stream, StandardCharsets.UTF_8.name());
        int legacyProviderIndex = -1;
        int legacyHostIndex = -1;
        int type;
        do {
            type = parser.next();
            if (type == XmlPullParser.START_TAG) {
                String tag = parser.getName();
                if ("gs".equals(tag)) {
                    String attributeValue = parser.getAttributeValue(null, "version");
                    try {
                        version = Integer.parseInt(attributeValue);
                    } catch (NumberFormatException e) {
                        version = 0;
                    }
                } else if ("p".equals(tag)) {
                    legacyProviderIndex++;
                    // TODO: do we need to check that this package has the same signature
                    // as before?
                    String pkg = parser.getAttributeValue(null, "pkg");
                    String cl = parser.getAttributeValue(null, "cl");
                    pkg = getCanonicalPackageName(pkg, cl, userId);
                    if (pkg == null) {
                        continue;
                    }
                    final int uid = getUidForPackage(pkg, userId);
                    if (uid < 0) {
                        continue;
                    }
                    ComponentName componentName = new ComponentName(pkg, cl);
                    ActivityInfo providerInfo = getProviderInfo(componentName, userId);
                    if (providerInfo == null) {
                        continue;
                    }
                    ProviderId providerId = new ProviderId(uid, componentName);
                    Provider provider = lookupProviderLocked(providerId);
                    if (provider == null && mSafeMode) {
                        // if we're in safe mode, make a temporary one
                        provider = new Provider();
                        provider.info = new AppWidgetProviderInfo();
                        provider.info.provider = providerId.componentName;
                        provider.info.providerInfo = providerInfo;
                        provider.zombie = true;
                        provider.id = providerId;
                        mProviders.add(provider);
                    }
                    String tagAttribute = parser.getAttributeValue(null, "tag");
                    final int providerTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyProviderIndex;
                    provider.tag = providerTag;
                } else if ("h".equals(tag)) {
                    legacyHostIndex++;
                    Host host = new Host();
                    // TODO: do we need to check that this package has the same signature
                    // as before?
                    String pkg = parser.getAttributeValue(null, "pkg");
                    final int uid = getUidForPackage(pkg, userId);
                    if (uid < 0) {
                        host.zombie = true;
                    }
                    if (!host.zombie || mSafeMode) {
                        // In safe mode, we don't discard the hosts we don't recognize
                        // so that they're not pruned from our list. Otherwise, we do.
                        final int hostId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
                        String tagAttribute = parser.getAttributeValue(null, "tag");
                        final int hostTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyHostIndex;
                        host.tag = hostTag;
                        host.id = new HostId(uid, hostId, pkg);
                        mHosts.add(host);
                    }
                } else if ("b".equals(tag)) {
                    String packageName = parser.getAttributeValue(null, "packageName");
                    final int uid = getUidForPackage(packageName, userId);
                    if (uid >= 0) {
                        Pair<Integer, String> packageId = Pair.create(userId, packageName);
                        mPackagesWithBindWidgetPermission.add(packageId);
                    }
                } else if ("g".equals(tag)) {
                    Widget widget = new Widget();
                    widget.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
                    setMinAppWidgetIdLocked(userId, widget.appWidgetId + 1);
                    // restored ID is allowed to be absent
                    String restoredIdString = parser.getAttributeValue(null, "rid");
                    widget.restoredId = (restoredIdString == null) ? 0 : Integer.parseInt(restoredIdString, 16);
                    Bundle options = new Bundle();
                    String minWidthString = parser.getAttributeValue(null, "min_width");
                    if (minWidthString != null) {
                        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, Integer.parseInt(minWidthString, 16));
                    }
                    String minHeightString = parser.getAttributeValue(null, "min_height");
                    if (minHeightString != null) {
                        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, Integer.parseInt(minHeightString, 16));
                    }
                    String maxWidthString = parser.getAttributeValue(null, "max_width");
                    if (maxWidthString != null) {
                        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, Integer.parseInt(maxWidthString, 16));
                    }
                    String maxHeightString = parser.getAttributeValue(null, "max_height");
                    if (maxHeightString != null) {
                        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, Integer.parseInt(maxHeightString, 16));
                    }
                    String categoryString = parser.getAttributeValue(null, "host_category");
                    if (categoryString != null) {
                        options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, Integer.parseInt(categoryString, 16));
                    }
                    widget.options = options;
                    final int hostTag = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
                    String providerString = parser.getAttributeValue(null, "p");
                    final int providerTag = (providerString != null) ? Integer.parseInt(parser.getAttributeValue(null, "p"), 16) : TAG_UNDEFINED;
                    // We can match widgets with hosts and providers only after hosts
                    // and providers for all users have been loaded since the widget
                    // host and provider can be in different user profiles.
                    LoadedWidgetState loadedWidgets = new LoadedWidgetState(widget, hostTag, providerTag);
                    outLoadedWidgets.add(loadedWidgets);
                }
            }
        } while (type != XmlPullParser.END_DOCUMENT);
    } catch (NullPointerException | NumberFormatException | XmlPullParserException | IOException | IndexOutOfBoundsException e) {
        Slog.w(TAG, "failed parsing " + e);
        return -1;
    }
    return version;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) XmlPullParser(org.xmlpull.v1.XmlPullParser) IAppWidgetHost(com.android.internal.appwidget.IAppWidgetHost) IOException(java.io.IOException) Point(android.graphics.Point) WidgetBackupProvider(com.android.server.WidgetBackupProvider) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Pair(android.util.Pair)

Example 79 with AppWidgetProviderInfo

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

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 80 with AppWidgetProviderInfo

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

the class ShadowAppWidgetManagerTest method getInstalledProviders_returnsWidgetList.

@Test
public void getInstalledProviders_returnsWidgetList() throws Exception {
    AppWidgetProviderInfo info1 = new AppWidgetProviderInfo();
    info1.label = "abc";
    AppWidgetProviderInfo info2 = new AppWidgetProviderInfo();
    info2.label = "def";
    shadowAppWidgetManager.addInstalledProvider(info1);
    shadowAppWidgetManager.addInstalledProvider(info2);
    List<AppWidgetProviderInfo> installedProviders = appWidgetManager.getInstalledProviders();
    assertEquals(2, installedProviders.size());
    assertEquals(info1, installedProviders.get(0));
    assertEquals(info2, installedProviders.get(1));
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Test(org.junit.Test)

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