Merge "[Work Profile] Fix NPE on WorkModeSwitch" into sc-v2-dev

This commit is contained in:
Samuel Fufa 2021-10-19 22:01:25 +00:00 committed by Android (Google) Code Review
commit c46c83c8c8
2 changed files with 9 additions and 5 deletions

View File

@ -485,8 +485,9 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mViewPager = (AllAppsPagedView) newView;
mViewPager.initParentViews(this);
mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
mWorkManager.attachWorkModeSwitch();
mWorkManager.getWorkModeSwitch().post(() -> mAH[AdapterHolder.WORK].applyPadding());
if (mWorkManager.attachWorkModeSwitch()) {
mWorkManager.getWorkModeSwitch().post(() -> mAH[AdapterHolder.WORK].applyPadding());
}
} else {
mWorkManager.detachWorkModeSwitch();
mViewPager = null;

View File

@ -28,6 +28,7 @@ import android.os.UserManager;
import android.util.Log;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.android.launcher3.R;
@ -127,11 +128,11 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
/**
* Creates and attaches for profile toggle button to {@link AllAppsContainerView}
*/
public void attachWorkModeSwitch() {
public boolean attachWorkModeSwitch() {
if (!mAllApps.getAppsStore().hasModelFlag(
FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION)) {
Log.e(TAG, "Unable to attach widget; Missing required permissions");
return;
Log.e(TAG, "unable to attach work mode switch; Missing required permissions");
return false;
}
if (mWorkModeSwitch == null) {
mWorkModeSwitch = (WorkModeSwitch) mAllApps.getLayoutInflater().inflate(
@ -144,6 +145,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
getAH().applyPadding();
}
mWorkModeSwitch.updateCurrentState(mCurrentState == STATE_ENABLED);
return true;
}
/**
@ -165,6 +167,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
return mMatcher;
}
@Nullable
public WorkModeSwitch getWorkModeSwitch() {
return mWorkModeSwitch;
}