feat: Add option to clear home screen in settings (#6125)

Signed-off-by: abhixv <abhi.sharma1@hotmail.com>
This commit is contained in:
Abhishek Sharma authored and Pun Butrach committed 2026-01-10 20:51:01 +07:00
1 parent 9898749619
commit 5f3a03f4fb
1577 files changed
+112559 -80244

No files matched your search

+22 -113
View File
@@ -16,7 +16,6 @@
package com.android.launcher3;
import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;
import static com.android.launcher3.util.FlagDebugUtils.appendFlag;
import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;
import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK;
@@ -32,34 +31,18 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.ActionMode;
import android.view.View;
import android.window.OnBackInvokedDispatcher;
import androidx.activity.ComponentActivity;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleRegistry;
import androidx.savedstate.SavedStateRegistry;
import androidx.savedstate.SavedStateRegistryController;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.LifecycleHelper;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.ViewCache;
import com.android.launcher3.util.WeakCleanupSet;
import com.android.launcher3.util.WindowBounds;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ScrimView;
@@ -72,8 +55,7 @@ import java.util.StringJoiner;
/**
* Launcher BaseActivity
*/
public abstract class BaseActivity extends Activity implements ActivityContext,
DisplayInfoChangeListener {
public abstract class BaseActivity extends ComponentActivity implements ActivityContext {
private static final String TAG = "BaseActivity";
static final boolean DEBUG = false;
@@ -106,15 +88,11 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners =
new ArrayList<>();
private final SavedStateRegistryController mSavedStateRegistryController =
SavedStateRegistryController.create(this);
private final LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this);
private final WeakCleanupSet mCleanupSet = new WeakCleanupSet(this);
protected DeviceProfile mDeviceProfile;
protected SystemUiController mSystemUiController;
private StatsLogManager mStatsLogManager;
public static final int ACTIVITY_STATE_STARTED = 1 << 0;
public static final int ACTIVITY_STATE_RESUMED = 1 << 1;
@@ -134,6 +112,11 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
*/
public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4;
/**
* State flag indicating if the user will be active shortly.
*/
public static final int ACTIVITY_STATE_USER_WILL_BE_ACTIVE = 1 << 5;
/**
* State flag indicating that a state transition is in progress
*/
@@ -151,10 +134,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
public @interface ActivityFlags {
}
// When starting an action mode, setting this tag will cause the action mode to be cancelled
// automatically when user interacts with the launcher.
public static final Object AUTO_CANCEL_ACTION_MODE = new Object();
/** Returns a human-readable string for the specified {@link ActivityFlags}. */
public static String getActivityStateString(@ActivityFlags int flags) {
StringJoiner result = new StringJoiner("|");
@@ -189,14 +168,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
private final RunnableList[] mEventCallbacks =
{new RunnableList(), new RunnableList(), new RunnableList(), new RunnableList()};
private ActionMode mCurrentActionMode;
public BaseActivity() {
mSavedStateRegistryController.performAttach();
registerActivityLifecycleCallbacks(
new LifecycleHelper(this, mSavedStateRegistryController, mLifecycleRegistry));
}
@Override
public ViewCache getViewCache() {
return mViewCache;
@@ -225,7 +196,7 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
public SystemUiController getSystemUiController() {
if (mSystemUiController == null) {
mSystemUiController = new SystemUiController(getWindow().getDecorView());
mSystemUiController = new SystemUiController(getWindow());
}
return mSystemUiController;
}
@@ -243,7 +214,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBackDispatcher();
DisplayController.INSTANCE.get(this).addChangeListener(this);
}
@Override
@@ -291,7 +261,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
protected void onDestroy() {
super.onDestroy();
mEventCallbacks[EVENT_DESTROYED].executeAllAndClear();
DisplayController.INSTANCE.get(this).removeChangeListener(this);
}
@Override
@@ -350,6 +319,7 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
*/
public void setResumed() {
addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE);
removeActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE);
}
public boolean isUserActive() {
@@ -424,6 +394,15 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
mEventCallbacks[event].add(callback);
}
@Override
public Handler getMainThreadHandler() {
try {
return new Handler(Looper.getMainLooper());
} catch (Throwable t) {
return super.getMainThreadHandler();
}
}
/** Removes a previously added callback */
public void removeEventCallback(@ActivityEvent int event, Runnable callback) {
mEventCallbacks[event].remove(callback);
@@ -442,83 +421,13 @@ public abstract class BaseActivity extends Activity implements ActivityContext,
writer.println(prefix + "mForceInvisible: " + mForceInvisible);
}
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
mCurrentActionMode = mode;
}
@Override
public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode);
mCurrentActionMode = null;
}
protected boolean isInAutoCancelActionMode() {
return mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag();
}
@Override
public boolean finishAutoCancelActionMode() {
if (isInAutoCancelActionMode()) {
mCurrentActionMode.finish();
return true;
}
return false;
}
@Override
@NonNull
public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
ActivityOptionsWrapper wrapper = ActivityContext.super.getActivityLaunchOptions(v, item);
addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy);
return wrapper;
}
@Override
public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
ActivityOptionsWrapper wrapper =
ActivityContext.super.makeDefaultActivityOptions(splashScreenStyle);
addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy);
return wrapper;
}
protected WindowBounds getMultiWindowDisplaySize() {
return WindowBounds.fromWindowMetrics(getWindowManager().getCurrentWindowMetrics());
}
@Override
public void onDisplayInfoChanged(Context context, Info info, int flags) {
if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.isVerticalBarLayout()) {
reapplyUi();
}
}
protected void reapplyUi() {}
@NonNull
@Override
public SavedStateRegistry getSavedStateRegistry() {
return mSavedStateRegistryController.getSavedStateRegistry();
}
@NonNull
@Override
public Lifecycle getLifecycle() {
return mLifecycleRegistry;
}
@Override
public WeakCleanupSet getOwnerCleanupSet() {
return mCleanupSet;
}
public static <T extends BaseActivity> T fromContext(Context context) {
if (context instanceof BaseActivity) {
return (T) context;
} else if (context instanceof ContextWrapper cw) {
return fromContext(cw.getBaseContext());
} else if (context instanceof ActivityContextDelegate) {
return (T) ((ActivityContextDelegate) context).mDelegate;
} else if (context instanceof ContextWrapper) {
return fromContext(((ContextWrapper) context).getBaseContext());
} else {
throw new IllegalArgumentException("Cannot find BaseActivity in parent tree");
}