Refresh list on work profile state change.
When the work profile is enabled or disabled from anywhere on the device, the share sheet and the intent picker will refresh to either show the list of work targets or show the empty state screen that the work profile is not enabled. Showing that empty state screen also has a button to enable the work profile. Pressing it enables the work profile and also refreshes the list. Fixes: 149497248 Test: manually toggled the work profile from quick settings, from the empty state screen button and from launcher for both share sheet and intent picker. Change-Id: I25e38b0cb5824ebdcf6255ed1959e9d7c6fac445
This commit is contained in:
committed by
Antoan Angelov
parent
b20749400c
commit
7f8743d50c
@@ -307,6 +307,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
showListView(activeListAdapter);
|
||||
return activeListAdapter.rebuildList(doPostProcessing);
|
||||
}
|
||||
|
||||
@@ -349,6 +350,14 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
button.setOnClickListener(buttonOnClick);
|
||||
}
|
||||
|
||||
private void showListView(ResolverListAdapter activeListAdapter) {
|
||||
ProfileDescriptor descriptor = getItem(
|
||||
userHandleToPageIndex(activeListAdapter.getUserHandle()));
|
||||
descriptor.rootView.findViewById(R.id.resolver_list).setVisibility(View.VISIBLE);
|
||||
View emptyStateView = descriptor.rootView.findViewById(R.id.resolver_empty_state);
|
||||
emptyStateView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private boolean hasCrossProfileIntents(List<Intent> intents, int source, int target) {
|
||||
IPackageManager packageManager = AppGlobals.getPackageManager();
|
||||
ContentResolver contentResolver = mContext.getContentResolver();
|
||||
|
||||
@@ -1476,7 +1476,6 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
|
||||
@Override
|
||||
public void addUseDifferentAppLabelIfNecessary(ResolverListAdapter adapter) {
|
||||
mChooserMultiProfilePagerAdapter.getActiveAdapterView().setVisibility(View.VISIBLE);
|
||||
if (mCallerChooserTargets != null && mCallerChooserTargets.length > 0) {
|
||||
mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults(
|
||||
/* origTarget */ null,
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.app.VoiceInteractor.PickOptionRequest;
|
||||
import android.app.VoiceInteractor.PickOptionRequest.Option;
|
||||
import android.app.VoiceInteractor.Prompt;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -169,6 +170,8 @@ public class ResolverActivity extends Activity implements
|
||||
// Intent extra for connected audio devices
|
||||
public static final String EXTRA_IS_AUDIO_CAPTURE_DEVICE = "is_audio_capture_device";
|
||||
|
||||
private BroadcastReceiver mWorkProfileStateReceiver;
|
||||
|
||||
/**
|
||||
* Get the string resource to be used as a label for the link to the resolver activity for an
|
||||
* action.
|
||||
@@ -739,6 +742,22 @@ public class ResolverActivity extends Activity implements
|
||||
updateProfileViewButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (hasWorkProfile() && ENABLE_TABBED_VIEW) {
|
||||
mWorkProfileStateReceiver = createWorkProfileStateReceiver();
|
||||
registerWorkProfileStateReceiver();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerWorkProfileStateReceiver() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
registerReceiverAsUser(mWorkProfileStateReceiver, UserHandle.ALL, filter, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
@@ -763,6 +782,10 @@ public class ResolverActivity extends Activity implements
|
||||
finish();
|
||||
}
|
||||
}
|
||||
if (mWorkPackageMonitor != null) {
|
||||
unregisterReceiver(mWorkProfileStateReceiver);
|
||||
mWorkPackageMonitor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1681,6 +1704,25 @@ public class ResolverActivity extends Activity implements
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver createWorkProfileStateReceiver() {
|
||||
return new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (!TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
||||
&& !TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
|
||||
return;
|
||||
}
|
||||
if (mMultiProfilePagerAdapter.getCurrentUserHandle()
|
||||
== getWorkProfileUserHandle()) {
|
||||
mMultiProfilePagerAdapter.rebuildActiveTab(true);
|
||||
} else {
|
||||
mMultiProfilePagerAdapter.clearInactiveProfileCache();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static final class ResolvedComponentInfo {
|
||||
public final ComponentName name;
|
||||
|
||||
Reference in New Issue
Block a user