Adding APIs to get manifest entries for Launcher activities and widgets

and getting resources for a particular config

This would allow fetching display infos for the activity in a particular
config independent of system config.

Bug: 156154533
Test: Included CTS
Change-Id: Ie245d685fb21444c10a88b4ca86dc7ff08e2b599
Merged-In: Ie245d685fb21444c10a88b4ca86dc7ff08e2b599
This commit is contained in:
Sunny Goyal
2020-12-14 11:39:18 -08:00
parent 6c6fb9eab8
commit 7152080c07
6 changed files with 60 additions and 22 deletions

View File

@@ -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 @NonNull public android.content.pm.ActivityInfo getProviderInfo();
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);
@@ -11866,6 +11867,7 @@ package android.content.pm {
}
public class LauncherActivityInfo {
method @NonNull public android.content.pm.ActivityInfo getActivityInfo();
method public android.content.pm.ApplicationInfo getApplicationInfo();
method public android.graphics.drawable.Drawable getBadgedIcon(int);
method public android.content.ComponentName getComponentName();
@@ -12238,6 +12240,7 @@ package android.content.pm {
method @NonNull public abstract android.content.pm.ActivityInfo getReceiverInfo(@NonNull android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public abstract android.content.res.Resources getResourcesForActivity(@NonNull android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public abstract android.content.res.Resources getResourcesForApplication(@NonNull android.content.pm.ApplicationInfo) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public android.content.res.Resources getResourcesForApplication(@NonNull android.content.pm.ApplicationInfo, @Nullable android.content.res.Configuration) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public abstract android.content.res.Resources getResourcesForApplication(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public abstract android.content.pm.ServiceInfo getServiceInfo(@NonNull android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public abstract java.util.List<android.content.pm.SharedLibraryInfo> getSharedLibraries(int);

View File

@@ -2291,9 +2291,10 @@ public final class ActivityThread extends ClientTransactionHandler {
* Resources if one has already been created.
*/
Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs,
String[] libDirs, LoadedApk pkgInfo) {
String[] libDirs, LoadedApk pkgInfo, Configuration overrideConfig) {
return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs,
null, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader(), null);
null, overrideConfig, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader(),
null);
}
@UnsupportedAppUsage

View File

@@ -70,6 +70,7 @@ import android.content.pm.SuspendDialogInfo;
import android.content.pm.VerifierDeviceIdentity;
import android.content.pm.VersionedPackage;
import android.content.pm.dex.ArtManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
@@ -1691,20 +1692,29 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
throws NameNotFoundException {
return getResourcesForApplication(app, null);
}
@Override
public Resources getResourcesForApplication(@NonNull ApplicationInfo app,
@Nullable Configuration configuration) throws NameNotFoundException {
if (app.packageName.equals("system")) {
return mContext.mMainThread.getSystemUiContext().getResources();
Context sysuiContext = mContext.mMainThread.getSystemUiContext();
if (configuration != null) {
sysuiContext = sysuiContext.createConfigurationContext(configuration);
}
return sysuiContext.getResources();
}
final boolean sameUid = (app.uid == Process.myUid());
final Resources r = mContext.mMainThread.getTopLevelResources(
sameUid ? app.sourceDir : app.publicSourceDir,
sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
app.resourceDirs, app.sharedLibraryFiles,
mContext.mPackageInfo);
sameUid ? app.sourceDir : app.publicSourceDir,
sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
app.resourceDirs, app.sharedLibraryFiles,
mContext.mPackageInfo, configuration);
if (r != null) {
return r;
}
throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
}
@Override

View File

@@ -406,6 +406,14 @@ public class AppWidgetProviderInfo implements Parcelable {
return new UserHandle(UserHandle.getUserId(providerInfo.applicationInfo.uid));
}
/**
* Returns the broadcast receiver that is providing this widget.
*/
@NonNull
public ActivityInfo getProviderInfo() {
return providerInfo;
}
@Override
@SuppressWarnings("deprecation")
public void writeToParcel(Parcel out, int flags) {

View File

@@ -17,6 +17,7 @@
package android.content.pm;
import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -32,8 +33,6 @@ import android.util.DisplayMetrics;
* and badged icon for the activity.
*/
public class LauncherActivityInfo {
private static final String TAG = "LauncherActivityInfo";
private final PackageManager mPm;
private UserHandle mUser;
private final LauncherActivityInfoInternal mInternal;
@@ -81,7 +80,7 @@ public class LauncherActivityInfo {
*/
public CharSequence getLabel() {
// TODO: Go through LauncherAppsService
return mInternal.getActivityInfo().loadLabel(mPm);
return getActivityInfo().loadLabel(mPm);
}
/**
@@ -101,20 +100,20 @@ public class LauncherActivityInfo {
*/
public Drawable getIcon(int density) {
// TODO: Go through LauncherAppsService
final int iconRes = mInternal.getActivityInfo().getIconResource();
final int iconRes = getActivityInfo().getIconResource();
Drawable icon = null;
// Get the preferred density icon from the app's resources
if (density != 0 && iconRes != 0) {
try {
final Resources resources = mPm.getResourcesForApplication(
mInternal.getActivityInfo().applicationInfo);
getActivityInfo().applicationInfo);
icon = resources.getDrawableForDensity(iconRes, density);
} catch (NameNotFoundException | Resources.NotFoundException exc) {
}
}
// Get the default density icon
if (icon == null) {
icon = mInternal.getActivityInfo().loadIcon(mPm);
icon = getActivityInfo().loadIcon(mPm);
}
return icon;
}
@@ -126,25 +125,25 @@ public class LauncherActivityInfo {
* @hide remove before shipping
*/
public int getApplicationFlags() {
return mInternal.getActivityInfo().flags;
return getActivityInfo().flags;
}
/**
* Returns the ActivityInfo of the activity.
*
* @return Activity Info
* @hide
*/
@NonNull
public ActivityInfo getActivityInfo() {
return mInternal.getActivityInfo();
}
/**
* Returns the application info for the appliction this activity belongs to.
* Returns the application info for the application this activity belongs to.
* @return
*/
public ApplicationInfo getApplicationInfo() {
return mInternal.getActivityInfo().applicationInfo;
return getActivityInfo().applicationInfo;
}
/**
@@ -155,7 +154,7 @@ public class LauncherActivityInfo {
public long getFirstInstallTime() {
try {
// TODO: Go through LauncherAppsService
return mPm.getPackageInfo(mInternal.getActivityInfo().packageName,
return mPm.getPackageInfo(getActivityInfo().packageName,
PackageManager.MATCH_UNINSTALLED_PACKAGES).firstInstallTime;
} catch (NameNotFoundException nnfe) {
// Sorry, can't find package
@@ -164,11 +163,11 @@ public class LauncherActivityInfo {
}
/**
* Returns the name for the acitivty from android:name in the manifest.
* @return the name from android:name for the acitivity.
* Returns the name for the activity from android:name in the manifest.
* @return the name from android:name for the activity.
*/
public String getName() {
return mInternal.getActivityInfo().name;
return getActivityInfo().name;
}
/**

View File

@@ -54,6 +54,7 @@ import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseResult;
import android.content.pm.parsing.result.ParseTypeImpl;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Rect;
@@ -6701,6 +6702,22 @@ public abstract class PackageManager {
public abstract Resources getResourcesForApplication(@NonNull ApplicationInfo app)
throws NameNotFoundException;
/**
* Retrieve the resources for an application for the provided configuration.
*
* @param app Information about the desired application.
* @param configuration Overridden configuration when loading the Resources
*
* @return Returns the application's Resources.
* @throws NameNotFoundException Thrown if the resources for the given
* application could not be loaded (most likely because it was uninstalled).
*/
@NonNull
public Resources getResourcesForApplication(@NonNull ApplicationInfo app, @Nullable
Configuration configuration) throws NameNotFoundException {
throw new UnsupportedOperationException();
}
/**
* Retrieve the resources associated with an application. Given the full
* package name of an application, retrieves the information about it and