Merge changes I7a3ba2af,Ifa89ae43 into sc-dev am: 0f1dd468bd am: ca4e09d0c1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15504100

Change-Id: Ib607b263e084c3211e01cd55e3062377f03c7cff
This commit is contained in:
TreeHugger Robot
2021-08-10 22:53:35 +00:00
committed by Automerger Merge Worker
4 changed files with 111 additions and 8 deletions

View File

@@ -19,6 +19,8 @@ package android.appwidget;
import android.annotation.Nullable;
import android.util.ArraySet;
import java.util.Set;
/**
* App widget manager local system service interface.
*
@@ -42,4 +44,16 @@ public abstract class AppWidgetManagerInternal {
* @param userId The user that is being unlocked.
*/
public abstract void unlockUser(int userId);
/**
* Updates all widgets, applying changes to Runtime Resource Overlay affecting the specified
* target packages.
*
* @param packageNames The names of all target packages for which an overlay was modified
* @param userId The user for which overlay modifications occurred.
* @param updateFrameworkRes Whether or not an overlay affected the values of framework
* resources.
*/
public abstract void applyResourceOverlaysToWidgets(Set<String> packageNames, int userId,
boolean updateFrameworkRes);
}

View File

@@ -5824,6 +5824,25 @@ public class RemoteViews implements Parcelable, Filter {
return false;
}
/** @hide */
public void updateAppInfo(@NonNull ApplicationInfo info) {
if (mApplication != null && mApplication.sourceDir.equals(info.sourceDir)) {
// Overlay paths are generated against a particular version of an application.
// The overlays paths of a newly upgraded application are incompatible with the
// old version of the application.
mApplication = info;
}
if (hasSizedRemoteViews()) {
for (RemoteViews layout : mSizedRemoteViews) {
layout.updateAppInfo(info);
}
}
if (hasLandscapeAndPortraitLayouts()) {
mLandscape.updateAppInfo(info);
mPortrait.updateAppInfo(info);
}
}
private Context getContextForResources(Context context) {
if (mApplication != null) {
if (context.getUserId() == UserHandle.getUserId(mApplication.uid)

View File

@@ -3285,6 +3285,57 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
private void applyResourceOverlaysToWidgetsLocked(Set<String> packageNames, int userId,
boolean updateFrameworkRes) {
for (int i = 0, N = mProviders.size(); i < N; i++) {
Provider provider = mProviders.get(i);
if (provider.getUserId() != userId) {
continue;
}
final String packageName = provider.id.componentName.getPackageName();
if (!updateFrameworkRes && !packageNames.contains(packageName)) {
continue;
}
ApplicationInfo newAppInfo = null;
try {
newAppInfo = mPackageManager.getApplicationInfo(packageName,
PackageManager.GET_SHARED_LIBRARY_FILES, userId);
} catch (RemoteException e) {
Slog.w(TAG, "Failed to retrieve app info for " + packageName
+ " userId=" + userId, e);
}
if (newAppInfo == null) {
continue;
}
ApplicationInfo oldAppInfo = provider.info.providerInfo.applicationInfo;
if (!newAppInfo.sourceDir.equals(oldAppInfo.sourceDir)) {
// Overlay paths are generated against a particular version of an application.
// The overlays paths of a newly upgraded application are incompatible with the
// old version of the application.
continue;
}
// Isolate the changes relating to RROs. The app info must be copied to prevent
// affecting other parts of system server that may have cached this app info.
oldAppInfo = new ApplicationInfo(oldAppInfo);
oldAppInfo.overlayPaths = newAppInfo.overlayPaths.clone();
oldAppInfo.resourceDirs = newAppInfo.resourceDirs.clone();
provider.info.providerInfo.applicationInfo = oldAppInfo;
for (int j = 0, M = provider.widgets.size(); j < M; j++) {
Widget widget = provider.widgets.get(j);
if (widget.views != null) {
widget.views.updateAppInfo(oldAppInfo);
}
if (widget.maskedViews != null) {
widget.maskedViews.updateAppInfo(oldAppInfo);
}
}
}
}
/**
* Updates all providers with the specified package names, and records any providers that were
* pruned.
@@ -4875,5 +4926,14 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
public void unlockUser(int userId) {
handleUserUnlocked(userId);
}
@Override
public void applyResourceOverlaysToWidgets(Set<String> packageNames, int userId,
boolean updateFrameworkRes) {
synchronized (mLock) {
applyResourceOverlaysToWidgetsLocked(new HashSet<>(packageNames), userId,
updateFrameworkRes);
}
}
}
}

View File

@@ -193,6 +193,7 @@ import android.app.usage.UsageEvents.Event;
import android.app.usage.UsageStatsManager;
import android.app.usage.UsageStatsManagerInternal;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetManagerInternal;
import android.content.AttributionSource;
import android.content.AutofillOptions;
import android.content.BroadcastReceiver;
@@ -16578,13 +16579,21 @@ public class ActivityManagerService extends IActivityManager.Stub
enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
"scheduleApplicationInfoChanged()");
synchronized (mProcLock) {
final long origId = Binder.clearCallingIdentity();
try {
updateApplicationInfoLOSP(packageNames, userId);
} finally {
Binder.restoreCallingIdentity(origId);
final long origId = Binder.clearCallingIdentity();
try {
final boolean updateFrameworkRes = packageNames.contains("android");
synchronized (mProcLock) {
updateApplicationInfoLOSP(packageNames, updateFrameworkRes, userId);
}
AppWidgetManagerInternal widgets = LocalServices.getService(
AppWidgetManagerInternal.class);
if (widgets != null) {
widgets.applyResourceOverlaysToWidgets(new HashSet<>(packageNames), userId,
updateFrameworkRes);
}
} finally {
Binder.restoreCallingIdentity(origId);
}
}
@@ -16601,11 +16610,12 @@ public class ActivityManagerService extends IActivityManager.Stub
}
@GuardedBy(anyOf = {"this", "mProcLock"})
private void updateApplicationInfoLOSP(@NonNull List<String> packagesToUpdate, int userId) {
final boolean updateFrameworkRes = packagesToUpdate.contains("android");
private void updateApplicationInfoLOSP(@NonNull List<String> packagesToUpdate,
boolean updateFrameworkRes, int userId) {
if (updateFrameworkRes) {
ParsingPackageUtils.readConfigUseRoundIcon(null);
}
mProcessList.updateApplicationInfoLOSP(packagesToUpdate, userId, updateFrameworkRes);
if (updateFrameworkRes) {