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

Commit 18e0a3ab authored by Jay Aliomer's avatar Jay Aliomer Committed by Android (Google) Code Review
Browse files

Merge "Allow SUW to change dark theme" into rvc-dev

parents 62292c85 e07d6f7a
Loading
Loading
Loading
Loading
+16 −76
Original line number Diff line number Diff line
@@ -122,7 +122,6 @@ final class UiModeManagerService extends SystemService {
    private boolean mVrHeadset;
    private boolean mComputedNightMode;
    private int mCarModeEnableFlags;
    private boolean mSetupWizardComplete;

    // flag set by resource, whether to enable Car dock launch when starting car mode.
    private boolean mEnableCarDockLaunch = true;
@@ -164,12 +163,6 @@ final class UiModeManagerService extends SystemService {
        mConfiguration.setToDefaults();
    }

    @VisibleForTesting
    protected UiModeManagerService(Context context, boolean setupWizardComplete) {
        this(context);
        mSetupWizardComplete = setupWizardComplete;
    }

    private static Intent buildHomeIntent(String category) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(category);
@@ -283,25 +276,6 @@ final class UiModeManagerService extends SystemService {
        }
    };

    private final ContentObserver mSetupWizardObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            synchronized (mLock) {
                // setup wizard is done now so we can unblock
                if (setupWizardCompleteForCurrentUser() && !selfChange) {
                    mSetupWizardComplete = true;
                    getContext().getContentResolver()
                            .unregisterContentObserver(mSetupWizardObserver);
                    // update night mode
                    Context context = getContext();
                    updateNightModeFromSettingsLocked(context, context.getResources(),
                            UserHandle.getCallingUserId());
                    updateLocked(0, 0);
                }
            }
        }
    };

    private final ContentObserver mDarkThemeObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
@@ -318,13 +292,6 @@ final class UiModeManagerService extends SystemService {
        SystemProperties.set(SYSTEM_PROPERTY_DEVICE_THEME, Integer.toString(mode));
    }

    @Override
    public void onSwitchUser(int userHandle) {
        super.onSwitchUser(userHandle);
        getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
        verifySetupWizardCompleted();
    }

    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
@@ -351,6 +318,8 @@ final class UiModeManagerService extends SystemService {
                context.registerReceiver(mBatteryReceiver, batteryFilter);
                IntentFilter filter = new IntentFilter();
                filter.addAction(Intent.ACTION_USER_SWITCHED);
                context.registerReceiver(mSettingsRestored,
                        new IntentFilter(Intent.ACTION_SETTING_RESTORED));
                context.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
                updateConfigurationLocked();
                applyConfigurationExternallyLocked();
@@ -361,9 +330,6 @@ final class UiModeManagerService extends SystemService {
    @Override
    public void onStart() {
        final Context context = getContext();
        // If setup isn't complete for this user listen for completion so we can unblock
        // being able to send a night mode configuration change event
        verifySetupWizardCompleted();

        final Resources res = context.getResources();
        mDefaultUiModeType = res.getInteger(
@@ -438,20 +404,6 @@ final class UiModeManagerService extends SystemService {
        return mConfiguration;
    }

    // Records whether setup wizard has happened or not and adds an observer for this user if not.
    private void verifySetupWizardCompleted() {
        final Context context = getContext();
        final int userId = UserHandle.getCallingUserId();
        if (!setupWizardCompleteForCurrentUser()) {
            mSetupWizardComplete = false;
            context.getContentResolver().registerContentObserver(
                    Secure.getUriFor(
                            Secure.USER_SETUP_COMPLETE), false, mSetupWizardObserver, userId);
        } else {
            mSetupWizardComplete = true;
        }
    }

    private boolean setupWizardCompleteForCurrentUser() {
        return Secure.getIntForUser(getContext().getContentResolver(),
                Secure.USER_SETUP_COMPLETE, 0, UserHandle.getCallingUserId()) == 1;
@@ -480,7 +432,6 @@ final class UiModeManagerService extends SystemService {
        final int defaultNightMode = res.getInteger(
                com.android.internal.R.integer.config_defaultNightMode);
        int oldNightMode = mNightMode;
        if (mSetupWizardComplete) {
        mNightMode = Secure.getIntForUser(context.getContentResolver(),
                Secure.UI_NIGHT_MODE, defaultNightMode, userId);
        mOverrideNightModeOn = Secure.getIntForUser(context.getContentResolver(),
@@ -495,13 +446,6 @@ final class UiModeManagerService extends SystemService {
                Secure.getLongForUser(context.getContentResolver(),
                        Secure.DARK_THEME_CUSTOM_END_TIME,
                        DEFAULT_CUSTOM_NIGHT_END_TIME.toNanoOfDay() / 1000L, userId) * 1000);
        } else {
            mNightMode = defaultNightMode;
            mCustomAutoNightModeEndMilliseconds = DEFAULT_CUSTOM_NIGHT_END_TIME;
            mCustomAutoNightModeStartMilliseconds = DEFAULT_CUSTOM_NIGHT_START_TIME;
            mOverrideNightModeOn = false;
            mOverrideNightModeOff = false;
        }

        return oldNightMode != mNightMode;
    }
@@ -644,10 +588,6 @@ final class UiModeManagerService extends SystemService {
                Slog.e(TAG, "Night mode locked, requires MODIFY_DAY_NIGHT_MODE permission");
                return;
            }
            if (!mSetupWizardComplete) {
                Slog.d(TAG, "Night mode cannot be changed before setup wizard completes.");
                return;
            }
            switch (mode) {
                case UiModeManager.MODE_NIGHT_NO:
                case UiModeManager.MODE_NIGHT_YES:
+1 −3
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
import android.os.RemoteException;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import com.android.server.twilight.TwilightManager;
@@ -55,7 +54,6 @@ import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
@@ -146,7 +144,7 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
        addLocalService(PowerManagerInternal.class, mLocalPowerManager);
        addLocalService(TwilightManager.class, mTwilightManager);
        
        mUiManagerService = new UiModeManagerService(mContext, true);
        mUiManagerService = new UiModeManagerService(mContext);
        try {
            mUiManagerService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
        } catch (SecurityException e) {/* ignore for permission denial */}