Using a proxy activity for startActivityForResult
This ensures that the home task is never blocked by a different task Bug: 74500048 Change-Id: I01fd26f1d6242e39b2d8fabac5e064b748aebe62
This commit is contained in:
1 parent
7daf892f66
commit
dedda05568
8 files changed
+314
-10
No files matched your search
@@ -72,7 +72,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.Toast;
|
||||
@@ -191,6 +190,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
private static final String RUNTIME_STATE = "launcher.state";
|
||||
// Type: PendingRequestArgs
|
||||
private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
|
||||
// Type: int
|
||||
private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code";
|
||||
// Type: ActivityResultInfo
|
||||
private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
|
||||
// Type: SparseArray<Parcelable>
|
||||
@@ -264,6 +265,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
* {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
|
||||
*/
|
||||
private PendingRequestArgs mPendingRequestArgs;
|
||||
// Request id for any pending activity result
|
||||
private int mPendingActivityRequestCode = -1;
|
||||
|
||||
public ViewGroupFocusHelper mFocusHandler;
|
||||
|
||||
@@ -762,6 +765,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
@Override
|
||||
public void onActivityResult(
|
||||
final int requestCode, final int resultCode, final Intent data) {
|
||||
mPendingActivityRequestCode = -1;
|
||||
handleActivityResult(requestCode, resultCode, data);
|
||||
if (mLauncherCallbacks != null) {
|
||||
mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -890,9 +894,21 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
|
||||
UiFactory.onLauncherStateOrResumeChanged(this);
|
||||
AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
|
||||
resetPendingActivityResultIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetPendingActivityResultIfNeeded() {
|
||||
if (hasBeenResumed() && mPendingActivityRequestCode != -1 && isInState(NORMAL)) {
|
||||
UiFactory.resetPendingActivityResults(this, mPendingActivityRequestCode);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onStateSet(LauncherState state) {
|
||||
getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
|
||||
resetPendingActivityResultIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
RaceConditionTracker.onEvent(ON_RESUME_EVT, ENTER);
|
||||
@@ -1009,6 +1025,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
if (requestArgs != null) {
|
||||
setWaitingForResult(requestArgs);
|
||||
}
|
||||
mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE);
|
||||
|
||||
mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
|
||||
|
||||
@@ -1392,6 +1409,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
if (mPendingRequestArgs != null) {
|
||||
outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
|
||||
}
|
||||
outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode);
|
||||
|
||||
if (mPendingActivityResult != null) {
|
||||
outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
|
||||
}
|
||||
@@ -1448,17 +1467,29 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
if (requestCode != -1) {
|
||||
mPendingActivityRequestCode = requestCode;
|
||||
}
|
||||
if (requestCode == -1
|
||||
|| !UiFactory.startActivityForResult(this, intent, requestCode, options)) {
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startIntentSenderForResult (IntentSender intent, int requestCode,
|
||||
public void startIntentSenderForResult(IntentSender intent, int requestCode,
|
||||
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
|
||||
try {
|
||||
super.startIntentSenderForResult(intent, requestCode,
|
||||
fillInIntent, flagsMask, flagsValues, extraFlags, options);
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
throw new ActivityNotFoundException();
|
||||
if (requestCode != -1) {
|
||||
mPendingActivityRequestCode = requestCode;
|
||||
}
|
||||
if (requestCode == -1 || !UiFactory.startIntentSenderForResult(this, intent, requestCode,
|
||||
fillInIntent, flagsMask, flagsValues, extraFlags, options)) {
|
||||
try {
|
||||
super.startIntentSenderForResult(intent, requestCode,
|
||||
fillInIntent, flagsMask, flagsValues, extraFlags, options);
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
throw new ActivityNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -452,7 +452,7 @@ public class LauncherStateManager {
|
||||
}
|
||||
mState = state;
|
||||
mState.onStateEnabled(mLauncher);
|
||||
mLauncher.getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
|
||||
mLauncher.onStateSet(mState);
|
||||
|
||||
if (state.disablePageClipping) {
|
||||
// Only disable clipping if needed, otherwise leave it as previous value.
|
||||
|
||||
@@ -46,6 +46,8 @@ import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.LauncherStateManager;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.FirstFrameAnimatorHelper;
|
||||
@@ -60,7 +62,7 @@ import androidx.dynamicanimation.animation.FloatPropertyCompat;
|
||||
import androidx.dynamicanimation.animation.SpringAnimation;
|
||||
import androidx.dynamicanimation.animation.SpringForce;
|
||||
|
||||
public class DragView extends View {
|
||||
public class DragView extends View implements LauncherStateManager.StateListener {
|
||||
private static final ColorMatrix sTempMatrix1 = new ColorMatrix();
|
||||
private static final ColorMatrix sTempMatrix2 = new ColorMatrix();
|
||||
|
||||
@@ -172,6 +174,27 @@ public class DragView extends View {
|
||||
setElevation(getResources().getDimension(R.dimen.drag_elevation));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mLauncher.getStateManager().addStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mLauncher.getStateManager().removeStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateTransitionStart(LauncherState toState) { }
|
||||
|
||||
@Override
|
||||
public void onStateTransitionComplete(LauncherState finalState) {
|
||||
setVisibility((finalState == LauncherState.NORMAL
|
||||
|| finalState == LauncherState.SPRING_LOADED) ? VISIBLE : INVISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize {@code #mIconDrawable} if the item can be represented using
|
||||
* an {@link AdaptiveIconDrawable} or {@link FolderAdaptiveIcon}.
|
||||
|
||||
Reference in new issue
Block a user