OSDN Git Service

Call SecurityLog methods via Injector
authorRubin Xu <rubinxu@google.com>
Tue, 2 Feb 2016 18:00:28 +0000 (18:00 +0000)
committerRubin Xu <rubinxu@google.com>
Tue, 2 Feb 2016 18:00:28 +0000 (18:00 +0000)
This is to make sure the unit test can mock them out.

Bug: 26911599
Change-Id: I07a1a8b43ad5716a4b667bc5266b3b03997268c5

services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java

index e8b9b1f..572843e 100644 (file)
@@ -1463,6 +1463,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
         void securityLogSetLoggingEnabledProperty(boolean enabled) {
             SecurityLog.setLoggingEnabledProperty(enabled);
         }
+
+        boolean securityLogGetLoggingEnabledProperty() {
+            return SecurityLog.getLoggingEnabledProperty();
+        }
+
+        boolean securityLogIsLoggingEnabled() {
+            return SecurityLog.isLoggingEnabled();
+        }
     }
 
     /**
@@ -1607,7 +1615,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
             if (mOwners.hasDeviceOwner()) {
                 mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, "true");
                 disableDeviceLoggingIfNotCompliant();
-                if (SecurityLog.getLoggingEnabledProperty()) {
+                if (mInjector.securityLogGetLoggingEnabledProperty()) {
                     mSecurityLogMonitor.start();
                 }
             } else {
@@ -4472,7 +4480,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
             mInjector.binderRestoreCallingIdentity(ident);
         }
 
-        if (SecurityLog.isLoggingEnabled()) {
+        if (mInjector.securityLogIsLoggingEnabled()) {
             SecurityLog.writeEvent(SecurityLog.TAG_KEYGUARD_DISMISS_AUTH_ATTEMPT, /*result*/ 0);
         }
     }
@@ -4502,7 +4510,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
             }
         }
 
-        if (SecurityLog.isLoggingEnabled()) {
+        if (mInjector.securityLogIsLoggingEnabled()) {
             SecurityLog.writeEvent(SecurityLog.TAG_KEYGUARD_DISMISS_AUTH_ATTEMPT, /*result*/ 1);
         }
     }
@@ -4511,7 +4519,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
     public void reportKeyguardDismissed() {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-        if (SecurityLog.isLoggingEnabled()) {
+        if (mInjector.securityLogIsLoggingEnabled()) {
             SecurityLog.writeEvent(SecurityLog.TAG_KEYGUARD_DISMISSED);
         }
     }
@@ -4520,7 +4528,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
     public void reportKeyguardSecured() {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-        if (SecurityLog.isLoggingEnabled()) {
+        if (mInjector.securityLogIsLoggingEnabled()) {
             SecurityLog.writeEvent(SecurityLog.TAG_KEYGUARD_SECURED);
         }
     }
@@ -8352,7 +8360,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
         Preconditions.checkNotNull(admin);
         synchronized (this) {
             getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
-            return SecurityLog.getLoggingEnabledProperty();
+            return mInjector.securityLogGetLoggingEnabledProperty();
         }
     }
 
index bd37f4a..db2a9ad 100644 (file)
@@ -291,5 +291,15 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi
         void securityLogSetLoggingEnabledProperty(boolean enabled) {
             context.settings.securityLogSetLoggingEnabledProperty(enabled);
         }
+
+        @Override
+        boolean securityLogGetLoggingEnabledProperty() {
+            return context.settings.securityLogGetLoggingEnabledProperty();
+        }
+
+        @Override
+        boolean securityLogIsLoggingEnabled() {
+            return context.settings.securityLogIsLoggingEnabled();
+        }
     }
 }
index 6518732..7a00098 100644 (file)
@@ -198,6 +198,14 @@ public class DpmMockContext extends MockContext {
 
         void securityLogSetLoggingEnabledProperty(boolean enabled) {
         }
+
+        public boolean securityLogGetLoggingEnabledProperty() {
+            return false;
+        }
+
+        public boolean securityLogIsLoggingEnabled() {
+            return false;
+        }
     }
 
     public final Context realTestContext;