Badge the icon properly in policy transparency dialog

Following the pattern used within the Settings app to badge the icon.

For location setting, the dialog is shown in work profile user.
Thus ai.loadIcon badged the icon for the first time and
getUserBadgedIcon baged the second time.

Fixes: 77844928
Test: adb shell wm density 560 -> suspend an app -> launch the app ->
      observe the dialog. Repeat the test with original density.

Change-Id: Ie79c3d9aa7b1a155edc74816850b1349fbd2d606
This commit is contained in:
Tony Mak
2018-04-11 12:40:08 +01:00
parent 1f02712e7a
commit 42b83a604f

View File

@@ -18,19 +18,16 @@ package com.android.settings.enterprise;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AppGlobals;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import android.util.IconDrawableFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -40,6 +37,7 @@ import android.widget.TextView;
import com.android.settings.DeviceAdminAdd;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -99,20 +97,12 @@ public class ActionDisabledByAdminDialogHelper {
|| !RestrictedLockUtils.isCurrentUserOrProfile(mActivity, userId)) {
admin = null;
} else {
ActivityInfo ai = null;
try {
ai = AppGlobals.getPackageManager().getReceiverInfo(admin, 0 /* flags */,
final Drawable badgedIcon = Utils.getBadgedIcon(
IconDrawableFactory.newInstance(mActivity),
mActivity.getPackageManager(),
admin.getPackageName(),
userId);
} catch (RemoteException e) {
Log.w(TAG, "Missing reciever info", e);
}
if (ai != null) {
final Drawable icon = ai.loadIcon(mActivity.getPackageManager());
final Drawable badgedIcon = mActivity.getPackageManager().getUserBadgedIcon(
icon, new UserHandle(userId));
((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(
badgedIcon);
}
((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(badgedIcon);
}
setAdminSupportTitle(root, restriction);