2020-07-27 17:50:33 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 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 static com.android.launcher3.util.PackageManagerHelper.hasShortcutsPermission;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2020-07-29 15:03:46 -07:00
|
|
|
import android.content.pm.ShortcutInfo;
|
2020-07-27 17:50:33 -07:00
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2020-07-27 17:50:33 -07:00
|
|
|
import androidx.annotation.WorkerThread;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
|
|
|
|
import com.android.launcher3.R;
|
2020-07-29 15:03:46 -07:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutKey;
|
2020-07-27 17:50:33 -07:00
|
|
|
import com.android.launcher3.util.ResourceBasedOverride;
|
|
|
|
|
|
2021-02-26 12:56:25 -08:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
|
import java.io.PrintWriter;
|
2020-07-29 15:03:46 -07:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
2020-07-27 17:50:33 -07:00
|
|
|
/**
|
|
|
|
|
* Class to extend LauncherModel functionality to provide extra data
|
|
|
|
|
*/
|
|
|
|
|
public class ModelDelegate implements ResourceBasedOverride {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates and initializes a new instance of the delegate
|
|
|
|
|
*/
|
|
|
|
|
public static ModelDelegate newInstance(
|
2021-08-26 10:37:17 -07:00
|
|
|
Context context, LauncherAppState app, AllAppsList appsList, BgDataModel dataModel,
|
|
|
|
|
boolean isPrimaryInstance) {
|
2020-07-27 17:50:33 -07:00
|
|
|
ModelDelegate delegate = Overrides.getObject(
|
|
|
|
|
ModelDelegate.class, context, R.string.model_delegate_class);
|
2022-02-16 10:23:54 +00:00
|
|
|
delegate.init(context, app, appsList, dataModel, isPrimaryInstance);
|
2020-07-27 17:50:33 -07:00
|
|
|
return delegate;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:47:38 +00:00
|
|
|
protected Context mContext;
|
2020-07-27 17:50:33 -07:00
|
|
|
protected LauncherAppState mApp;
|
|
|
|
|
protected AllAppsList mAppsList;
|
|
|
|
|
protected BgDataModel mDataModel;
|
2021-08-26 10:37:17 -07:00
|
|
|
protected boolean mIsPrimaryInstance;
|
2020-07-27 17:50:33 -07:00
|
|
|
|
|
|
|
|
public ModelDelegate() { }
|
|
|
|
|
|
2022-02-16 10:23:54 +00:00
|
|
|
/**
|
|
|
|
|
* Initializes the object with the given params.
|
|
|
|
|
*/
|
|
|
|
|
private void init(Context context, LauncherAppState app, AllAppsList appsList,
|
|
|
|
|
BgDataModel dataModel, boolean isPrimaryInstance) {
|
|
|
|
|
this.mApp = app;
|
|
|
|
|
this.mAppsList = appsList;
|
|
|
|
|
this.mDataModel = dataModel;
|
|
|
|
|
this.mIsPrimaryInstance = isPrimaryInstance;
|
|
|
|
|
this.mContext = context;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** Called periodically to validate and update any data */
|
2020-07-27 17:50:33 -07:00
|
|
|
@WorkerThread
|
|
|
|
|
public void validateData() {
|
|
|
|
|
if (hasShortcutsPermission(mApp.getContext())
|
|
|
|
|
!= mAppsList.hasShortcutHostPermission()) {
|
|
|
|
|
mApp.getModel().forceReload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** Load workspace items (for example, those in the hot seat) if any in the data model */
|
2020-07-27 17:50:33 -07:00
|
|
|
@WorkerThread
|
2023-04-07 19:28:05 +00:00
|
|
|
public void loadAndBindWorkspaceItems(@NonNull UserManagerState ums,
|
|
|
|
|
@NonNull BgDataModel.Callbacks[] callbacks,
|
|
|
|
|
@NonNull Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) { }
|
2022-11-22 20:02:07 +00:00
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** Load all apps items if any in the data model */
|
2022-11-22 20:02:07 +00:00
|
|
|
@WorkerThread
|
2023-04-07 19:28:05 +00:00
|
|
|
public void loadAndBindAllAppsItems(@NonNull UserManagerState ums,
|
|
|
|
|
@NonNull BgDataModel.Callbacks[] callbacks,
|
|
|
|
|
@NonNull Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) { }
|
2022-11-22 20:02:07 +00:00
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** Load other items like widget recommendations if any in the data model */
|
2022-11-22 20:02:07 +00:00
|
|
|
@WorkerThread
|
2023-04-07 19:28:05 +00:00
|
|
|
public void loadAndBindOtherItems(@NonNull BgDataModel.Callbacks[] callbacks) { }
|
2022-11-22 20:02:07 +00:00
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** binds everything not bound by launcherBinder */
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public void bindAllModelExtras(@NonNull BgDataModel.Callbacks[] callbacks) { }
|
|
|
|
|
|
|
|
|
|
/** Marks the ModelDelegate as active */
|
2022-11-22 20:02:07 +00:00
|
|
|
public void markActive() { }
|
2020-07-27 17:50:33 -07:00
|
|
|
|
2023-04-07 19:28:05 +00:00
|
|
|
/** Load String cache */
|
2021-12-20 16:47:38 +00:00
|
|
|
@WorkerThread
|
2023-04-07 19:28:05 +00:00
|
|
|
public void loadStringCache(@NonNull StringCache cache) {
|
2022-03-14 13:58:51 +00:00
|
|
|
cache.loadStrings(mContext);
|
2021-12-20 16:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 18:49:28 -07:00
|
|
|
/**
|
|
|
|
|
* Called during loader after workspace loading is complete
|
|
|
|
|
*/
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public void workspaceLoadComplete() { }
|
|
|
|
|
|
2020-10-13 13:37:28 -07:00
|
|
|
/**
|
|
|
|
|
* Called at the end of model load task
|
|
|
|
|
*/
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public void modelLoadComplete() { }
|
|
|
|
|
|
2020-07-27 17:50:33 -07:00
|
|
|
/**
|
|
|
|
|
* Called when the delegate is no loner needed
|
|
|
|
|
*/
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public void destroy() { }
|
2020-07-29 15:03:46 -07:00
|
|
|
|
2021-02-26 12:56:25 -08:00
|
|
|
/**
|
|
|
|
|
* Add data to a dumpsys request for Launcher (e.g. for bug reports).
|
|
|
|
|
*
|
|
|
|
|
* @see com.android.launcher3.Launcher#dump(java.lang.String, java.io.FileDescriptor,
|
|
|
|
|
* java.io.PrintWriter, java.lang.String[])
|
|
|
|
|
**/
|
|
|
|
|
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { }
|
2020-07-27 17:50:33 -07:00
|
|
|
}
|