Merge "Moved TISBinder lifecycle handling to TISBinderHelper" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9c9764c28b
@@ -29,6 +29,7 @@ import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentCallbacks;
|
||||
import android.content.Context;
|
||||
@@ -56,6 +57,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
|
||||
import com.android.launcher3.statemanager.StatefulActivity;
|
||||
import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider;
|
||||
import com.android.launcher3.uioverrides.QuickstepLauncher;
|
||||
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
|
||||
import com.android.launcher3.util.DisplayController;
|
||||
import com.android.launcher3.util.NavigationMode;
|
||||
import com.android.launcher3.util.SettingsCache;
|
||||
@@ -144,6 +146,25 @@ public class TaskbarManager {
|
||||
}
|
||||
};
|
||||
|
||||
private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks =
|
||||
new ActivityLifecycleCallbacksAdapter() {
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
if (mActivity != activity) return;
|
||||
if (mActivity != null) {
|
||||
mActivity.removeOnDeviceProfileChangeListener(
|
||||
mDebugActivityDeviceProfileChanged);
|
||||
mActivity.unregisterActivityLifecycleCallbacks(this);
|
||||
}
|
||||
mActivity = null;
|
||||
debugWhyTaskbarNotDestroyed("clearActivity");
|
||||
if (mTaskbarActivityContext != null) {
|
||||
mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
|
||||
}
|
||||
mUnfoldProgressProvider.setSourceProvider(null);
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
public TaskbarManager(TouchInteractionService service) {
|
||||
mDisplayController = DisplayController.INSTANCE.get(service);
|
||||
@@ -306,10 +327,12 @@ public class TaskbarManager {
|
||||
}
|
||||
if (mActivity != null) {
|
||||
mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
|
||||
mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
|
||||
}
|
||||
mActivity = activity;
|
||||
debugWhyTaskbarNotDestroyed("Set mActivity=" + mActivity);
|
||||
mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
|
||||
mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
|
||||
UnfoldTransitionProgressProvider unfoldTransitionProgressProvider =
|
||||
getUnfoldTransitionProgressProviderForActivity(activity);
|
||||
mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider);
|
||||
@@ -348,21 +371,6 @@ public class TaskbarManager {
|
||||
return TaskbarUIController.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a previously set {@link StatefulActivity}
|
||||
*/
|
||||
public void clearActivity(@NonNull StatefulActivity activity) {
|
||||
if (mActivity == activity) {
|
||||
mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
|
||||
mActivity = null;
|
||||
debugWhyTaskbarNotDestroyed("clearActivity");
|
||||
if (mTaskbarActivityContext != null) {
|
||||
mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
|
||||
}
|
||||
mUnfoldProgressProvider.setSourceProvider(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called multiple times (ex. initial init, then when user unlocks) in which case
|
||||
* we fully want to destroy an existing taskbar and create a new one.
|
||||
|
||||
@@ -210,8 +210,6 @@ public class QuickstepLauncher extends Launcher {
|
||||
private QuickstepTransitionManager mAppTransitionManager;
|
||||
private OverviewActionsView mActionsView;
|
||||
private TISBindHelper mTISBindHelper;
|
||||
private @Nullable TaskbarManager mTaskbarManager;
|
||||
private @Nullable OverviewCommandHelper mOverviewCommandHelper;
|
||||
private @Nullable LauncherTaskbarUIController mTaskbarUIController;
|
||||
// Will be updated when dragging from taskbar.
|
||||
private @Nullable DragOptions mNextWorkspaceDragOptions = null;
|
||||
@@ -479,9 +477,6 @@ public class QuickstepLauncher extends Launcher {
|
||||
}
|
||||
|
||||
mTISBindHelper.onDestroy();
|
||||
if (mTaskbarManager != null) {
|
||||
mTaskbarManager.clearActivity(this);
|
||||
}
|
||||
|
||||
if (mLauncherUnfoldAnimationController != null) {
|
||||
mLauncherUnfoldAnimationController.onDestroy();
|
||||
@@ -690,9 +685,9 @@ public class QuickstepLauncher extends Launcher {
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
if (mOverviewCommandHelper != null) {
|
||||
mOverviewCommandHelper.clearPendingCommands();
|
||||
OverviewCommandHelper overviewCommandHelper = mTISBindHelper.getOverviewCommandHelper();
|
||||
if (overviewCommandHelper != null) {
|
||||
overviewCommandHelper.clearPendingCommands();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -815,8 +810,9 @@ public class QuickstepLauncher extends Launcher {
|
||||
}
|
||||
|
||||
private void onTaskbarInAppDisplayProgressUpdate(float progress, int flag) {
|
||||
if (mTaskbarManager == null
|
||||
|| mTaskbarManager.getCurrentActivityContext() == null
|
||||
TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
|
||||
if (taskbarManager == null
|
||||
|| taskbarManager.getCurrentActivityContext() == null
|
||||
|| mTaskbarUIController == null) {
|
||||
return;
|
||||
}
|
||||
@@ -888,11 +884,10 @@ public class QuickstepLauncher extends Launcher {
|
||||
}
|
||||
|
||||
private void onTISConnected(TISBinder binder) {
|
||||
mTaskbarManager = binder.getTaskbarManager();
|
||||
if (mTaskbarManager != null) {
|
||||
mTaskbarManager.setActivity(this);
|
||||
TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
|
||||
if (taskbarManager != null) {
|
||||
taskbarManager.setActivity(this);
|
||||
}
|
||||
mOverviewCommandHelper = binder.getOverviewCommandHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1276,8 +1271,9 @@ public class QuickstepLauncher extends Launcher {
|
||||
Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged",
|
||||
getDeviceProfile().toSmallString());
|
||||
SystemUiProxy.INSTANCE.get(this).setLauncherAppIconSize(mDeviceProfile.iconSizePx);
|
||||
if (mTaskbarManager != null) {
|
||||
mTaskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged");
|
||||
TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
|
||||
if (taskbarManager != null) {
|
||||
taskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
|
||||
private FallbackRecentsView mFallbackRecentsView;
|
||||
private OverviewActionsView mActionsView;
|
||||
private TISBindHelper mTISBindHelper;
|
||||
private @Nullable TaskbarManager mTaskbarManager;
|
||||
private @Nullable FallbackTaskbarUIController mTaskbarUIController;
|
||||
|
||||
private StateManager<RecentsState> mStateManager;
|
||||
@@ -142,9 +141,9 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
|
||||
}
|
||||
|
||||
private void onTISConnected(TouchInteractionService.TISBinder binder) {
|
||||
mTaskbarManager = binder.getTaskbarManager();
|
||||
if (mTaskbarManager != null) {
|
||||
mTaskbarManager.setActivity(this);
|
||||
TaskbarManager taskbarManager = binder.getTaskbarManager();
|
||||
if (taskbarManager != null) {
|
||||
taskbarManager.setActivity(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,9 +384,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
|
||||
mActivityLaunchAnimationRunner = null;
|
||||
|
||||
mTISBindHelper.onDestroy();
|
||||
if (mTaskbarManager != null) {
|
||||
mTaskbarManager.clearActivity(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -100,8 +100,6 @@ public class AllSetActivity extends Activity {
|
||||
private final Rect mTempExclusionBounds = new Rect();
|
||||
|
||||
private TISBindHelper mTISBindHelper;
|
||||
private TISBinder mBinder;
|
||||
@Nullable private TaskbarManager mTaskbarManager = null;
|
||||
|
||||
private final AnimatedFloat mSwipeProgress = new AnimatedFloat(this::onSwipeProgressUpdate);
|
||||
private BgDrawable mBackground;
|
||||
@@ -265,27 +263,27 @@ public class AllSetActivity extends Activity {
|
||||
}
|
||||
|
||||
private void setSetupUIVisible(boolean visible) {
|
||||
if (mBinder == null || mTaskbarManager == null) return;
|
||||
mTaskbarManager.setSetupUIVisible(visible);
|
||||
TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
|
||||
if (taskbarManager == null) return;
|
||||
taskbarManager.setSetupUIVisible(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
maybeResumeOrPauseBackgroundAnimation();
|
||||
if (mBinder != null) {
|
||||
TISBinder binder = mTISBindHelper.getBinder();
|
||||
if (binder != null) {
|
||||
setSetupUIVisible(true);
|
||||
mBinder.setSwipeUpProxy(this::createSwipeUpProxy);
|
||||
binder.setSwipeUpProxy(this::createSwipeUpProxy);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTISConnected(TISBinder binder) {
|
||||
mBinder = binder;
|
||||
mTaskbarManager = mBinder.getTaskbarManager();
|
||||
setSetupUIVisible(isResumed());
|
||||
mBinder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
|
||||
mBinder.setOverviewTargetChangeListener(mBinder::preloadOverviewForSUWAllSet);
|
||||
mBinder.preloadOverviewForSUWAllSet();
|
||||
binder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
|
||||
binder.setOverviewTargetChangeListener(binder::preloadOverviewForSUWAllSet);
|
||||
binder.preloadOverviewForSUWAllSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,10 +298,11 @@ public class AllSetActivity extends Activity {
|
||||
}
|
||||
|
||||
private void clearBinderOverride() {
|
||||
if (mBinder != null) {
|
||||
TISBinder binder = mTISBindHelper.getBinder();
|
||||
if (binder != null) {
|
||||
setSetupUIVisible(false);
|
||||
mBinder.setSwipeUpProxy(null);
|
||||
mBinder.setOverviewTargetChangeListener(null);
|
||||
binder.setSwipeUpProxy(null);
|
||||
binder.setOverviewTargetChangeListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,8 +359,9 @@ public class AllSetActivity extends Activity {
|
||||
mContentView.setAlpha(alpha);
|
||||
mContentView.setTranslationY((alpha - 1) * mSwipeUpShift);
|
||||
|
||||
if (mLauncherStartAnim == null && mTaskbarManager != null) {
|
||||
mLauncherStartAnim = mTaskbarManager.createLauncherStartFromSuwAnim(MAX_SWIPE_DURATION);
|
||||
TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
|
||||
if (mLauncherStartAnim == null && taskbarManager != null) {
|
||||
mLauncherStartAnim = taskbarManager.createLauncherStartFromSuwAnim(MAX_SWIPE_DURATION);
|
||||
}
|
||||
if (mLauncherStartAnim != null) {
|
||||
mLauncherStartAnim.setPlayFraction(Utilities.mapBoundToRange(
|
||||
|
||||
@@ -58,7 +58,6 @@ public class GestureSandboxActivity extends FragmentActivity {
|
||||
private StatsLogManager mStatsLogManager;
|
||||
|
||||
private TISBindHelper mTISBindHelper;
|
||||
private TISBinder mBinder;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -271,7 +270,6 @@ public class GestureSandboxActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void onTISConnected(TISBinder binder) {
|
||||
mBinder = binder;
|
||||
updateServiceState(isResumed());
|
||||
}
|
||||
|
||||
@@ -282,8 +280,9 @@ public class GestureSandboxActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void updateServiceState(boolean isEnabled) {
|
||||
if (mBinder != null) {
|
||||
mBinder.setGestureBlockedTaskId(isEnabled ? getTaskId() : -1);
|
||||
TISBinder binder = mTISBindHelper.getBinder();
|
||||
if (binder != null) {
|
||||
binder.setGestureBlockedTaskId(isEnabled ? getTaskId() : -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.taskbar.TaskbarManager;
|
||||
import com.android.quickstep.OverviewCommandHelper;
|
||||
import com.android.quickstep.TouchInteractionService;
|
||||
import com.android.quickstep.TouchInteractionService.TISBinder;
|
||||
|
||||
@@ -50,6 +54,7 @@ public class TISBindHelper implements ServiceConnection {
|
||||
private short mConnectionAttempts;
|
||||
private boolean mTisServiceBound;
|
||||
private boolean mIsConnected;
|
||||
@Nullable private TISBinder mBinder;
|
||||
|
||||
public TISBindHelper(Context context, Consumer<TISBinder> connectionCallback) {
|
||||
mContext = context;
|
||||
@@ -70,7 +75,8 @@ public class TISBindHelper implements ServiceConnection {
|
||||
|
||||
Log.d(TAG, "TIS service connected");
|
||||
mIsConnected = true;
|
||||
mConnectionCallback.accept((TISBinder) iBinder);
|
||||
mBinder = (TISBinder) iBinder;
|
||||
mConnectionCallback.accept(mBinder);
|
||||
// Flush the pending callbacks
|
||||
for (Runnable r : mPendingConnectedCallbacks) {
|
||||
r.run();
|
||||
@@ -80,7 +86,11 @@ public class TISBindHelper implements ServiceConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) { }
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
Log.d(TAG, "TIS service disconnected");
|
||||
mBinder = null;
|
||||
mIsConnected = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindingDied(ComponentName name) {
|
||||
@@ -88,6 +98,21 @@ public class TISBindHelper implements ServiceConnection {
|
||||
internalBindToTIS();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TISBinder getBinder() {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TaskbarManager getTaskbarManager() {
|
||||
return mBinder == null ? null : mBinder.getTaskbarManager();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public OverviewCommandHelper getOverviewCommandHelper() {
|
||||
return mBinder == null ? null : mBinder.getOverviewCommandHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given {@param r} runnable when the service is connected.
|
||||
*/
|
||||
@@ -139,6 +164,7 @@ public class TISBindHelper implements ServiceConnection {
|
||||
public void onDestroy() {
|
||||
internalUnbindToTIS();
|
||||
resetServiceBindRetryState();
|
||||
mBinder = null;
|
||||
mIsConnected = false;
|
||||
mPendingConnectedCallbacks.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user