Skip to content

Commit 99870f7

Browse files
Merge branch 'lineage-22.1' of https://github.com/LineageOS/android_frameworks_base into fifteen-los
2 parents f252b8f + 8f2748b commit 99870f7

File tree

9 files changed

+213
-56
lines changed

9 files changed

+213
-56
lines changed

core/java/android/app/ResourcesManager.java

Lines changed: 89 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,58 @@ public void registerResourcePaths(@NonNull String uniqueId, @NonNull Application
174174
}
175175

176176
/**
177-
* Apply the registered library paths to the passed impl object
178-
* @return the hash code for the current version of the registered paths
177+
* Apply the registered library paths to the passed AssetManager. If may create a new
178+
* AssetManager if any changes are needed and it isn't allowed to reuse the old one.
179+
*
180+
* @return new AssetManager and the hash code for the current version of the registered paths
179181
*/
180-
public int updateResourceImplWithRegisteredLibs(@NonNull ResourcesImpl impl) {
182+
public @NonNull Pair<AssetManager, Integer> updateResourceImplAssetsWithRegisteredLibs(
183+
@NonNull AssetManager assets, boolean reuseAssets) {
181184
if (!Flags.registerResourcePaths()) {
182-
return 0;
185+
return new Pair<>(assets, 0);
183186
}
184187

185-
final var collector = new PathCollector(null);
186-
final int size = mSharedLibAssetsMap.size();
187-
for (int i = 0; i < size; i++) {
188-
final var libraryKey = mSharedLibAssetsMap.valueAt(i).getResourcesKey();
189-
collector.appendKey(libraryKey);
188+
final int size;
189+
final PathCollector collector;
190+
191+
synchronized (mLock) {
192+
size = mSharedLibAssetsMap.size();
193+
if (assets == AssetManager.getSystem()) {
194+
return new Pair<>(assets, size);
195+
}
196+
collector = new PathCollector(resourcesKeyFromAssets(assets));
197+
for (int i = 0; i < size; i++) {
198+
final var libraryKey = mSharedLibAssetsMap.valueAt(i).getResourcesKey();
199+
collector.appendKey(libraryKey);
200+
}
190201
}
191-
impl.getAssets().addPresetApkKeys(extractApkKeys(collector.collectedKey()));
192-
return size;
202+
if (collector.isSameAsOriginal()) {
203+
return new Pair<>(assets, size);
204+
}
205+
if (reuseAssets) {
206+
assets.addPresetApkKeys(extractApkKeys(collector.collectedKey()));
207+
return new Pair<>(assets, size);
208+
}
209+
final var newAssetsBuilder = new AssetManager.Builder().setNoInit();
210+
for (final var asset : assets.getApkAssets()) {
211+
// Skip everything that's either default, or will get added by the collector (builder
212+
// doesn't check for duplicates at all).
213+
if (asset.isSystem() || asset.isForLoader() || asset.isOverlay()
214+
|| asset.isSharedLib()) {
215+
continue;
216+
}
217+
newAssetsBuilder.addApkAssets(asset);
218+
}
219+
for (final var key : extractApkKeys(collector.collectedKey())) {
220+
try {
221+
final var asset = loadApkAssets(key);
222+
newAssetsBuilder.addApkAssets(asset);
223+
} catch (IOException e) {
224+
Log.e(TAG, "Couldn't load assets for key " + key, e);
225+
}
226+
}
227+
assets.getLoaders().forEach(newAssetsBuilder::addLoader);
228+
return new Pair<>(newAssetsBuilder.build(), size);
193229
}
194230

195231
public static class ApkKey {
@@ -621,6 +657,23 @@ private static String overlayPathToIdmapPath(String path) {
621657
return apkKeys;
622658
}
623659

660+
private ResourcesKey resourcesKeyFromAssets(@NonNull AssetManager assets) {
661+
final var libs = new ArrayList<String>();
662+
final var overlays = new ArrayList<String>();
663+
for (final ApkAssets asset : assets.getApkAssets()) {
664+
if (asset.isSystem() || asset.isForLoader()) {
665+
continue;
666+
}
667+
if (asset.isOverlay()) {
668+
overlays.add(asset.getAssetPath());
669+
} else if (asset.isSharedLib()) {
670+
libs.add(asset.getAssetPath());
671+
}
672+
}
673+
return new ResourcesKey(null, null, overlays.toArray(new String[0]),
674+
libs.toArray(new String[0]), 0, null, null);
675+
}
676+
624677
/**
625678
* Creates an AssetManager from the paths within the ResourcesKey.
626679
*
@@ -749,7 +802,7 @@ private int generateDisplayId(@NonNull ResourcesKey key) {
749802

750803
final Configuration config = generateConfig(key);
751804
final DisplayMetrics displayMetrics = getDisplayMetrics(generateDisplayId(key), daj);
752-
final ResourcesImpl impl = new ResourcesImpl(assets, displayMetrics, config, daj);
805+
final ResourcesImpl impl = new ResourcesImpl(assets, displayMetrics, config, daj, true);
753806

754807
if (DEBUG) {
755808
Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
@@ -1832,31 +1885,32 @@ private void redirectAllResourcesToNewImplLocked(
18321885
for (int i = 0; i < resourcesCount; i++) {
18331886
final WeakReference<Resources> ref = mAllResourceReferences.get(i);
18341887
final Resources r = ref != null ? ref.get() : null;
1835-
if (r != null) {
1836-
final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
1837-
if (key != null) {
1838-
final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
1839-
if (impl == null) {
1840-
throw new Resources.NotFoundException("failed to redirect ResourcesImpl");
1841-
}
1842-
r.setImpl(impl);
1843-
} else {
1844-
// ResourcesKey is null which means the ResourcesImpl could belong to a
1845-
// Resources created by application through Resources constructor and was not
1846-
// managed by ResourcesManager, so the ResourcesImpl needs to be recreated to
1847-
// have shared library asset paths appended if there are any.
1848-
if (r.getImpl() != null) {
1849-
final ResourcesImpl oldImpl = r.getImpl();
1850-
final AssetManager oldAssets = oldImpl.getAssets();
1851-
// ResourcesImpl constructor will help to append shared library asset paths.
1852-
if (oldAssets != AssetManager.getSystem() && oldAssets.isUpToDate()) {
1853-
final ResourcesImpl newImpl = new ResourcesImpl(oldAssets,
1854-
oldImpl.getMetrics(), oldImpl.getConfiguration(),
1855-
oldImpl.getDisplayAdjustments());
1888+
if (r == null) {
1889+
continue;
1890+
}
1891+
final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
1892+
if (key != null) {
1893+
final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
1894+
if (impl == null) {
1895+
throw new Resources.NotFoundException("failed to redirect ResourcesImpl");
1896+
}
1897+
r.setImpl(impl);
1898+
} else {
1899+
// ResourcesKey is null which means the ResourcesImpl could belong to a
1900+
// Resources created by application through Resources constructor and was not
1901+
// managed by ResourcesManager, so the ResourcesImpl needs to be recreated to
1902+
// have shared library asset paths appended if there are any.
1903+
final ResourcesImpl oldImpl = r.getImpl();
1904+
if (oldImpl != null) {
1905+
final AssetManager oldAssets = oldImpl.getAssets();
1906+
// ResourcesImpl constructor will help to append shared library asset paths.
1907+
if (oldAssets != AssetManager.getSystem()) {
1908+
if (oldAssets.isUpToDate()) {
1909+
final ResourcesImpl newImpl = new ResourcesImpl(oldImpl);
18561910
r.setImpl(newImpl);
18571911
} else {
1858-
Slog.w(TAG, "Skip appending shared library asset paths for the "
1859-
+ "Resource as its assets are not up to date.");
1912+
Slog.w(TAG, "Skip appending shared library asset paths for "
1913+
+ "the Resources as its assets are not up to date.");
18601914
}
18611915
}
18621916
}

core/java/android/content/res/ApkAssets.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ public final class ApkAssets {
124124

125125
@Nullable
126126
@GuardedBy("this")
127-
private final StringBlock mStringBlock; // null or closed if mNativePtr = 0.
127+
private StringBlock mStringBlock; // null or closed if mNativePtr = 0.
128128

129129
@PropertyFlags
130130
private final int mFlags;
131131

132+
private final boolean mIsOverlay;
133+
132134
@Nullable
133135
private final AssetsProvider mAssets;
134136

@@ -302,40 +304,43 @@ public static ApkAssets loadEmptyForLoader(@PropertyFlags int flags,
302304

303305
private ApkAssets(@FormatType int format, @NonNull String path, @PropertyFlags int flags,
304306
@Nullable AssetsProvider assets) throws IOException {
307+
this(format, flags, assets);
305308
Objects.requireNonNull(path, "path");
306-
mFlags = flags;
307309
mNativePtr = nativeLoad(format, path, flags, assets);
308310
mStringBlock = new StringBlock(nativeGetStringBlock(mNativePtr), true /*useSparse*/);
309-
mAssets = assets;
310311
}
311312

312313
private ApkAssets(@FormatType int format, @NonNull FileDescriptor fd,
313314
@NonNull String friendlyName, @PropertyFlags int flags, @Nullable AssetsProvider assets)
314315
throws IOException {
316+
this(format, flags, assets);
315317
Objects.requireNonNull(fd, "fd");
316318
Objects.requireNonNull(friendlyName, "friendlyName");
317-
mFlags = flags;
318319
mNativePtr = nativeLoadFd(format, fd, friendlyName, flags, assets);
319320
mStringBlock = new StringBlock(nativeGetStringBlock(mNativePtr), true /*useSparse*/);
320-
mAssets = assets;
321321
}
322322

323323
private ApkAssets(@FormatType int format, @NonNull FileDescriptor fd,
324324
@NonNull String friendlyName, long offset, long length, @PropertyFlags int flags,
325325
@Nullable AssetsProvider assets) throws IOException {
326+
this(format, flags, assets);
326327
Objects.requireNonNull(fd, "fd");
327328
Objects.requireNonNull(friendlyName, "friendlyName");
328-
mFlags = flags;
329329
mNativePtr = nativeLoadFdOffsets(format, fd, friendlyName, offset, length, flags, assets);
330330
mStringBlock = new StringBlock(nativeGetStringBlock(mNativePtr), true /*useSparse*/);
331-
mAssets = assets;
332331
}
333332

334333
private ApkAssets(@PropertyFlags int flags, @Nullable AssetsProvider assets) {
335-
mFlags = flags;
334+
this(FORMAT_APK, flags, assets);
336335
mNativePtr = nativeLoadEmpty(flags, assets);
337336
mStringBlock = null;
337+
}
338+
339+
private ApkAssets(@FormatType int format, @PropertyFlags int flags,
340+
@Nullable AssetsProvider assets) {
341+
mFlags = flags;
338342
mAssets = assets;
343+
mIsOverlay = format == FORMAT_IDMAP;
339344
}
340345

341346
@UnsupportedAppUsage
@@ -425,6 +430,18 @@ public boolean isUpToDate() {
425430
}
426431
}
427432

433+
public boolean isSystem() {
434+
return (mFlags & PROPERTY_SYSTEM) != 0;
435+
}
436+
437+
public boolean isSharedLib() {
438+
return (mFlags & PROPERTY_DYNAMIC) != 0;
439+
}
440+
441+
public boolean isOverlay() {
442+
return mIsOverlay;
443+
}
444+
428445
@Override
429446
public String toString() {
430447
return "ApkAssets{path=" + getDebugName() + "}";

core/java/android/content/res/ResourcesImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,25 @@ static void resetDrawableStateCache() {
203203
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
204204
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
205205
@Nullable Configuration config, @NonNull DisplayAdjustments displayAdjustments) {
206-
mAssets = assets;
207-
mAppliedSharedLibsHash =
208-
ResourcesManager.getInstance().updateResourceImplWithRegisteredLibs(this);
206+
// Don't reuse assets by default as we have no control over whether they're already
207+
// inside some other ResourcesImpl.
208+
this(assets, metrics, config, displayAdjustments, false);
209+
}
210+
211+
public ResourcesImpl(@NonNull ResourcesImpl orig) {
212+
// We know for sure that the other assets are in use, so can't reuse the object here.
213+
this(orig.getAssets(), orig.getMetrics(), orig.getConfiguration(),
214+
orig.getDisplayAdjustments(), false);
215+
}
216+
217+
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
218+
@Nullable Configuration config, @NonNull DisplayAdjustments displayAdjustments,
219+
boolean reuseAssets) {
220+
final var assetsAndHash =
221+
ResourcesManager.getInstance().updateResourceImplAssetsWithRegisteredLibs(assets,
222+
reuseAssets);
223+
mAssets = assetsAndHash.first;
224+
mAppliedSharedLibsHash = assetsAndHash.second;
209225
mMetrics.setToDefaults();
210226
mDisplayAdjustments = displayAdjustments;
211227
mConfiguration.setToDefaults();

packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ public void onCreate(Bundle savedInstanceState) {
123123
mReviewGrantedConsentRequired = launchingIntent.getBooleanExtra(
124124
EXTRA_USER_REVIEW_GRANTED_CONSENT, false);
125125

126-
mPackageName = getCallingPackage();
127-
128-
// This activity is launched directly by an app, or system server. System server provides
129-
// the package name through the intent if so.
130-
if (mPackageName == null) {
126+
// The original requester of this activity start
127+
mPackageName = getLaunchedFromPackage();
128+
129+
// This activity is launched directly by using startActivity(),
130+
// thus getCallingPackage() will be null.
131+
if (getCallingPackage() == null) {
132+
// System server provides the package name through the intent if so and is able to get
133+
// the result back. Other applications can't.
131134
if (launchingIntent.hasExtra(EXTRA_PACKAGE_REUSING_GRANTED_CONSENT)) {
132135
mPackageName = launchingIntent.getStringExtra(
133136
EXTRA_PACKAGE_REUSING_GRANTED_CONSENT);

packages/SystemUI/src/com/android/systemui/tuner/TunerServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class TunerServiceImpl extends TunerService {
7373
// shouldn't be reset with tuner settings.
7474
private static final String[] RESET_EXCEPTION_LIST = new String[] {
7575
QSHost.TILES_SETTING,
76+
Settings.Secure.DOUBLE_TAP_TO_WAKE,
7677
Settings.Secure.DOZE_ALWAYS_ON,
7778
Settings.Secure.MEDIA_CONTROLS_RESUME,
7879
Settings.Secure.MEDIA_CONTROLS_RECOMMENDATION

services/autofill/java/com/android/server/autofill/Helper.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
import android.app.assist.AssistStructure;
2929
import android.app.assist.AssistStructure.ViewNode;
3030
import android.app.assist.AssistStructure.WindowNode;
31+
import android.app.slice.Slice;
32+
import android.app.slice.SliceItem;
3133
import android.content.ComponentName;
3234
import android.content.Context;
35+
import android.graphics.drawable.Icon;
3336
import android.hardware.display.DisplayManager;
3437
import android.metrics.LogMaker;
3538
import android.os.UserHandle;
@@ -97,11 +100,12 @@ private static boolean checkRemoteViewUriPermissions(
97100
@UserIdInt int userId, @NonNull RemoteViews rView) {
98101
final AtomicBoolean permissionsOk = new AtomicBoolean(true);
99102

100-
rView.visitUris(uri -> {
101-
int uriOwnerId = android.content.ContentProvider.getUserIdFromUri(uri);
102-
boolean allowed = uriOwnerId == userId;
103-
permissionsOk.set(allowed & permissionsOk.get());
104-
});
103+
rView.visitUris(
104+
uri -> {
105+
int uriOwnerId = android.content.ContentProvider.getUserIdFromUri(uri, userId);
106+
boolean allowed = uriOwnerId == userId;
107+
permissionsOk.set(allowed & permissionsOk.get());
108+
});
105109

106110
return permissionsOk.get();
107111
}
@@ -150,6 +154,47 @@ public static Context getUserContext(Context context) {
150154
return (ok ? rView : null);
151155
}
152156

157+
/**
158+
* Checks the URI permissions of the icon in the slice, to see if the current userId is able to
159+
* access it.
160+
*
161+
* <p>Returns null if slice contains user inaccessible icons
162+
*
163+
* <p>TODO: instead of returning a null Slice when the current userId cannot access an icon,
164+
* return a reconstructed Slice without the icons. This is currently non-trivial since there are
165+
* no public methods to generically add SliceItems to Slices
166+
*/
167+
public static @Nullable Slice sanitizeSlice(Slice slice) {
168+
if (slice == null) {
169+
return null;
170+
}
171+
172+
int userId = ActivityManager.getCurrentUser();
173+
174+
// Recontruct the Slice, filtering out bad icons
175+
for (SliceItem sliceItem : slice.getItems()) {
176+
if (!sliceItem.getFormat().equals(SliceItem.FORMAT_IMAGE)) {
177+
// Not an image slice
178+
continue;
179+
}
180+
181+
Icon icon = sliceItem.getIcon();
182+
if (icon.getType() != Icon.TYPE_URI
183+
&& icon.getType() != Icon.TYPE_URI_ADAPTIVE_BITMAP) {
184+
// No URIs to sanitize
185+
continue;
186+
}
187+
188+
int iconUriId = android.content.ContentProvider.getUserIdFromUri(icon.getUri(), userId);
189+
190+
if (iconUriId != userId) {
191+
Slog.w(TAG, "sanitizeSlice() user: " + userId + " cannot access icons in Slice");
192+
return null;
193+
}
194+
}
195+
196+
return slice;
197+
}
153198

154199
@Nullable
155200
static AutofillId[] toArray(@Nullable ArraySet<AutofillId> set) {

services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.util.Slog;
2828

2929
import com.android.server.LocalServices;
30+
import com.android.server.autofill.Helper;
3031
import com.android.server.autofill.RemoteInlineSuggestionRenderService;
3132
import com.android.server.inputmethod.InputMethodManagerInternal;
3233

@@ -83,6 +84,10 @@ final class RemoteInlineSuggestionViewConnector {
8384
*/
8485
public boolean renderSuggestion(int width, int height,
8586
@NonNull IInlineSuggestionUiCallback callback) {
87+
if (Helper.sanitizeSlice(mInlinePresentation.getSlice()) == null) {
88+
if (sDebug) Slog.d(TAG, "Skipped rendering inline suggestion.");
89+
return false;
90+
}
8691
if (mRemoteRenderService != null) {
8792
if (sDebug) Slog.d(TAG, "Request to recreate the UI");
8893
mRemoteRenderService.renderSuggestion(callback, mInlinePresentation, width, height,

0 commit comments

Comments
 (0)