Merge "Fix a potential concurrency issue for loading CDB file Bug: 158919530" into ub-launcher3-rvc-dev

This commit is contained in:
Hyunyoung Song 2020-06-19 21:48:30 +00:00 committed by Android (Google) Code Review
commit bb8257344c
4 changed files with 11 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import com.android.launcher3.folder.FolderNameProvider;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.Executors;
/**
* Interface defining an object that can receive a drag.
@ -84,7 +85,9 @@ public interface DropTarget {
public DragObject(Context context) {
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
folderNameProvider = FolderNameProvider.newInstance(context);
Executors.MODEL_EXECUTOR.post(() -> {
folderNameProvider = FolderNameProvider.newInstance(context);
});
}
}

View File

@ -1005,7 +1005,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (!items.isEmpty()) {
mLauncher.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
}
if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind) {
if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind
&& total > 1 /* no need to update if there's one icon */) {
Executors.MODEL_EXECUTOR.post(() -> {
FolderNameInfo[] nameInfos =
new FolderNameInfo[FolderNameProvider.SUGGEST_MAX];

View File

@ -409,7 +409,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
FolderNameInfo[] nameInfos =
new FolderNameInfo[FolderNameProvider.SUGGEST_MAX];
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
Executors.UI_HELPER_EXECUTOR.post(() -> {
Executors.MODEL_EXECUTOR.post(() -> {
d.folderNameProvider.getSuggestedFolderName(
getContext(), mInfo.contents, nameInfos);
showFinalView(finalIndex, item, nameInfos, d.logInstanceId);

View File

@ -31,6 +31,7 @@ import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.ResourceBasedOverride;
import java.util.ArrayList;
@ -64,6 +65,7 @@ public class FolderNameProvider implements ResourceBasedOverride {
public static FolderNameProvider newInstance(Context context) {
FolderNameProvider fnp = Overrides.getObject(FolderNameProvider.class,
context.getApplicationContext(), R.string.folder_name_provider_class);
Preconditions.assertWorkerThread();
fnp.load(context);
return fnp;
@ -71,6 +73,7 @@ public class FolderNameProvider implements ResourceBasedOverride {
public static FolderNameProvider newInstance(Context context, List<AppInfo> appInfos,
IntSparseArrayMap<FolderInfo> folderInfos) {
Preconditions.assertWorkerThread();
FolderNameProvider fnp = Overrides.getObject(FolderNameProvider.class,
context.getApplicationContext(), R.string.folder_name_provider_class);
fnp.load(appInfos, folderInfos);
@ -94,7 +97,7 @@ public class FolderNameProvider implements ResourceBasedOverride {
public void getSuggestedFolderName(Context context,
ArrayList<WorkspaceItemInfo> workspaceItemInfos,
FolderNameInfo[] nameInfos) {
Preconditions.assertWorkerThread();
if (DEBUG) {
Log.d(TAG, "getSuggestedFolderName:" + Arrays.toString(nameInfos));
}