Merge "Also listen to ACTION_MANAGED_PROFILE_AVAILABLE in sharesheet ResolverActivity." into rvc-dev am: 3c34454ae9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11987765 Change-Id: Ia26c3c37e74c993eb73d793ff559f83bf38e4edc
This commit is contained in:
@@ -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.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.content.PermissionChecker.PID_UNKNOWN;
|
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.Nullable;
|
||||||
import android.annotation.StringRes;
|
import android.annotation.StringRes;
|
||||||
import android.annotation.UiThread;
|
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_RESOLVER = "intent_resolver";
|
||||||
protected static final String METRICS_CATEGORY_CHOOSER = "intent_chooser";
|
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
|
@VisibleForTesting
|
||||||
public static boolean ENABLE_TABBED_VIEW = true;
|
public static boolean ENABLE_TABBED_VIEW = true;
|
||||||
private static final String TAB_TAG_PERSONAL = "personal";
|
private static final String TAB_TAG_PERSONAL = "personal";
|
||||||
@@ -825,12 +825,23 @@ public class ResolverActivity extends Activity implements
|
|||||||
if (shouldShowTabs()) {
|
if (shouldShowTabs()) {
|
||||||
mWorkProfileStateReceiver = createWorkProfileStateReceiver();
|
mWorkProfileStateReceiver = createWorkProfileStateReceiver();
|
||||||
registerWorkProfileStateReceiver();
|
registerWorkProfileStateReceiver();
|
||||||
|
|
||||||
|
mWorkProfileHasBeenEnabled = isWorkProfileEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWorkProfileEnabled() {
|
||||||
|
UserHandle workUserHandle = getWorkProfileUserHandle();
|
||||||
|
UserManager userManager = getSystemService(UserManager.class);
|
||||||
|
|
||||||
|
return !userManager.isQuietModeEnabled(workUserHandle)
|
||||||
|
&& userManager.isUserUnlocked(workUserHandle);
|
||||||
|
}
|
||||||
|
|
||||||
private void registerWorkProfileStateReceiver() {
|
private void registerWorkProfileStateReceiver() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||||
|
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||||
registerReceiverAsUser(mWorkProfileStateReceiver, UserHandle.ALL, filter, null, null);
|
registerReceiverAsUser(mWorkProfileStateReceiver, UserHandle.ALL, filter, null, null);
|
||||||
}
|
}
|
||||||
@@ -1961,17 +1972,29 @@ public class ResolverActivity extends Activity implements
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (!TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
|
|
||||||
if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
|
int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
|
||||||
&& userHandle != getWorkProfileUserHandle().getIdentifier()) {
|
|
||||||
|
if (userId != getWorkProfileUserHandle().getIdentifier()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)) {
|
|
||||||
|
if (isWorkProfileEnabled()) {
|
||||||
|
if (mWorkProfileHasBeenEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mWorkProfileHasBeenEnabled = true;
|
||||||
mMultiProfilePagerAdapter.markWorkProfileEnabledBroadcastReceived();
|
mMultiProfilePagerAdapter.markWorkProfileEnabledBroadcastReceived();
|
||||||
|
} else {
|
||||||
|
// Must be an UNAVAILABLE broadcast, so we watch for the next availability
|
||||||
|
mWorkProfileHasBeenEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMultiProfilePagerAdapter.getCurrentUserHandle()
|
if (mMultiProfilePagerAdapter.getCurrentUserHandle()
|
||||||
.equals(getWorkProfileUserHandle())) {
|
.equals(getWorkProfileUserHandle())) {
|
||||||
mMultiProfilePagerAdapter.rebuildActiveTab(true);
|
mMultiProfilePagerAdapter.rebuildActiveTab(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user