Skip to content

Commit

Permalink
Support feed being loaded from an isolated split
Browse files Browse the repository at this point in the history
These changes are needed to allow feed to access resources from the feed
isolated split. The implementation of the DFM is in the internal change
here:
https://chrome-internal-review.googlesource.com/c/clank/internal/apps/+/3336642

The feed DFM also uncovered a bug in how we were handling feature jars in
R8. If multiple features specified a jar that was not in the base module,
the jar would only be applied to the first feature that specified it
instead of moving to the base module.

Bug: 1126301
Change-Id: Iedc67a97358414adfa82e7a199bf5c72b1f47eae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469235
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Justin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817287}
  • Loading branch information
clarkduvall authored and Commit Bot committed Oct 15, 2020
1 parent 7c60fc7 commit 233fbe3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
12 changes: 10 additions & 2 deletions build/android/gyp/proguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,15 @@ def _OptimizeWithR8(options,
for main_dex_rule in options.main_dex_rules_path:
cmd += ['--main-dex-rules', main_dex_rule]

module_input_jars = set(base_dex_context.input_paths)
base_jars = set(base_dex_context.input_paths)
# If a jar is present in multiple features, it should be moved to the base
# module.
all_feature_jars = set()
for feature in feature_contexts:
base_jars.update(all_feature_jars.intersection(feature.input_paths))
all_feature_jars.update(feature.input_paths)

module_input_jars = base_jars.copy()
for feature in feature_contexts:
feature_input_jars = [
p for p in feature.input_paths if p not in module_input_jars
Expand All @@ -297,7 +305,7 @@ def _OptimizeWithR8(options,
for in_jar in feature_input_jars:
cmd += ['--feature', in_jar, feature.staging_dir]

cmd += base_dex_context.input_paths
cmd += sorted(base_jars)
# Add any extra input jars to the base module (e.g. desugar runtime).
extra_jars = set(options.input_paths) - module_input_jars
cmd += sorted(extra_jars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.view.ContextThemeWrapper;
import android.view.View;
Expand All @@ -25,6 +27,7 @@
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.R;
Expand Down Expand Up @@ -70,6 +73,7 @@
import org.chromium.ui.mojom.WindowOpenDisposition;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -84,6 +88,8 @@
public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHandler {
private static final String TAG = "FeedStreamSurface";

private static final String FEED_SPLIT_NAME = "feedv2";

private static final int SNACKBAR_DURATION_MS_SHORT = 4000;
private static final int SNACKBAR_DURATION_MS_LONG = 10000;

Expand Down Expand Up @@ -211,15 +217,17 @@ public static void clearAll() {
*/
private static class FeedProcessScopeDependencyProvider
implements ProcessScopeDependencyProvider {
private Context mContext;
private ImageFetchClient mImageFetchClient;

FeedProcessScopeDependencyProvider() {
mContext = createFeedContext(ContextUtils.getApplicationContext());
mImageFetchClient = new FeedImageFetchClient();
}

@Override
public Context getContext() {
return ContextUtils.getApplicationContext();
return mContext;
}

@Deprecated
Expand Down Expand Up @@ -288,7 +296,7 @@ private class FeedSurfaceScopeDependencyProvider implements SurfaceScopeDependen
final boolean mDarkMode;

FeedSurfaceScopeDependencyProvider(Context activityContext, boolean darkMode) {
mActivityContext = activityContext;
mActivityContext = createFeedContext(activityContext);
mDarkMode = darkMode;
}

Expand Down Expand Up @@ -1008,6 +1016,27 @@ void streamScrolled(int dx, int dy) {
mScrollReporter.trackScroll(dx, dy);
}

private static Context createFeedContext(Context context) {
// Isolated splits are only supported in O+, so just return the base context on other
// versions, since it will have access to all splits.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return context;
}

// If the feed split does not exist, return the original context.
String[] splitNames = ApiHelperForO.getSplitNames(context.getApplicationInfo());
if (splitNames == null || !Arrays.asList(splitNames).contains(FEED_SPLIT_NAME)) {
return context;
}

try {
return ApiHelperForO.createContextForSplit(context, FEED_SPLIT_NAME);
} catch (PackageManager.NameNotFoundException e) {
// Feed is not in a split.
return context;
}
}

// Detects animation finishes in RecyclerView.
// https://stackoverflow.com/questions/33710605/detect-animation-finish-in-androids-recyclerview
private class RecyclerViewAnimationFinishDetector implements ItemAnimatorFinishedListener {
Expand Down

0 comments on commit 233fbe3

Please sign in to comment.