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

Commit cab7ed2b authored by Jonathan Scott's avatar Jonathan Scott
Browse files

Also listen to ACTION_MANAGED_PROFILE_AVAILABLE in sharesheet

ResolverActivity.

Test: Manual, using `adb shell su 1000 service call user 72 s16 android
i32 1 i32 10 i32 0 i32 0 && adb shell su 1000 service call user 72 s16
android i32 0 i32 10 i32 0 i32 0` to quickly toggle work profile while
on share sheet. Confirm that the work profile is visible again.
Fixes: 159646289

Change-Id: I29e5600b6d416e1bb6150629c9d94d20b344e4a9
parent b3f5a7a9
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@ import static android.Manifest.permission.INTERACT_ACROSS_PROFILES;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.PermissionChecker.PID_UNKNOWN;

import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_WORK;

import android.annotation.Nullable;
import android.annotation.StringRes;
import android.annotation.UiThread;
@@ -159,6 +156,9 @@ public class ResolverActivity extends Activity implements
    protected static final String METRICS_CATEGORY_RESOLVER = "intent_resolver";
    protected static final String METRICS_CATEGORY_CHOOSER = "intent_chooser";

    /** Tracks if we should ignore future broadcasts telling us the work profile is enabled */
    private boolean mWorkProfileHasBeenEnabled = false;

    @VisibleForTesting
    public static boolean ENABLE_TABBED_VIEW = true;
    private static final String TAB_TAG_PERSONAL = "personal";
@@ -825,12 +825,23 @@ public class ResolverActivity extends Activity implements
        if (shouldShowTabs()) {
            mWorkProfileStateReceiver = createWorkProfileStateReceiver();
            registerWorkProfileStateReceiver();

            mWorkProfileHasBeenEnabled = isWorkProfileEnabled();
        }
    }

    private boolean isWorkProfileEnabled() {
        UserHandle workUserHandle = getWorkProfileUserHandle();
        UserManager userManager = getSystemService(UserManager.class);

        return !userManager.isQuietModeEnabled(workUserHandle)
                && userManager.isUserUnlocked(workUserHandle);
    }

    private void registerWorkProfileStateReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_USER_UNLOCKED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
        registerReceiverAsUser(mWorkProfileStateReceiver, UserHandle.ALL, filter, null, null);
    }
@@ -1961,17 +1972,29 @@ public class ResolverActivity extends Activity implements
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (!TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
                        && !TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
                        && !TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
                        && !TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_AVAILABLE)) {
                    return;
                }
                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
                        && userHandle != getWorkProfileUserHandle().getIdentifier()) {

                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);

                if (userId != getWorkProfileUserHandle().getIdentifier()) {
                    return;
                }

                if (isWorkProfileEnabled()) {
                    if (mWorkProfileHasBeenEnabled) {
                        return;
                    }
                if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)) {

                    mWorkProfileHasBeenEnabled = true;
                    mMultiProfilePagerAdapter.markWorkProfileEnabledBroadcastReceived();
                } else {
                    // Must be an UNAVAILABLE broadcast, so we watch for the next availability
                    mWorkProfileHasBeenEnabled = false;
                }

                if (mMultiProfilePagerAdapter.getCurrentUserHandle()
                        .equals(getWorkProfileUserHandle())) {
                    mMultiProfilePagerAdapter.rebuildActiveTab(true);