Log the reason why a WorkspaceItemInfo was removed
In the past we've seen a WorkspaceItem disappeared from the workspace but wasn't able to determine why it was removed. This CL includes the reason why it was removed in the error log, which hopefully would help us debugging similar issues in the future. Bug: 231239260 Test: make Change-Id: Iba3d57568c9b3e011a6b65b26f0d4170d42fe1a5
This commit is contained in:
@@ -23,8 +23,10 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
@@ -272,27 +274,30 @@ public class ModelWriter {
|
||||
/**
|
||||
* Removes the specified item from the database
|
||||
*/
|
||||
public void deleteItemFromDatabase(ItemInfo item) {
|
||||
deleteItemsFromDatabase(Arrays.asList(item));
|
||||
public void deleteItemFromDatabase(ItemInfo item, @Nullable final String reason) {
|
||||
deleteItemsFromDatabase(Arrays.asList(item), reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the items from the database matching {@param matcher}.
|
||||
*/
|
||||
public void deleteItemsFromDatabase(Predicate<ItemInfo> matcher) {
|
||||
public void deleteItemsFromDatabase(@NonNull final Predicate<ItemInfo> matcher,
|
||||
@Nullable final String reason) {
|
||||
deleteItemsFromDatabase(StreamSupport.stream(mBgDataModel.itemsIdMap.spliterator(), false)
|
||||
.filter(matcher).collect(Collectors.toList()));
|
||||
.filter(matcher).collect(Collectors.toList()), reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified items from the database
|
||||
*/
|
||||
public void deleteItemsFromDatabase(final Collection<? extends ItemInfo> items) {
|
||||
public void deleteItemsFromDatabase(final Collection<? extends ItemInfo> items,
|
||||
@Nullable final String reason) {
|
||||
ModelVerifier verifier = new ModelVerifier();
|
||||
FileLog.d(TAG, "removing items from db " + items.stream().map(
|
||||
(item) -> item.getTargetComponent() == null ? ""
|
||||
: item.getTargetComponent().getPackageName()).collect(
|
||||
Collectors.joining(",")));
|
||||
Collectors.joining(","))
|
||||
+ ". Reason: [" + (TextUtils.isEmpty(reason) ? "unknown" : reason) + "]");
|
||||
notifyDelete(items);
|
||||
enqueueDeleteRunnable(() -> {
|
||||
for (ItemInfo item : items) {
|
||||
@@ -328,14 +333,15 @@ public class ModelWriter {
|
||||
/**
|
||||
* Deletes the widget info and the widget id.
|
||||
*/
|
||||
public void deleteWidgetInfo(final LauncherAppWidgetInfo info, LauncherAppWidgetHost host) {
|
||||
public void deleteWidgetInfo(final LauncherAppWidgetInfo info, LauncherAppWidgetHost host,
|
||||
@Nullable final String reason) {
|
||||
notifyDelete(Collections.singleton(info));
|
||||
if (host != null && !info.isCustomWidget() && info.isWidgetIdAllocated()) {
|
||||
// Deleting an app widget ID is a void call but writes to disk before returning
|
||||
// to the caller...
|
||||
enqueueDeleteRunnable(() -> host.deleteAppWidgetId(info.appWidgetId));
|
||||
}
|
||||
deleteItemFromDatabase(info);
|
||||
deleteItemFromDatabase(info, reason);
|
||||
}
|
||||
|
||||
private void notifyDelete(Collection<? extends ItemInfo> items) {
|
||||
|
||||
Reference in New Issue
Block a user