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

Commit d2d3e4d9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert DevicePolicyManager time / zone changes" into rvc-dev

parents 94be6df3 ce509627
Loading
Loading
Loading
Loading
+2 −21
Original line number Diff line number Diff line
@@ -148,10 +148,6 @@ import android.app.admin.StartInstallingUpdateCallback;
import android.app.admin.SystemUpdateInfo;
import android.app.admin.SystemUpdatePolicy;
import android.app.backup.IBackupManager;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.TimeDetector;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TimeZoneDetector;
import android.app.trust.TrustManager;
import android.app.usage.UsageStatsManagerInternal;
import android.compat.annotation.ChangeId;
@@ -2118,14 +2114,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            return mContext.getSystemService(AlarmManager.class);
        }
        TimeDetector getTimeDetector() {
            return mContext.getSystemService(TimeDetector.class);
        }
        TimeZoneDetector getTimeZoneDetector() {
            return mContext.getSystemService(TimeZoneDetector.class);
        }
        ConnectivityManager getConnectivityManager() {
            return mContext.getSystemService(ConnectivityManager.class);
        }
@@ -11730,15 +11718,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME, 0) == 1) {
            return false;
        }
        ManualTimeSuggestion manualTimeSuggestion = TimeDetector.createManualTimeSuggestion(
                millis, "DevicePolicyManagerService: setTime");
        mInjector.binderWithCleanCallingIdentity(
                () -> mInjector.getTimeDetector().suggestManualTime(manualTimeSuggestion));
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_TIME)
                .setAdmin(who)
                .write();
        mInjector.binderWithCleanCallingIdentity(() -> mInjector.getAlarmManager().setTime(millis));
        return true;
    }
@@ -11750,11 +11734,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) {
            return false;
        }
        ManualTimeZoneSuggestion manualTimeZoneSuggestion =
                TimeZoneDetector.createManualTimeZoneSuggestion(
                        timeZone, "DevicePolicyManagerService: setTimeZone");
        mInjector.binderWithCleanCallingIdentity(() ->
                mInjector.getTimeZoneDetector().suggestManualTimeZone(manualTimeZoneSuggestion));
                mInjector.getAlarmManager().setTimeZone(timeZone));
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_TIME_ZONE)
+0 −12
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import android.app.IActivityTaskManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.backup.IBackupManager;
import android.app.timedetector.TimeDetector;
import android.app.timezonedetector.TimeZoneDetector;
import android.app.usage.UsageStatsManagerInternal;
import android.content.Context;
import android.content.Intent;
@@ -235,16 +233,6 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi
        @Override
        AlarmManager getAlarmManager() {return services.alarmManager;}

        @Override
        TimeDetector getTimeDetector() {
            return services.timeDetector;
        }

        @Override
        TimeZoneDetector getTimeZoneDetector() {
            return services.timeZoneDetector;
        }

        @Override
        LockPatternUtils newLockPatternUtils() {
            return services.lockPatternUtils;
+4 −35
Original line number Diff line number Diff line
@@ -67,9 +67,6 @@ import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.FactoryResetProtectionPolicy;
import android.app.admin.PasswordMetrics;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TimeZoneDetector;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Intent;
@@ -3969,19 +3966,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        setupDeviceOwner();
        dpm.setTime(admin1, 0);

        BaseMatcher<ManualTimeSuggestion> hasZeroTime = new BaseMatcher<ManualTimeSuggestion>() {
            @Override
            public boolean matches(Object item) {
                final ManualTimeSuggestion suggestion = (ManualTimeSuggestion) item;
                return suggestion.getUtcTime().getValue() == 0;
            }
            @Override
            public void describeTo(Description description) {
                description.appendText("ManualTimeSuggestion{utcTime.value=0}");
            }
        };
        verify(getServices().timeDetector).suggestManualTime(argThat(hasZeroTime));
        verify(getServices().alarmManager).setTime(0);
    }

    public void testSetTimeFailWithPO() throws Exception {
@@ -3993,19 +3978,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        setupProfileOwner();
        configureProfileOwnerOfOrgOwnedDevice(admin1, DpmMockContext.CALLER_USER_HANDLE);
        dpm.setTime(admin1, 0);

        BaseMatcher<ManualTimeSuggestion> hasZeroTime = new BaseMatcher<ManualTimeSuggestion>() {
            @Override
            public boolean matches(Object item) {
                final ManualTimeSuggestion suggestion = (ManualTimeSuggestion) item;
                return suggestion.getUtcTime().getValue() == 0;
            }
            @Override
            public void describeTo(Description description) {
                description.appendText("ManualTimeSuggestion{utcTime.value=0}");
            }
        };
        verify(getServices().timeDetector).suggestManualTime(argThat(hasZeroTime));
        verify(getServices().alarmManager).setTime(0);
    }

    public void testSetTimeWithAutoTimeOn() throws Exception {
@@ -4020,9 +3993,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        setupDeviceOwner();
        dpm.setTimeZone(admin1, "Asia/Shanghai");
        ManualTimeZoneSuggestion suggestion =
                TimeZoneDetector.createManualTimeZoneSuggestion("Asia/Shanghai", "Test debug info");
        verify(getServices().timeZoneDetector).suggestManualTimeZone(suggestion);
        verify(getServices().alarmManager).setTimeZone("Asia/Shanghai");
    }

    public void testSetTimeZoneFailWithPO() throws Exception {
@@ -4035,9 +4006,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        setupProfileOwner();
        configureProfileOwnerOfOrgOwnedDevice(admin1, DpmMockContext.CALLER_USER_HANDLE);
        dpm.setTimeZone(admin1, "Asia/Shanghai");
        ManualTimeZoneSuggestion suggestion =
                TimeZoneDetector.createManualTimeZoneSuggestion("Asia/Shanghai", "Test debug info");
        verify(getServices().timeZoneDetector).suggestManualTimeZone(suggestion);
        verify(getServices().alarmManager).setTimeZone("Asia/Shanghai");
    }

    public void testSetTimeZoneWithAutoTimeZoneOn() throws Exception {
+0 −2
Original line number Diff line number Diff line
@@ -207,8 +207,6 @@ public class DpmMockContext extends MockContext {
        switch (name) {
            case Context.ALARM_SERVICE:
                return mMockSystemServices.alarmManager;
            case Context.TIME_DETECTOR_SERVICE:
                return mMockSystemServices.timeDetector;
            case Context.USER_SERVICE:
                return mMockSystemServices.userManager;
            case Context.POWER_SERVICE:
+0 −6
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ import android.app.IActivityManager;
import android.app.IActivityTaskManager;
import android.app.NotificationManager;
import android.app.backup.IBackupManager;
import android.app.timedetector.TimeDetector;
import android.app.timezonedetector.TimeZoneDetector;
import android.app.usage.UsageStatsManagerInternal;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -118,8 +116,6 @@ public class MockSystemServices {
    public final TelephonyManager telephonyManager;
    public final AccountManager accountManager;
    public final AlarmManager alarmManager;
    public final TimeDetector timeDetector;
    public final TimeZoneDetector timeZoneDetector;
    public final KeyChain.KeyChainConnection keyChainConnection;
    public final CrossProfileApps crossProfileApps;
    public final PersistentDataBlockManagerInternal persistentDataBlockManagerInternal;
@@ -164,8 +160,6 @@ public class MockSystemServices {
        telephonyManager = mock(TelephonyManager.class);
        accountManager = mock(AccountManager.class);
        alarmManager = mock(AlarmManager.class);
        timeDetector = mock(TimeDetector.class);
        timeZoneDetector = mock(TimeZoneDetector.class);
        keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS);
        crossProfileApps = mock(CrossProfileApps.class);
        persistentDataBlockManagerInternal = mock(PersistentDataBlockManagerInternal.class);