Skip to content

Commit 68505b3

Browse files
author
android-build-team Robot
committed
Merge cherrypicks of [3509910] into oc-mr1-release
Change-Id: Id1d5683a00a88832ec7bf746fa7bb918a8d7579c
2 parents 23fbf77 + 6f89a3e commit 68505b3

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

core/java/android/content/pm/PackageInfo.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,26 @@ public class PackageInfo implements Parcelable {
286286
/** @hide */
287287
public int overlayPriority;
288288

289-
/** @hide */
290-
public boolean isStaticOverlay;
289+
290+
/**
291+
* Flag for use with {@link #overlayFlags}. Marks the overlay as static, meaning it cannot
292+
* be enabled/disabled at runtime.
293+
* @hide
294+
*/
295+
public static final int FLAG_OVERLAY_STATIC = 1 << 1;
296+
297+
/**
298+
* Flag for use with {@link #overlayFlags}. Marks the overlay as trusted (not 3rd party).
299+
* @hide
300+
*/
301+
public static final int FLAG_OVERLAY_TRUSTED = 1 << 2;
302+
303+
/**
304+
* Modifiers that affect the state of this overlay. See {@link #FLAG_OVERLAY_STATIC},
305+
* {@link #FLAG_OVERLAY_TRUSTED}.
306+
* @hide
307+
*/
308+
public int overlayFlags;
291309

292310
public PackageInfo() {
293311
}
@@ -342,8 +360,8 @@ public void writeToParcel(Parcel dest, int parcelableFlags) {
342360
dest.writeString(restrictedAccountType);
343361
dest.writeString(requiredAccountType);
344362
dest.writeString(overlayTarget);
345-
dest.writeInt(isStaticOverlay ? 1 : 0);
346363
dest.writeInt(overlayPriority);
364+
dest.writeInt(overlayFlags);
347365
}
348366

349367
public static final Parcelable.Creator<PackageInfo> CREATOR
@@ -394,8 +412,8 @@ private PackageInfo(Parcel source) {
394412
restrictedAccountType = source.readString();
395413
requiredAccountType = source.readString();
396414
overlayTarget = source.readString();
397-
isStaticOverlay = source.readInt() != 0;
398415
overlayPriority = source.readInt();
416+
overlayFlags = source.readInt();
399417

400418
// The component lists were flattened with the redundant ApplicationInfo
401419
// instances omitted. Distribute the canonical one here as appropriate.

core/java/android/content/pm/PackageParser.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,15 @@ public static PackageInfo generatePackageInfo(PackageParser.Package p,
678678
pi.requiredAccountType = p.mRequiredAccountType;
679679
pi.overlayTarget = p.mOverlayTarget;
680680
pi.overlayPriority = p.mOverlayPriority;
681-
pi.isStaticOverlay = p.mIsStaticOverlay;
681+
682+
if (p.mIsStaticOverlay) {
683+
pi.overlayFlags |= PackageInfo.FLAG_OVERLAY_STATIC;
684+
}
685+
686+
if (p.mTrustedOverlay) {
687+
pi.overlayFlags |= PackageInfo.FLAG_OVERLAY_TRUSTED;
688+
}
689+
682690
pi.firstInstallTime = firstInstallTime;
683691
pi.lastUpdateTime = lastUpdateTime;
684692
if ((flags&PackageManager.GET_GIDS) != 0) {

services/core/java/com/android/server/om/OverlayManagerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ private void enforceDumpPermission(@NonNull final String message) {
669669
};
670670

671671
private boolean isOverlayPackage(@NonNull final PackageInfo pi) {
672-
return pi != null && pi.overlayTarget != null;
672+
return pi != null && pi.overlayTarget != null
673+
&& (pi.overlayFlags & PackageInfo.FLAG_OVERLAY_TRUSTED) != 0;
673674
}
674675

675676
private final class OverlayChangeListener

services/core/java/com/android/server/om/OverlayManagerServiceImpl.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ final class OverlayManagerServiceImpl {
6868
mListener = listener;
6969
}
7070

71+
private static boolean isPackageStaticOverlay(final PackageInfo packageInfo) {
72+
return packageInfo.overlayTarget != null
73+
&& (packageInfo.overlayFlags & PackageInfo.FLAG_OVERLAY_STATIC) != 0;
74+
}
75+
7176
/**
7277
* Call this to synchronize the Settings for a user with what PackageManager knows about a user.
7378
* Returns a list of target packages that must refresh their overlays. This list is the union
@@ -102,11 +107,11 @@ ArrayList<String> updateOverlaysForUser(final int newUserId) {
102107
mSettings.init(overlayPackage.packageName, newUserId,
103108
overlayPackage.overlayTarget,
104109
overlayPackage.applicationInfo.getBaseCodePath(),
105-
overlayPackage.isStaticOverlay, overlayPackage.overlayPriority);
110+
isPackageStaticOverlay(overlayPackage), overlayPackage.overlayPriority);
106111

107112
if (oi == null) {
108113
// This overlay does not exist in our settings.
109-
if (overlayPackage.isStaticOverlay ||
114+
if (isPackageStaticOverlay(overlayPackage) ||
110115
mDefaultOverlays.contains(overlayPackage.packageName)) {
111116
// Enable this overlay by default.
112117
if (DEBUG) {
@@ -255,8 +260,8 @@ void onOverlayPackageAdded(@NonNull final String packageName, final int userId)
255260
mPackageManager.getPackageInfo(overlayPackage.overlayTarget, userId);
256261

257262
mSettings.init(packageName, userId, overlayPackage.overlayTarget,
258-
overlayPackage.applicationInfo.getBaseCodePath(), overlayPackage.isStaticOverlay,
259-
overlayPackage.overlayPriority);
263+
overlayPackage.applicationInfo.getBaseCodePath(),
264+
isPackageStaticOverlay(overlayPackage), overlayPackage.overlayPriority);
260265
try {
261266
if (updateState(targetPackage, overlayPackage, userId)) {
262267
mListener.onOverlaysChanged(overlayPackage.overlayTarget, userId);
@@ -313,7 +318,7 @@ boolean setEnabled(@NonNull final String packageName, final boolean enable,
313318
}
314319

315320
// Ignore static overlays.
316-
if (overlayPackage.isStaticOverlay) {
321+
if (isPackageStaticOverlay(overlayPackage)) {
317322
return false;
318323
}
319324

@@ -363,7 +368,7 @@ boolean setEnabledExclusive(@NonNull final String packageName, final int userId)
363368
continue;
364369
}
365370

366-
if (disabledOverlayPackageInfo.isStaticOverlay) {
371+
if (isPackageStaticOverlay(disabledOverlayPackageInfo)) {
367372
// Don't touch static overlays.
368373
continue;
369374
}
@@ -388,7 +393,7 @@ boolean setEnabledExclusive(@NonNull final String packageName, final int userId)
388393

389394
private boolean isPackageUpdatableOverlay(@NonNull final String packageName, final int userId) {
390395
final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
391-
if (overlayPackage == null || overlayPackage.isStaticOverlay) {
396+
if (overlayPackage == null || isPackageStaticOverlay(overlayPackage)) {
392397
return false;
393398
}
394399
return true;
@@ -483,7 +488,8 @@ private boolean updateState(@Nullable final PackageInfo targetPackage,
483488
throws OverlayManagerSettings.BadKeyException {
484489
// Static RROs targeting to "android", ie framework-res.apk, are handled by native layers.
485490
if (targetPackage != null &&
486-
!("android".equals(targetPackage.packageName) && overlayPackage.isStaticOverlay)) {
491+
!("android".equals(targetPackage.packageName)
492+
&& isPackageStaticOverlay(overlayPackage))) {
487493
mIdmapManager.createIdmap(targetPackage, overlayPackage, userId);
488494
}
489495

0 commit comments

Comments
 (0)