Commit 233fbe3a authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Support feed being loaded from an isolated split

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: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817287}
parent 7c60fc77
...@@ -288,7 +288,15 @@ def _OptimizeWithR8(options, ...@@ -288,7 +288,15 @@ def _OptimizeWithR8(options,
for main_dex_rule in options.main_dex_rules_path: for main_dex_rule in options.main_dex_rules_path:
cmd += ['--main-dex-rules', main_dex_rule] 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: for feature in feature_contexts:
feature_input_jars = [ feature_input_jars = [
p for p in feature.input_paths if p not in module_input_jars p for p in feature.input_paths if p not in module_input_jars
...@@ -297,7 +305,7 @@ def _OptimizeWithR8(options, ...@@ -297,7 +305,7 @@ def _OptimizeWithR8(options,
for in_jar in feature_input_jars: for in_jar in feature_input_jars:
cmd += ['--feature', in_jar, feature.staging_dir] 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). # Add any extra input jars to the base module (e.g. desugar runtime).
extra_jars = set(options.input_paths) - module_input_jars extra_jars = set(options.input_paths) - module_input_jars
cmd += sorted(extra_jars) cmd += sorted(extra_jars)
......
...@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.feed.v2; ...@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.feed.v2;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
...@@ -25,6 +27,7 @@ import org.chromium.base.ThreadUtils; ...@@ -25,6 +27,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits; import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -70,6 +73,7 @@ import org.chromium.ui.base.PageTransition; ...@@ -70,6 +73,7 @@ import org.chromium.ui.base.PageTransition;
import org.chromium.ui.mojom.WindowOpenDisposition; import org.chromium.ui.mojom.WindowOpenDisposition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -84,6 +88,8 @@ import java.util.Map; ...@@ -84,6 +88,8 @@ import java.util.Map;
public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHandler { public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHandler {
private static final String TAG = "FeedStreamSurface"; 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_SHORT = 4000;
private static final int SNACKBAR_DURATION_MS_LONG = 10000; private static final int SNACKBAR_DURATION_MS_LONG = 10000;
...@@ -211,15 +217,17 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -211,15 +217,17 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
*/ */
private static class FeedProcessScopeDependencyProvider private static class FeedProcessScopeDependencyProvider
implements ProcessScopeDependencyProvider { implements ProcessScopeDependencyProvider {
private Context mContext;
private ImageFetchClient mImageFetchClient; private ImageFetchClient mImageFetchClient;
FeedProcessScopeDependencyProvider() { FeedProcessScopeDependencyProvider() {
mContext = createFeedContext(ContextUtils.getApplicationContext());
mImageFetchClient = new FeedImageFetchClient(); mImageFetchClient = new FeedImageFetchClient();
} }
@Override @Override
public Context getContext() { public Context getContext() {
return ContextUtils.getApplicationContext(); return mContext;
} }
@Deprecated @Deprecated
...@@ -288,7 +296,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -288,7 +296,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
final boolean mDarkMode; final boolean mDarkMode;
FeedSurfaceScopeDependencyProvider(Context activityContext, boolean darkMode) { FeedSurfaceScopeDependencyProvider(Context activityContext, boolean darkMode) {
mActivityContext = activityContext; mActivityContext = createFeedContext(activityContext);
mDarkMode = darkMode; mDarkMode = darkMode;
} }
...@@ -1008,6 +1016,27 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -1008,6 +1016,27 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
mScrollReporter.trackScroll(dx, 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. // Detects animation finishes in RecyclerView.
// https://stackoverflow.com/questions/33710605/detect-animation-finish-in-androids-recyclerview // https://stackoverflow.com/questions/33710605/detect-animation-finish-in-androids-recyclerview
private class RecyclerViewAnimationFinishDetector implements ItemAnimatorFinishedListener { private class RecyclerViewAnimationFinishDetector implements ItemAnimatorFinishedListener {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment