Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2665fc07 authored by Rubin Xu's avatar Rubin Xu Committed by Android (Google) Code Review
Browse files

Merge "Add metric logging for new delegated APIs"

parents 576c8b77 8b17ad02
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ public final class DevicePolicyEventLogger {
    }

    /**
     * Retrieves the package name of the admin application from the {@link ComponentName}.
     * Sets the package name of the admin application from the {@link ComponentName}.
     */
    public DevicePolicyEventLogger setAdmin(@Nullable ComponentName componentName) {
        mAdminPackageName = (componentName != null ? componentName.getPackageName() : null);
+4 −2
Original line number Diff line number Diff line
@@ -136,11 +136,13 @@ enum EventId {

  SEPARATE_PROFILE_CHALLENGE_CHANGED = 110;
  SET_GLOBAL_SETTING = 111;
  PM_IS_INSTALLER_DEVICE_OWNER_OR_AFFILIATED_PROFILE_OWNER = 112;
  PM_UNINSTALL = 113;
  INSTALL_PACKAGE = 112;
  UNINSTALL_PACKAGE = 113;
  WIFI_SERVICE_ADD_NETWORK_SUGGESTIONS = 114;
  WIFI_SERVICE_ADD_OR_UPDATE_NETWORK = 115;
  QUERY_SUMMARY_FOR_DEVICE = 116;
  REMOVE_CROSS_PROFILE_WIDGET_PROVIDER = 117;
  ESTABLISH_VPN = 118;
  SET_NETWORK_LOGGING_ENABLED = 119;
  RETRIEVE_NETWORK_LOGS = 120;
}
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PackageDeleteObserver;
import android.app.PackageInstallObserver;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.Context;
import android.content.Intent;
@@ -59,6 +60,7 @@ import android.os.RemoteException;
import android.os.SELinux;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.stats.devicepolicy.DevicePolicyEnums;
import android.system.ErrnoException;
import android.system.Os;
import android.text.TextUtils;
@@ -810,6 +812,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.UNINSTALL_PACKAGE)
                    .setAdmin(callerPackageName)
                    .write();
        } else {
            ApplicationInfo appInfo = mPm.getApplicationInfo(callerPackageName, 0, userId);
            if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
+8 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import static com.android.server.pm.PackageInstallerService.prepareStageDir;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.Context;
import android.content.IIntentReceiver;
@@ -82,6 +83,7 @@ import android.os.RevocableFileDescriptor;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.stats.devicepolicy.DevicePolicyEnums;
import android.system.ErrnoException;
import android.system.Int64Ref;
import android.system.Os;
@@ -1072,6 +1074,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }

    private void handleCommit() {
        if (isInstallerDeviceOwnerOrAffiliatedProfileOwnerLocked()) {
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.INSTALL_PACKAGE)
                    .setAdmin(mInstallerPackageName)
                    .write();
        }
        if (params.isStaged) {
            try {
                mStagingManager.commitSession(this);
+19 −3
Original line number Diff line number Diff line
@@ -5912,10 +5912,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        delegateReceiver = resolveDelegateReceiver(DELEGATION_CERT_SELECTION,
                DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS, caller.getIdentifier());
        final boolean isDelegate;
        if (delegateReceiver != null) {
            intent.setComponent(delegateReceiver);
            isDelegate = true;
        } else {
            intent.setComponent(aliasChooser);
            isDelegate = false;
        }
        final long id = mInjector.binderClearCallingIdentity();
@@ -5927,11 +5930,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    sendPrivateKeyAliasResponse(chosenAlias, response);
                }
            }, null, Activity.RESULT_OK, null, null);
            final String adminPackageName =
                    (aliasChooser != null ? aliasChooser.getPackageName() : null);
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.CHOOSE_PRIVATE_KEY_ALIAS)
                    .setAdmin(adminPackageName)
                    .setAdmin(intent.getComponent())
                    .setBoolean(isDelegate)
                    .write();
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
@@ -13091,6 +13093,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            saveSettingsLocked(mInjector.userHandleGetCallingUserId());
            setNetworkLoggingActiveInternal(enabled);
            final boolean isDelegate = (admin == null);
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.SET_NETWORK_LOGGING_ENABLED)
                    .setAdmin(packageName)
                    .setBoolean(isDelegate)
                    .setInt(enabled ? 1 : 0)
                    .write();
        }
    }
@@ -13222,6 +13232,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    || !isNetworkLoggingEnabledInternalLocked()) {
                return null;
            }
            final boolean isDelegate = (admin == null);
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.RETRIEVE_NETWORK_LOGS)
                    .setAdmin(packageName)
                    .setBoolean(isDelegate)
                    .write();
            final long currentTime = System.currentTimeMillis();
            DevicePolicyData policyData = getUserData(UserHandle.USER_SYSTEM);