mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
Merge "Adding support to delete unrestored icons and widgets" into ub-now-porkchop
This commit is contained in:
@@ -45,6 +45,11 @@ public class LauncherAppWidgetInfo extends ItemInfo {
|
||||
*/
|
||||
public static final int FLAG_UI_NOT_READY = 4;
|
||||
|
||||
/**
|
||||
* Indicates that the widget restore has started.
|
||||
*/
|
||||
public static final int FLAG_RESTORE_STARTED = 8;
|
||||
|
||||
/**
|
||||
* Indicates that the widget hasn't been instantiated yet.
|
||||
*/
|
||||
|
||||
@@ -86,6 +86,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||
implements LauncherAppsCompat.OnAppsChangedCallbackCompat {
|
||||
static final boolean DEBUG_LOADERS = false;
|
||||
private static final boolean DEBUG_RECEIVER = false;
|
||||
private static final boolean REMOVE_UNRESTORED_ICONS = true;
|
||||
|
||||
static final String TAG = "Launcher.Model";
|
||||
|
||||
@@ -1885,7 +1886,8 @@ public class LauncherModel extends BroadcastReceiver
|
||||
|
||||
synchronized (sBgLock) {
|
||||
clearSBgDataStructures();
|
||||
PackageInstallerCompat.getInstance(mContext).updateActiveSessionCache();
|
||||
final HashSet<String> installingPkgs = PackageInstallerCompat
|
||||
.getInstance(mContext).updateAndGetActiveSessionCache();
|
||||
|
||||
final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
|
||||
final ArrayList<Long> restoredRows = new ArrayList<Long>();
|
||||
@@ -2014,6 +2016,25 @@ public class LauncherModel extends BroadcastReceiver
|
||||
// installed later.
|
||||
Launcher.addDumpLog(TAG,
|
||||
"package not yet restored: " + cn, true);
|
||||
|
||||
if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) {
|
||||
// Restore has started once.
|
||||
} else if (installingPkgs.contains(cn.getPackageName())) {
|
||||
// App restore has started. Update the flag
|
||||
promiseType |= ShortcutInfo.FLAG_RESTORE_STARTED;
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(LauncherSettings.Favorites.RESTORED,
|
||||
promiseType);
|
||||
String where = BaseColumns._ID + "= ?";
|
||||
String[] args = {Long.toString(id)};
|
||||
contentResolver.update(contentUri, values, where, args);
|
||||
|
||||
} else if (REMOVE_UNRESTORED_ICONS) {
|
||||
Launcher.addDumpLog(TAG,
|
||||
"Unrestored package removed: " + cn, true);
|
||||
itemsToRemove.add(id);
|
||||
continue;
|
||||
}
|
||||
} else if (isSdCardReady) {
|
||||
// Do not wait for external media load anymore.
|
||||
// Log the invalid package, and remove it
|
||||
@@ -2221,6 +2242,19 @@ public class LauncherModel extends BroadcastReceiver
|
||||
appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId,
|
||||
component);
|
||||
appWidgetInfo.restoreStatus = restoreStatus;
|
||||
|
||||
if ((restoreStatus & LauncherAppWidgetInfo.FLAG_RESTORE_STARTED) != 0) {
|
||||
// Restore has started once.
|
||||
} else if (installingPkgs.contains(component.getPackageName())) {
|
||||
// App restore has started. Update the flag
|
||||
appWidgetInfo.restoreStatus |=
|
||||
LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
|
||||
} else if (REMOVE_UNRESTORED_ICONS) {
|
||||
Launcher.addDumpLog(TAG,
|
||||
"Unrestored package removed: " + component, true);
|
||||
itemsToRemove.add(id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
appWidgetInfo.id = id;
|
||||
@@ -2249,19 +2283,17 @@ public class LauncherModel extends BroadcastReceiver
|
||||
break;
|
||||
}
|
||||
|
||||
if (isProviderReady) {
|
||||
String providerName = provider.provider.flattenToString();
|
||||
if (!providerName.equals(savedProvider) ||
|
||||
(appWidgetInfo.restoreStatus != restoreStatus)) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER,
|
||||
providerName);
|
||||
values.put(LauncherSettings.Favorites.RESTORED,
|
||||
appWidgetInfo.restoreStatus);
|
||||
String where = BaseColumns._ID + "= ?";
|
||||
String[] args = {Long.toString(id)};
|
||||
contentResolver.update(contentUri, values, where, args);
|
||||
}
|
||||
String providerName = appWidgetInfo.providerName.flattenToString();
|
||||
if (!providerName.equals(savedProvider) ||
|
||||
(appWidgetInfo.restoreStatus != restoreStatus)) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER,
|
||||
providerName);
|
||||
values.put(LauncherSettings.Favorites.RESTORED,
|
||||
appWidgetInfo.restoreStatus);
|
||||
String where = BaseColumns._ID + "= ?";
|
||||
String[] args = {Long.toString(id)};
|
||||
contentResolver.update(contentUri, values, where, args);
|
||||
}
|
||||
sBgItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
|
||||
sBgAppWidgets.add(appWidgetInfo);
|
||||
|
||||
@@ -54,6 +54,11 @@ public class ShortcutInfo extends ItemInfo {
|
||||
*/
|
||||
public static final int FLAG_INSTALL_SESSION_ACTIVE = 4;
|
||||
|
||||
/**
|
||||
* Indicates that the widget restore has started.
|
||||
*/
|
||||
public static final int FLAG_RESTORE_STARTED = 8;
|
||||
|
||||
/**
|
||||
* The intent used to start the application.
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.content.Context;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public abstract class PackageInstallerCompat {
|
||||
|
||||
public static final int STATUS_INSTALLED = 0;
|
||||
@@ -42,7 +44,7 @@ public abstract class PackageInstallerCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void updateActiveSessionCache();
|
||||
public abstract HashSet<String> updateAndGetActiveSessionCache();
|
||||
|
||||
public abstract void onPause();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.json.JSONStringer;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PackageInstallerCompatV16 extends PackageInstallerCompat {
|
||||
|
||||
@@ -76,9 +77,6 @@ public class PackageInstallerCompatV16 extends PackageInstallerCompat {
|
||||
@Override
|
||||
public void onStop() { }
|
||||
|
||||
@Override
|
||||
public void updateActiveSessionCache() { }
|
||||
|
||||
private void replayUpdates() {
|
||||
if (DEBUG) Log.d(TAG, "updates resumed");
|
||||
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
|
||||
@@ -169,4 +167,9 @@ public class PackageInstallerCompatV16 extends PackageInstallerCompat {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashSet<String> updateAndGetActiveSessionCache() {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.android.launcher3.IconCache;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
|
||||
@@ -57,11 +58,16 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateActiveSessionCache() {
|
||||
public HashSet<String> updateAndGetActiveSessionCache() {
|
||||
HashSet<String> activePackages = new HashSet<String>();
|
||||
UserHandleCompat user = UserHandleCompat.myUserHandle();
|
||||
for (SessionInfo info : mInstaller.getAllSessions()) {
|
||||
addSessionInfoToCahce(info, user);
|
||||
if (info.getAppPackageName() != null) {
|
||||
activePackages.add(info.getAppPackageName());
|
||||
}
|
||||
}
|
||||
return activePackages;
|
||||
}
|
||||
|
||||
private void addSessionInfoToCahce(SessionInfo info, UserHandleCompat user) {
|
||||
|
||||
Reference in New Issue
Block a user