Fix launcher leaks
Follow up of: ag/12558751 Bug: 168121204 Change-Id: I381284a5e1cd9568ed14ec7a357ff150e35c18c6
This commit is contained in:
@@ -94,9 +94,13 @@ import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
|
||||
import com.android.launcher3.DropTarget.DragObject;
|
||||
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
|
||||
@@ -206,7 +210,8 @@ import java.util.stream.Stream;
|
||||
* Default launcher application.
|
||||
*/
|
||||
public class Launcher extends StatefulActivity<LauncherState> implements LauncherExterns,
|
||||
Callbacks, InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin> {
|
||||
Callbacks, InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin>,
|
||||
LifecycleOwner {
|
||||
public static final String TAG = "Launcher";
|
||||
|
||||
public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>();
|
||||
@@ -267,6 +272,8 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
private LauncherAppTransitionManager mAppTransitionManager;
|
||||
private Configuration mOldConfig;
|
||||
|
||||
private LifecycleRegistry mLifecycleRegistry;
|
||||
|
||||
@Thunk
|
||||
Workspace mWorkspace;
|
||||
@Thunk
|
||||
@@ -471,6 +478,15 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
if (Utilities.ATLEAST_R) {
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
|
||||
}
|
||||
|
||||
mLifecycleRegistry = new LifecycleRegistry(this);
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
return mLifecycleRegistry;
|
||||
}
|
||||
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
@@ -886,6 +902,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
||||
super.onStop();
|
||||
if (mDeferOverlayCallbacks) {
|
||||
checkIfOverlayStillDeferred();
|
||||
@@ -909,6 +926,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
|
||||
mAppWidgetHost.setListenIfResumed(true);
|
||||
TraceHelper.INSTANCE.endSection(traceToken);
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1068,6 +1086,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
}
|
||||
|
||||
TraceHelper.INSTANCE.endSection(traceToken);
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.RESUMED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1075,6 +1094,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
// Ensure that items added to Launcher are queued until Launcher returns
|
||||
ItemInstallQueue.INSTANCE.get(this).pauseModelPush(FLAG_ACTIVITY_PAUSED);
|
||||
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
||||
super.onPause();
|
||||
mDragController.cancelDrag();
|
||||
mLastTouchUpTime = -1;
|
||||
@@ -1557,6 +1577,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
mOverlayManager.onActivityDestroyed(this);
|
||||
mAppTransitionManager.unregisterRemoteAnimations();
|
||||
mUserChangedCallbackCloseable.close();
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.DESTROYED);
|
||||
}
|
||||
|
||||
public LauncherAccessibilityDelegate getAccessibilityDelegate() {
|
||||
|
||||
@@ -37,9 +37,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -49,6 +46,7 @@ import androidx.slice.widget.SliceView;
|
||||
|
||||
import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.search.AllAppsSearchBarController.PayloadResultHandler;
|
||||
import com.android.launcher3.allapps.search.SearchSectionInfo;
|
||||
@@ -67,8 +65,7 @@ import java.util.function.IntConsumer;
|
||||
* The grid view adapter of all the apps.
|
||||
*/
|
||||
public class AllAppsGridAdapter extends
|
||||
RecyclerView.Adapter<AllAppsGridAdapter.ViewHolder> implements
|
||||
LifecycleOwner {
|
||||
RecyclerView.Adapter<AllAppsGridAdapter.ViewHolder> {
|
||||
|
||||
public static final String TAG = "AppsGridAdapter";
|
||||
|
||||
@@ -103,8 +100,6 @@ public class AllAppsGridAdapter extends
|
||||
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
|
||||
|
||||
private final LifecycleRegistry mLifecycleRegistry;
|
||||
|
||||
/**
|
||||
* ViewHolder for each icon.
|
||||
*/
|
||||
@@ -353,12 +348,6 @@ public class AllAppsGridAdapter extends
|
||||
mOnIconClickListener = launcher.getItemOnClickListener();
|
||||
|
||||
setAppsPerRow(mLauncher.getDeviceProfile().inv.numAllAppsColumns);
|
||||
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
mLifecycleRegistry = new LifecycleRegistry(this);
|
||||
mLifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
||||
} else {
|
||||
mLifecycleRegistry = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppsPerRow(int appsPerRow) {
|
||||
@@ -525,7 +514,7 @@ public class AllAppsGridAdapter extends
|
||||
});
|
||||
try {
|
||||
LiveData<Slice> liveData = SliceLiveData.fromUri(mLauncher, item.getPayload());
|
||||
liveData.observe(this::getLifecycle, sliceView);
|
||||
liveData.observe((Launcher) mLauncher, sliceView);
|
||||
sliceView.setTag(liveData);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
@@ -559,7 +548,7 @@ public class AllAppsGridAdapter extends
|
||||
sliceView.setOnSliceActionListener(null);
|
||||
if (sliceView.getTag() instanceof LiveData) {
|
||||
LiveData sliceLiveData = (LiveData) sliceView.getTag();
|
||||
sliceLiveData.removeObservers(this::getLifecycle);
|
||||
sliceLiveData.removeObservers((Launcher) mLauncher);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -581,10 +570,4 @@ public class AllAppsGridAdapter extends
|
||||
AdapterItem item = mApps.getAdapterItems().get(position);
|
||||
return item.viewType;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
return mLifecycleRegistry;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user