Dump PersonalAppsSuspensionHelper state.
Test: adb shell dumpsys device_policy |grep -A 20 PersonalAppsSuspensionHelper Bug: 181238156 Change-Id: I5ab83d9026330d10b6054e3f6d2531a7fb6bf01c
This commit is contained in:
@@ -1583,8 +1583,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
}
|
||||
|
||||
public String[] getPersonalAppsForSuspension(int userId) {
|
||||
return new PersonalAppsSuspensionHelper(
|
||||
mContext.createContextAsUser(UserHandle.of(userId), 0 /* flags */))
|
||||
return PersonalAppsSuspensionHelper.forUser(mContext, userId)
|
||||
.getPersonalAppsForSuspension();
|
||||
}
|
||||
|
||||
@@ -1599,6 +1598,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) {
|
||||
mSafetyChecker = safetyChecker;
|
||||
}
|
||||
|
||||
void dumpPerUserData(IndentingPrintWriter pw, @UserIdInt int userId) {
|
||||
PersonalAppsSuspensionHelper.forUser(mContext, userId).dump(pw);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9161,11 +9164,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpDevicePolicyData(IndentingPrintWriter pw) {
|
||||
private void dumpPerUserData(IndentingPrintWriter pw) {
|
||||
int userCount = mUserData.size();
|
||||
for (int u = 0; u < userCount; u++) {
|
||||
DevicePolicyData policy = getUserData(mUserData.keyAt(u));
|
||||
for (int userId = 0; userId < userCount; userId++) {
|
||||
DevicePolicyData policy = getUserData(mUserData.keyAt(userId));
|
||||
policy.dump(pw);
|
||||
pw.println();
|
||||
|
||||
pw.increaseIndent();
|
||||
mInjector.dumpPerUserData(pw, userId);
|
||||
pw.decreaseIndent();
|
||||
pw.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9183,7 +9192,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
pw.println();
|
||||
mDeviceAdminServiceController.dump(pw);
|
||||
pw.println();
|
||||
dumpDevicePolicyData(pw);
|
||||
dumpPerUserData(pw);
|
||||
pw.println();
|
||||
mConstants.dump(pw);
|
||||
pw.println();
|
||||
@@ -9229,20 +9238,30 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
pw.increaseIndent();
|
||||
dumpResources(pw, mContext, "cross_profile_apps", R.array.cross_profile_apps);
|
||||
dumpResources(pw, mContext, "vendor_cross_profile_apps", R.array.vendor_cross_profile_apps);
|
||||
dumpResources(pw, mContext, "config_packagesExemptFromSuspension",
|
||||
R.array.config_packagesExemptFromSuspension);
|
||||
pw.decreaseIndent();
|
||||
pw.println();
|
||||
}
|
||||
|
||||
static void dumpResources(IndentingPrintWriter pw, Context context, String resName, int resId) {
|
||||
String[] apps = context.getResources().getStringArray(resId);
|
||||
if (apps == null || apps.length == 0) {
|
||||
pw.printf("%s: empty\n", resName);
|
||||
dumpApps(pw, resName, context.getResources().getStringArray(resId));
|
||||
}
|
||||
|
||||
static void dumpApps(IndentingPrintWriter pw, String name, String[] apps) {
|
||||
dumpApps(pw, name, Arrays.asList(apps));
|
||||
}
|
||||
|
||||
static void dumpApps(IndentingPrintWriter pw, String name, List apps) {
|
||||
if (apps == null || apps.isEmpty()) {
|
||||
pw.printf("%s: empty\n", name);
|
||||
return;
|
||||
}
|
||||
pw.printf("%s: %d app%s\n", resName, apps.length, apps.length == 1 ? "" : "s");
|
||||
int size = apps.size();
|
||||
pw.printf("%s: %d app%s\n", name, size, size == 1 ? "" : "s");
|
||||
pw.increaseIndent();
|
||||
for (int i = 0; i < apps.length; i++) {
|
||||
pw.printf("%d: %s\n", i, apps[i]);
|
||||
for (int i = 0; i < size; i++) {
|
||||
pw.printf("%d: %s\n", i, apps.get(i));
|
||||
}
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -29,10 +30,12 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.IBinder;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Telephony;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Slog;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.IAccessibilityManager;
|
||||
@@ -49,7 +52,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Utility class to find what personal apps should be suspended to limit personal device use.
|
||||
*/
|
||||
public class PersonalAppsSuspensionHelper {
|
||||
public final class PersonalAppsSuspensionHelper {
|
||||
private static final String LOG_TAG = DevicePolicyManagerService.LOG_TAG;
|
||||
|
||||
// Flags to get all packages even if the user is still locked.
|
||||
@@ -59,10 +62,18 @@ public class PersonalAppsSuspensionHelper {
|
||||
private final Context mContext;
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
/**
|
||||
* Factory method
|
||||
*/
|
||||
public static PersonalAppsSuspensionHelper forUser(Context context, @UserIdInt int userId) {
|
||||
return new PersonalAppsSuspensionHelper(context.createContextAsUser(UserHandle.of(userId),
|
||||
/* flags= */ 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context Context for the user whose apps should to be suspended.
|
||||
*/
|
||||
public PersonalAppsSuspensionHelper(Context context) {
|
||||
private PersonalAppsSuspensionHelper(Context context) {
|
||||
mContext = context;
|
||||
mPackageManager = context.getPackageManager();
|
||||
}
|
||||
@@ -181,4 +192,21 @@ public class PersonalAppsSuspensionHelper {
|
||||
iBinder == null ? null : IAccessibilityManager.Stub.asInterface(iBinder);
|
||||
return new AccessibilityManager(mContext, service, userId);
|
||||
}
|
||||
|
||||
void dump(IndentingPrintWriter pw) {
|
||||
pw.println("PersonalAppsSuspensionHelper");
|
||||
pw.increaseIndent();
|
||||
|
||||
DevicePolicyManagerService.dumpApps(pw, "critical packages", getCriticalPackages());
|
||||
DevicePolicyManagerService.dumpApps(pw, "launcher packages", getSystemLauncherPackages());
|
||||
DevicePolicyManagerService.dumpApps(pw, "accessibility services",
|
||||
getAccessibilityServices());
|
||||
DevicePolicyManagerService.dumpApps(pw, "input method packages", getInputMethodPackages());
|
||||
pw.printf("SMS package: %s\n", Telephony.Sms.getDefaultSmsPackage(mContext));
|
||||
pw.printf("Settings package: %s\n", getSettingsPackageName());
|
||||
DevicePolicyManagerService.dumpApps(pw, "Packages subject to suspension",
|
||||
getPersonalAppsForSuspension());
|
||||
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user