Commit bc29bb5d authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Handle onRemove event

parent 0dd4980a
Pipeline #140615 passed with stage
in 1 minute and 56 seconds
...@@ -165,7 +165,6 @@ ...@@ -165,7 +165,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
--> -->
<receiver android:name="core.broadcast.PackageAddedRemovedHandler" />
<meta-data <meta-data
android:name="android.nfc.disable_beam_default" android:name="android.nfc.disable_beam_default"
......
...@@ -37,6 +37,7 @@ import android.view.animation.AnimationUtils; ...@@ -37,6 +37,7 @@ import android.view.animation.AnimationUtils;
import android.view.animation.OvershootInterpolator; import android.view.animation.OvershootInterpolator;
import android.widget.GridLayout; import android.widget.GridLayout;
import android.widget.Toast; import android.widget.Toast;
import foundation.e.blisslauncher.BuildConfig; import foundation.e.blisslauncher.BuildConfig;
import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Utilities; import foundation.e.blisslauncher.core.Utilities;
...@@ -61,6 +62,7 @@ import foundation.e.blisslauncher.features.shortcuts.ShortcutKey; ...@@ -61,6 +62,7 @@ import foundation.e.blisslauncher.features.shortcuts.ShortcutKey;
import foundation.e.blisslauncher.features.test.Alarm; import foundation.e.blisslauncher.features.test.Alarm;
import foundation.e.blisslauncher.features.test.CellLayout; import foundation.e.blisslauncher.features.test.CellLayout;
import foundation.e.blisslauncher.features.test.IconTextView; import foundation.e.blisslauncher.features.test.IconTextView;
import foundation.e.blisslauncher.features.test.LauncherItemMatcher;
import foundation.e.blisslauncher.features.test.LauncherState; import foundation.e.blisslauncher.features.test.LauncherState;
import foundation.e.blisslauncher.features.test.LauncherStateManager; import foundation.e.blisslauncher.features.test.LauncherStateManager;
import foundation.e.blisslauncher.features.test.OnAlarmListener; import foundation.e.blisslauncher.features.test.OnAlarmListener;
...@@ -78,6 +80,7 @@ import foundation.e.blisslauncher.features.test.dragndrop.DropTarget; ...@@ -78,6 +80,7 @@ import foundation.e.blisslauncher.features.test.dragndrop.DropTarget;
import foundation.e.blisslauncher.features.test.dragndrop.SpringLoadedDragController; import foundation.e.blisslauncher.features.test.dragndrop.SpringLoadedDragController;
import foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider; import foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider;
import foundation.e.blisslauncher.features.test.uninstall.UninstallHelper; import foundation.e.blisslauncher.features.test.uninstall.UninstallHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
...@@ -86,6 +89,7 @@ import java.util.List; ...@@ -86,6 +89,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class LauncherPagedView extends PagedView<PageIndicatorDots> implements View.OnTouchListener, public class LauncherPagedView extends PagedView<PageIndicatorDots> implements View.OnTouchListener,
...@@ -426,7 +430,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -426,7 +430,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
throw new RuntimeException("Unexpected info type"); throw new RuntimeException("Unexpected info type");
} }
if(item.itemType == Constants.ITEM_TYPE_SHORTCUT) { if (item.itemType == Constants.ITEM_TYPE_SHORTCUT) {
// Increment the count for the given shortcut // Increment the count for the given shortcut
ShortcutKey pinnedShortcut = ShortcutKey.fromItem((ShortcutItem) item); ShortcutKey pinnedShortcut = ShortcutKey.fromItem((ShortcutItem) item);
MutableInt count = pinnedShortcutCounts.get(pinnedShortcut); MutableInt count = pinnedShortcutCounts.get(pinnedShortcut);
...@@ -441,7 +445,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -441,7 +445,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
if (count.value == 1) { if (count.value == 1) {
DeepShortcutManager.getInstance(getContext()).pinShortcut(pinnedShortcut); DeepShortcutManager.getInstance(getContext()).pinShortcut(pinnedShortcut);
} }
} }
// Save the WorkspaceItemInfo for binding in the workspace // Save the WorkspaceItemInfo for binding in the workspace
addedItemsFinal.add(itemInfo); addedItemsFinal.add(itemInfo);
...@@ -2736,6 +2739,55 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -2736,6 +2739,55 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
computeScrollHelper(false); computeScrollHelper(false);
} }
/**
* Removes items that match the {@param matcher}. When applications are removed
* as a part of an update, this is called to ensure that other widgets and application
* shortcuts are not removed.
*/
public void removeItemsByMatcher(@NotNull LauncherItemMatcher matcher) {
for (final CellLayout layout : getWorkspaceAndHotseatCellLayouts()) {
HashMap<String, View> idToViewMap = new HashMap<>();
ArrayList<LauncherItem> items = new ArrayList<>();
for (int j = 0; j < layout.getChildCount(); j++) {
final View view = layout.getChildAt(j);
if (view.getTag() instanceof LauncherItem) {
LauncherItem item = (LauncherItem) view.getTag();
items.add(item);
idToViewMap.put(item.id, view);
}
}
for (LauncherItem itemToRemove : matcher.filterItemInfos(items)) {
View child = idToViewMap.get(itemToRemove.id);
if (child != null) {
// Note: We can not remove the view directly from CellLayoutChildren as this
// does not re-mark the spaces as unoccupied.
layout.removeViewInLayout(child);
if (child instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) child);
}
} else if (itemToRemove.container >= 0) {
// The item may belong to a folder.
View parent = idToViewMap.get(String.valueOf(itemToRemove.container));
if (parent != null) {
/*
FolderItem folderInfo = (FolderItem) parent.getTag();
folderInfo.prepareAutoUpdate();
folderInfo.remove((WorkspaceItemInfo) itemToRemove, false);
*/
// TODO: Properly handle item removal from folder.
}
}
}
}
// Strip all the empty screens
stripEmptyScreens();
updateDatabase(getWorkspaceAndHotseatCellLayouts());
}
public interface ItemOperator { public interface ItemOperator {
/** /**
* Process the next itemInfo, possibly with side-effect on the next item. * Process the next itemInfo, possibly with side-effect on the next item.
......
...@@ -119,7 +119,7 @@ public class AppProvider { ...@@ -119,7 +119,7 @@ public class AppProvider {
Context.LAUNCHER_APPS_SERVICE); Context.LAUNCHER_APPS_SERVICE);
assert launcher != null; assert launcher != null;
launcher.registerCallback(new LauncherApps.Callback() { /*launcher.registerCallback(new LauncherApps.Callback() {
@Override @Override
public void onPackageRemoved(String packageName, android.os.UserHandle user) { public void onPackageRemoved(String packageName, android.os.UserHandle user) {
if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase( if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase(
...@@ -194,7 +194,7 @@ public class AppProvider { ...@@ -194,7 +194,7 @@ public class AppProvider {
super.onPackagesUnsuspended(packageNames, user); super.onPackagesUnsuspended(packageNames, user);
Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + packageNames + "], user = [" + user + "]"); Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + packageNames + "], user = [" + user + "]");
} }
}); });*/
mAppsRepository = AppsRepository.getAppsRepository(); mAppsRepository = AppsRepository.getAppsRepository();
} }
......
...@@ -109,7 +109,6 @@ public class LauncherAppState { ...@@ -109,7 +109,6 @@ public class LauncherAppState {
mCallbacks.put(mModel, wrappedCallback); mCallbacks.put(mModel, wrappedCallback);
} }
launcherApps.registerCallback(wrappedCallback); launcherApps.registerCallback(wrappedCallback);
mModel.registerCallbacks(launcherApps);
// Register intent receivers // Register intent receivers
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_LOCALE_CHANGED); filter.addAction(Intent.ACTION_LOCALE_CHANGED);
......
...@@ -5,6 +5,7 @@ import android.os.UserHandle; ...@@ -5,6 +5,7 @@ import android.os.UserHandle;
import java.util.HashSet; import java.util.HashSet;
import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.FolderItem; import foundation.e.blisslauncher.core.database.model.FolderItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.database.model.ShortcutItem; import foundation.e.blisslauncher.core.database.model.ShortcutItem;
...@@ -22,7 +23,13 @@ public abstract class LauncherItemMatcher { ...@@ -22,7 +23,13 @@ public abstract class LauncherItemMatcher {
public final HashSet<LauncherItem> filterItemInfos(Iterable<LauncherItem> infos) { public final HashSet<LauncherItem> filterItemInfos(Iterable<LauncherItem> infos) {
HashSet<LauncherItem> filtered = new HashSet<>(); HashSet<LauncherItem> filtered = new HashSet<>();
for (LauncherItem i : infos) { for (LauncherItem i : infos) {
if (i instanceof ShortcutItem) { if (i instanceof ApplicationItem) {
ApplicationItem info = (ApplicationItem) i;
ComponentName cn = info.getTargetComponent();
if (cn != null && matches(info, cn)) {
filtered.add(info);
}
} else if (i instanceof ShortcutItem) {
ShortcutItem info = (ShortcutItem) i; ShortcutItem info = (ShortcutItem) i;
ComponentName cn = info.getTargetComponent(); ComponentName cn = info.getTargetComponent();
if (cn != null && matches(info, cn)) { if (cn != null && matches(info, cn)) {
......
...@@ -19,31 +19,25 @@ package foundation.e.blisslauncher.features.test; ...@@ -19,31 +19,25 @@ package foundation.e.blisslauncher.features.test;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Looper; import android.os.Looper;
import android.os.Process; import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.telecom.Call;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.NonNull;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.executors.MainThreadExecutor; import foundation.e.blisslauncher.core.executors.MainThreadExecutor;
import foundation.e.blisslauncher.core.utils.Constants;
import foundation.e.blisslauncher.core.utils.Preconditions; import foundation.e.blisslauncher.core.utils.Preconditions;
import foundation.e.blisslauncher.features.shortcuts.DeepShortcutManager; import foundation.e.blisslauncher.features.shortcuts.InstallShortcutReceiver;
public class LauncherModel extends BroadcastReceiver implements public class LauncherModel extends BroadcastReceiver implements
OnAppsChangedCallback { OnAppsChangedCallback {
...@@ -53,17 +47,19 @@ public class LauncherModel extends BroadcastReceiver implements ...@@ -53,17 +47,19 @@ public class LauncherModel extends BroadcastReceiver implements
static final String TAG = "Launcher.Model"; static final String TAG = "Launcher.Model";
private final MainThreadExecutor mUiExecutor = new MainThreadExecutor(); private final MainThreadExecutor mUiExecutor = new MainThreadExecutor();
final LauncherAppState mApp; final LauncherAppState mApp;
final Object mLock = new Object(); final Object mLock = new Object();
WeakReference<Callbacks> mCallbacks; WeakReference<Callbacks> mCallbacks;
static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader"); static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
private static final Looper mWorkerLooper; private static final Looper mWorkerLooper;
static { static {
sWorkerThread.start(); sWorkerThread.start();
mWorkerLooper = sWorkerThread.getLooper(); mWorkerLooper = sWorkerThread.getLooper();
} }
static final Handler sWorker = new Handler(mWorkerLooper); static final Handler sWorker = new Handler(mWorkerLooper);
@Override @Override
...@@ -75,6 +71,22 @@ public class LauncherModel extends BroadcastReceiver implements ...@@ -75,6 +71,22 @@ public class LauncherModel extends BroadcastReceiver implements
public void onPackagesRemoved(UserHandle user, String... packages) { public void onPackagesRemoved(UserHandle user, String... packages) {
final HashSet<String> removedPackages = new HashSet<>(); final HashSet<String> removedPackages = new HashSet<>();
Collections.addAll(removedPackages, packages); Collections.addAll(removedPackages, packages);
if (!removedPackages.isEmpty()) {
LauncherItemMatcher removeMatch = LauncherItemMatcher.ofPackages(removedPackages, user);
deleteAndBindComponentsRemoved(removeMatch);
// Remove any queued items from the install queue
if (sWorkerThread.getThreadId() == Process.myTid()) {
} else {
// If we are not on the worker thread, then post to the worker handler
sWorker.post(() -> InstallShortcutReceiver
.removeFromInstallQueue(mApp.getContext(), removedPackages, user));
}
}
}
private void deleteAndBindComponentsRemoved(LauncherItemMatcher removeMatch) {
mCallbacks.get().bindWorkspaceComponentsRemoved(removeMatch);
} }
@Override @Override
...@@ -130,6 +142,8 @@ public class LauncherModel extends BroadcastReceiver implements ...@@ -130,6 +142,8 @@ public class LauncherModel extends BroadcastReceiver implements
public interface Callbacks { public interface Callbacks {
void bindAppsAdded(List<LauncherItem> items); void bindAppsAdded(List<LauncherItem> items);
void bindWorkspaceComponentsRemoved(LauncherItemMatcher matcher);
} }
LauncherModel(LauncherAppState app) { LauncherModel(LauncherAppState app) {
...@@ -158,13 +172,12 @@ public class LauncherModel extends BroadcastReceiver implements ...@@ -158,13 +172,12 @@ public class LauncherModel extends BroadcastReceiver implements
Callbacks callbacks = getCallback(); Callbacks callbacks = getCallback();
if (callbacks != null) { if (callbacks != null) {
//callbacks.preAddApps(); //callbacks.preAddApps();
List<LauncherItem> items = new ArrayList<>(); List<LauncherItem> items = new ArrayList<>();
for (Pair<LauncherItem, Object> entry : itemList) { for (Pair<LauncherItem, Object> entry : itemList) {
items.add(entry.first); items.add(entry.first);
} }
mUiExecutor.execute(() -> callbacks.bindAppsAdded(items)); mUiExecutor.execute(() -> callbacks.bindAppsAdded(items));
} }
} }
public Callbacks getCallback() { public Callbacks getCallback() {
......
...@@ -82,6 +82,7 @@ import foundation.e.blisslauncher.core.utils.AppUtils ...@@ -82,6 +82,7 @@ import foundation.e.blisslauncher.core.utils.AppUtils
import foundation.e.blisslauncher.core.utils.Constants import foundation.e.blisslauncher.core.utils.Constants
import foundation.e.blisslauncher.core.utils.IntSet import foundation.e.blisslauncher.core.utils.IntSet
import foundation.e.blisslauncher.core.utils.IntegerArray import foundation.e.blisslauncher.core.utils.IntegerArray
import foundation.e.blisslauncher.core.utils.ItemInfoMatcher
import foundation.e.blisslauncher.core.utils.ListUtil import foundation.e.blisslauncher.core.utils.ListUtil
import foundation.e.blisslauncher.core.utils.PackageUserKey import foundation.e.blisslauncher.core.utils.PackageUserKey
import foundation.e.blisslauncher.core.utils.UserHandle import foundation.e.blisslauncher.core.utils.UserHandle
...@@ -1100,7 +1101,6 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1100,7 +1101,6 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
} }
private fun showApps(launcherItems: List<LauncherItem>) { private fun showApps(launcherItems: List<LauncherItem>) {
Log.d(TAG, "showApps() called with: launcherItems = $launcherItems")
hotseat.resetLayout(false) hotseat.resetLayout(false)
val populatedItems = populateItemPositions(launcherItems) val populatedItems = populateItemPositions(launcherItems)
val orderedScreenIds = IntegerArray() val orderedScreenIds = IntegerArray()
...@@ -1778,7 +1778,18 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1778,7 +1778,18 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
override fun bindAppsAdded(items: MutableList<LauncherItem>) { override fun bindAppsAdded(items: MutableList<LauncherItem>) {
if (items.isEmpty()) return if (items.isEmpty()) return
workspace.bindItemsAdded(items)
}
workspace?.bindItemsAdded(items) /**
* A package was uninstalled/updated. We take both the super set of packageNames
* in addition to specific applications to remove, the reason being that
* this can be called when a package is updated as well. In that scenario,
* we only remove specific components from the workspace and hotseat, where as
* package-removal should clear all items by package name.
*/
override fun bindWorkspaceComponentsRemoved(matcher: LauncherItemMatcher) {
workspace.removeItemsByMatcher(matcher)
dragController.onAppsRemoved(matcher)
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment