Merge branch 'heads/android-14.0.0_r18' into 14-dev

This commit is contained in:
MrSluffy
2023-12-14 15:26:43 +08:00
parent 32700b0100
commit cc8f9828ab
756 changed files with 23785 additions and 12235 deletions

View File

@@ -22,9 +22,7 @@ import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURC
import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
import static com.android.launcher3.config.FeatureFlags.IS_STUDIO_BUILD;
import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;
import static com.android.launcher3.testing.shared.TestProtocol.sDebugTracing;
import static com.android.launcher3.testing.shared.TestProtocol.testLogD;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
@@ -71,7 +69,6 @@ import com.android.launcher3.pm.InstallSessionTracker;
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageUserKey;
@@ -88,8 +85,10 @@ import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Maintains in-memory state of the Launcher. It is expected that there should be only one
* LauncherModel object held in a static. Also provide APIs for updating the database state
* Maintains in-memory state of the Launcher. It is expected that there should
* be only one
* LauncherModel object held in a static. Also provide APIs for updating the
* database state
* for the Launcher.
*/
public class LauncherModel extends LauncherApps.Callback implements InstallSessionTracker.Callback {
@@ -98,9 +97,11 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
static final String TAG = "Launcher.Model";
// Broadcast intent to track when the profile gets locked:
// ACTION_MANAGED_PROFILE_UNAVAILABLE can be used until Android U where profile no longer gets
// ACTION_MANAGED_PROFILE_UNAVAILABLE can be used until Android U where profile
// no longer gets
// locked when paused.
// ACTION_PROFILE_INACCESSIBLE always means that the profile is getting locked but it only
// ACTION_PROFILE_INACCESSIBLE always means that the profile is getting locked
// but it only
// appeared in Android S.
private static final String ACTION_PROFILE_LOCKED = Utilities.ATLEAST_U
? Intent.ACTION_PROFILE_INACCESSIBLE
@@ -116,12 +117,16 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
private LoaderTask mLoaderTask;
private boolean mIsLoaderTaskRunning;
// only allow this once per reboot to reload work apps
private boolean mShouldReloadWorkProfile = true;
// Indicates whether the current model data is valid or not.
// We start off with everything not loaded. After that, we assume that
// our monitoring of the package manager provides all updates and we never
// need to do a requery. This is only ever touched from the loader thread.
private boolean mModelLoaded;
private boolean mModelDestroyed = false;
public boolean isModelLoaded() {
synchronized (mLock) {
return mModelLoaded && mLoaderTask == null && !mModelDestroyed;
@@ -136,7 +141,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
private final AllAppsList mBgAllAppsList;
/**
* All the static data should be accessed on the background thread, A lock should be acquired
* All the static data should be accessed on the background thread, A lock
* should be acquired
* on this object when accessing any data from this model.
*/
@NonNull
@@ -145,6 +151,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
@NonNull
private final ModelDelegate mModelDelegate;
private int mLastLoadId = -1;
// Runnable to check if the shortcuts permission has changed.
@NonNull
private final Runnable mDataValidationCheck = new Runnable() {
@@ -298,33 +306,13 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
public void onBroadcastIntent(@NonNull final Intent intent) {
if (DEBUG_RECEIVER || sDebugTracing) Log.d(TAG, "onReceive intent=" + intent);
if (DEBUG_RECEIVER || sDebugTracing)
Log.d(TAG, "onReceive intent=" + intent);
final String action = intent.getAction();
if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
// If we have changed locale we need to clear out the labels in all apps/workspace.
// If we have changed locale we need to clear out the labels in all
// apps/workspace.
forceReload();
} else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)
|| Intent.ACTION_PROFILE_INACCESSIBLE.equals(action)) {
UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.WORK_TAB_MISSING, "onBroadcastIntent intentAction: " + action +
" user: " + user);
}
if (user != null) {
if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
enqueueModelUpdateTask(new PackageUpdatedTask(
PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user));
}
if (ACTION_PROFILE_LOCKED.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
enqueueModelUpdateTask(new UserLockStateChangedTask(
user, Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)));
}
}
} else if (ACTION_DEVICE_POLICY_RESOURCE_UPDATED.equals(action)) {
enqueueModelUpdateTask(new ReloadStringCacheTask(mModelDelegate));
} else if (IS_STUDIO_BUILD && ACTION_FORCE_ROLOAD.equals(action)) {
@@ -337,7 +325,33 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
/**
* Reloads the workspace items from the DB and re-binds the workspace. This should generally
* Called then there use a user event
*
* @see UserCache#addUserEventListener
*/
public void onUserEvent(UserHandle user, String action) {
if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action)
&& mShouldReloadWorkProfile) {
mShouldReloadWorkProfile = false;
forceReload();
} else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
mShouldReloadWorkProfile = false;
enqueueModelUpdateTask(new PackageUpdatedTask(
PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user));
} else if (UserCache.ACTION_PROFILE_LOCKED.equals(action)
|| UserCache.ACTION_PROFILE_UNLOCKED.equals(action)) {
enqueueModelUpdateTask(new UserLockStateChangedTask(
user, UserCache.ACTION_PROFILE_UNLOCKED.equals(action)));
} else if (UserCache.ACTION_PROFILE_ADDED.equals(action)
|| UserCache.ACTION_PROFILE_REMOVED.equals(action)) {
forceReload();
}
}
/**
* Reloads the workspace items from the DB and re-binds the workspace. This
* should generally
* not be called as DB updates are automatically followed by UI update
*/
public void forceReload() {
@@ -347,7 +361,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
mModelLoaded = false;
}
// Start the loader if launcher is already running, otherwise the loader will run,
// Start the loader if launcher is already running, otherwise the loader will
// run,
// the next time launcher starts
if (hasCallbacks()) {
startLoader();
@@ -380,6 +395,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
/**
* Adds a callbacks to receive model updates
*
* @return true if workspace load was performed synchronously
*/
public boolean addCallbacksAndLoad(@NonNull final Callbacks callbacks) {
@@ -401,7 +417,9 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
/**
* Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible.
* Starts the loader. Tries to bind {@params synchronousBindPage} synchronously
* if possible.
*
* @return true if the page could be bound synchronously.
*/
public boolean startLoader() {
@@ -409,7 +427,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
private boolean startLoader(@NonNull final Callbacks[] newCallbacks) {
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
// Enable queue before starting loader. It will get disabled in
// Launcher#finishBindingItems
ItemInstallQueue.INSTANCE.get(mApp.getContext())
.pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
synchronized (mLock) {
@@ -456,6 +475,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
/**
* If there is already a loader task running, tell it to stop.
*
* @return true if an existing loader was stopped.
*/
private boolean stopLoader() {
@@ -472,7 +492,9 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
/**
* Loads the model if not loaded
* @param callback called with the data model upon successful load or null on model thread.
*
* @param callback called with the data model upon successful load or null on
* model thread.
*/
public void loadAsync(@NonNull final Consumer<BgDataModel> callback) {
synchronized (mLock) {
@@ -532,7 +554,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
/**
* Updates the icons and label of all pending icons for the provided package name.
* Updates the icons and label of all pending icons for the provided package
* name.
*/
@Override
public void onUpdateSessionDisplay(@NonNull final PackageUserKey key,
@@ -555,6 +578,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
if (mLoaderTask != task) {
throw new CancellationException("Loader already stopped");
}
mLastLoadId++;
mTask = task;
mIsLoaderTaskRunning = true;
mModelLoaded = false;
@@ -565,7 +589,6 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
synchronized (mLock) {
// Everything loaded bind the data.
mModelLoaded = true;
testLogD(WORK_TAB_MISSING, "launcher model loaded");
}
}
@@ -588,7 +611,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
/**
* Refreshes the cached shortcuts if the shortcut permission has changed.
* Current implementation simply reloads the workspace, but it can be optimized to
* Current implementation simply reloads the workspace, but it can be optimized
* to
* use partial updates similar to {@link UserCache}
*/
public void validateModelDataOnResume() {
@@ -640,7 +664,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
/**
* A runnable which changes/updates the data model of the launcher based on certain events.
* A runnable which changes/updates the data model of the launcher based on
* certain events.
*/
public interface ModelUpdateTask extends Runnable {
@@ -724,4 +749,13 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
return mCallbacksList.toArray(new Callbacks[mCallbacksList.size()]);
}
}
/**
* Returns the ID for the last model load. If the load ID doesn't match for a
* transaction, the
* transaction should be ignored.
*/
public int getLastLoadId() {
return mLastLoadId;
}
}