Merge "Also listen to ACTION_MANAGED_PROFILE_AVAILABLE in sharesheet ResolverActivity." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-06-25 16:29:26 +00:00
committed by Android (Google) Code Review

View File

@@ -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 (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)) {
if (isWorkProfileEnabled()) {
if (mWorkProfileHasBeenEnabled) {
return;
}
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);