Add sdk version guard to UserManager use

Also switch call to getUserRestrictions to support back to JBMR2
with one call.

Bug: 17300500
Change-Id: I1205730e517c6670f6359a0d448458cae6e8a8d4
This commit is contained in:
Jason Monk
2014-09-02 13:13:24 -04:00
parent 25ad9e4ee5
commit 6a2c77856f

View File

@@ -30,6 +30,8 @@ import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.TransitionDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.util.AttributeSet;
import android.view.View;
@@ -193,11 +195,14 @@ public class DeleteDropTarget extends ButtonDropTarget {
isVisible = false;
}
if (useUninstallLabel) {
UserManager userManager = (UserManager)
getContext().getSystemService(Context.USER_SERVICE);
if (userManager.hasUserRestriction(UserManager.DISALLOW_APPS_CONTROL)
|| userManager.hasUserRestriction(UserManager.DISALLOW_UNINSTALL_APPS)) {
isVisible = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
UserManager userManager = (UserManager)
getContext().getSystemService(Context.USER_SERVICE);
Bundle restrictions = userManager.getUserRestrictions();
if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
|| restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
isVisible = false;
}
}
}