Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 016e50a9 authored by Alina Zaidi's avatar Alina Zaidi
Browse files

Include an attribute for description of the widget in the attributes file for...

Include an attribute for description of the widget in the attributes file for AppWidgetProviderInfo.

Test: Instrumentation test added- AppWidgetServiceImplTest_testLoadDescription

Bug: 178460757

Change-Id: Ic9b9cd8c592936bbe421183f8715ba5d8f770742
parent d8d8acfd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8349,6 +8349,7 @@ package android.appwidget {
    method public android.appwidget.AppWidgetProviderInfo clone();
    method public int describeContents();
    method public final android.os.UserHandle getProfile();
    method @Nullable public final String loadDescription(@NonNull android.content.Context);
    method public final android.graphics.drawable.Drawable loadIcon(@NonNull android.content.Context, int);
    method public final String loadLabel(android.content.pm.PackageManager);
    method public final android.graphics.drawable.Drawable loadPreviewImage(@NonNull android.content.Context, int);
@@ -8366,6 +8367,7 @@ package android.appwidget {
    field public static final int WIDGET_FEATURE_RECONFIGURABLE = 1; // 0x1
    field public int autoAdvanceViewId;
    field public android.content.ComponentName configure;
    field @IdRes public int descriptionResource;
    field public int icon;
    field public int initialKeyguardLayout;
    field public int initialLayout;
+30 −0
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.appwidget;

import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
@@ -272,6 +275,15 @@ public class AppWidgetProviderInfo implements Parcelable {
    @CategoryFlags
    public int widgetCategory;

    /**
     * Resource id for the description of the AppWidget.
     * <p>This field corresponds to the <code>android:description</code> attribute in the AppWidget
     * meta-data file.
     */
    @SuppressLint("MutableBareField")
    @IdRes
    public int descriptionResource;

    /**
     * Flags indicating various features supported by the widget. These are hints to the widget
     * host, and do not actually change the behavior of the widget.
@@ -313,6 +325,7 @@ public class AppWidgetProviderInfo implements Parcelable {
        this.widgetCategory = in.readInt();
        this.providerInfo = in.readTypedObject(ActivityInfo.CREATOR);
        this.widgetFeatures = in.readInt();
        this.descriptionResource = in.readInt();
    }

    /**
@@ -369,6 +382,21 @@ public class AppWidgetProviderInfo implements Parcelable {
        return loadDrawable(context, density, previewImage, false);
    }

    /** Loads localized description for the app widget. */
    @Nullable
    public final String loadDescription(@NonNull Context context) {
        if (ResourceId.isValid(descriptionResource)) {
            return context.getPackageManager()
                    .getText(
                            providerInfo.packageName,
                            descriptionResource,
                            providerInfo.applicationInfo)
                    .toString()
                    .trim();
        }
        return null;
    }

    /**
     * Gets the user profile in which the provider resides.
     *
@@ -398,6 +426,7 @@ public class AppWidgetProviderInfo implements Parcelable {
        out.writeInt(this.widgetCategory);
        out.writeTypedObject(this.providerInfo, flags);
        out.writeInt(this.widgetFeatures);
        out.writeInt(this.descriptionResource);
    }

    @Override
@@ -421,6 +450,7 @@ public class AppWidgetProviderInfo implements Parcelable {
        that.widgetCategory = this.widgetCategory;
        that.providerInfo = this.providerInfo;
        that.widgetFeatures = this.widgetFeatures;
        that.descriptionResource = this.descriptionResource;
        return that;
    }

+2 −0
Original line number Diff line number Diff line
@@ -7997,6 +7997,8 @@
                   the provided configuration activity. -->
           <flag name="configuration_optional" value="0x3" />
        </attr>
        <!-- A resource identifier for a string containing a short description of the widget. -->
        <attr name="description" />
    </declare-styleable>
    <!-- =============================== -->
+3 −1
Original line number Diff line number Diff line
@@ -2710,7 +2710,9 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                    AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
            info.widgetFeatures = sa.getInt(
                    com.android.internal.R.styleable.AppWidgetProviderInfo_widgetFeatures, 0);

            info.descriptionResource = sa.getResourceId(
                    com.android.internal.R.styleable.AppWidgetProviderInfo_description,
                    Resources.ID_NULL);
            sa.recycle();
            return info;
        } catch (IOException | PackageManager.NameNotFoundException | XmlPullParserException e) {
+2 −0
Original line number Diff line number Diff line
@@ -34,4 +34,6 @@
    <string name="config_batterySaverDeviceSpecificConfig_3">cpufreq-n=2:222,cpufreq-i=3:333/4:444</string>
    <string name="module_1_name" translatable="false">module_1_name</string>
    <string name="module_2_name" translatable="false">module_2_name</string>

    <string name="widget_description">widget description string</string>
</resources>
Loading