Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b2300b0 authored by Rubin Xu's avatar Rubin Xu Committed by Android (Google) Code Review
Browse files

Merge "Relaunch previous activity after turning work profile on" into nyc-dev

parents 55e00501 e420c550
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -53,6 +54,7 @@ public class UnlaunchableAppActivity extends Activity

    private int mUserId;
    private int mReason;
    private IntentSender mTarget;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -60,6 +62,7 @@ public class UnlaunchableAppActivity extends Activity
        Intent intent = getIntent();
        mReason = intent.getIntExtra(EXTRA_UNLAUNCHABLE_REASON, -1);
        mUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
        mTarget = intent.getParcelableExtra(Intent.EXTRA_INTENT);

        if (mUserId == UserHandle.USER_NULL) {
            Log.wtf(TAG, "Invalid user id: " + mUserId + ". Stopping.");
@@ -105,6 +108,14 @@ public class UnlaunchableAppActivity extends Activity
    public void onClick(DialogInterface dialog, int which) {
        if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE && which == DialogInterface.BUTTON_POSITIVE) {
            UserManager.get(this).setQuietModeEnabled(mUserId, false);

            if (mTarget != null) {
                try {
                    startIntentSenderForResult(mTarget, -1, null, 0, 0, 0);
                } catch (IntentSender.SendIntentException e) {
                    /* ignore */
                }
            }
        }
    }

@@ -121,4 +132,10 @@ public class UnlaunchableAppActivity extends Activity
        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
        return intent;
    }

    public static Intent createInQuietModeDialogIntent(int userId, IntentSender target) {
        Intent intent = createInQuietModeDialogIntent(userId);
        intent.putExtra(Intent.EXTRA_INTENT, target);
        return intent;
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -119,7 +119,13 @@ class ActivityStartInterceptor {
        if (!mUserManager.isQuietModeEnabled(UserHandle.of(mUserId))) {
            return false;
        }
        mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId);
        IIntentSender target = mService.getIntentSenderLocked(
                INTENT_SENDER_ACTIVITY, mCallingPackage, mCallingUid, mUserId, null, null, 0,
                new Intent[] {mIntent}, new String[] {mResolvedType},
                FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT, null);

        mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId,
                new IntentSender(target));
        mCallingPid = mRealCallingPid;
        mCallingUid = mRealCallingUid;
        mResolvedType = null;