diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 1d8877c51e..0490832173 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -58,6 +58,7 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.Utilities; +import com.android.launcher3.model.ModelPreload; import com.android.launcher3.util.TraceHelper; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; @@ -195,6 +196,7 @@ public class TouchInteractionService extends Service { mEventQueue = new MotionEventQueue(Choreographer.getInstance(), mNoOpTouchConsumer); sConnected = true; + new ModelPreload().start(this); initBackgroundChoreographer(); } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 1b169f5304..929606e4a4 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -20,7 +20,6 @@ import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD; import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD; import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.ContentProviderOperation; import android.content.ContentResolver; import android.content.ContentValues; @@ -40,21 +39,18 @@ import android.util.Pair; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; import com.android.launcher3.compat.UserManagerCompat; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.model.AddWorkspaceItemsTask; +import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.model.CacheDataUpdatedTask; -import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.LoaderResults; import com.android.launcher3.model.LoaderTask; import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.PackageInstallStateChangedTask; -import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.model.PackageUpdatedTask; import com.android.launcher3.model.ShortcutsChangedTask; import com.android.launcher3.model.UserLockStateChangedTask; -import com.android.launcher3.model.WidgetItem; import com.android.launcher3.provider.LauncherDbUtils; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 883c33d5a3..00dd3aac61 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -54,7 +54,6 @@ import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIconPreviewVerifier; -import com.android.launcher3.graphics.IconNormalizer; import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.logging.FileLog; import com.android.launcher3.provider.ImportDataTask; diff --git a/src/com/android/launcher3/model/ModelPreload.java b/src/com/android/launcher3/model/ModelPreload.java new file mode 100644 index 0000000000..6f33bedb0e --- /dev/null +++ b/src/com/android/launcher3/model/ModelPreload.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.model; + +import android.content.Context; +import android.support.annotation.WorkerThread; +import android.util.Log; + +import com.android.launcher3.AllAppsList; +import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherModel; +import com.android.launcher3.LauncherModel.ModelUpdateTask; + +import java.util.concurrent.Executor; + +/** + * Utility class to preload LauncherModel + */ +public class ModelPreload implements ModelUpdateTask { + + private static final String TAG = "ModelPreload"; + + private LauncherAppState mApp; + private LauncherModel mModel; + private BgDataModel mBgDataModel; + private AllAppsList mAllAppsList; + + @Override + public final void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, + AllAppsList allAppsList, Executor uiExecutor) { + mApp = app; + mModel = model; + mBgDataModel = dataModel; + mAllAppsList = allAppsList; + } + + @Override + public final void run() { + if (!mModel.isModelLoaded()) { + Log.d(TAG, "Workspace not loaded, loading now"); + mModel.startLoaderForResults( + new LoaderResults(mApp, mBgDataModel, mAllAppsList, 0, null)); + } + Log.d(TAG, "Preload completed : " + mModel.isModelLoaded()); + onComplete(mModel.isModelLoaded()); + } + + /** + * Called when the task is complete + */ + @WorkerThread + public void onComplete(boolean isSuccess) { } + + public void start(Context context) { + LauncherAppState.getInstance(context).getModel().enqueueModelUpdateTask(this); + } +} \ No newline at end of file