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

Commit 89db5be0 authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge "Remove target Q check for transient night mode in UiModeManager"

parents ff75e72e 3f5ad738
Loading
Loading
Loading
Loading
+6 −31
Original line number Diff line number Diff line
@@ -30,13 +30,11 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.BatteryManager;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.ServiceType;
@@ -356,8 +354,8 @@ final class UiModeManagerService extends SystemService {
            try {
                synchronized (mLock) {
                    if (mNightMode != mode) {
                        // Only persist setting if not transient night mode or not in car mode
                        if (!shouldTransientNightWhenInCarMode() || !mCarModeEnabled) {
                        // Only persist setting if not in car mode
                        if (!mCarModeEnabled) {
                            Settings.Secure.putIntForUser(getContext().getContentResolver(),
                                    Settings.Secure.UI_NIGHT_MODE, mode, user);
                        }
@@ -444,34 +442,12 @@ final class UiModeManagerService extends SystemService {
        }
    }

    // Night mode settings in car mode are only persisted below Q.
    // When targeting Q, changes are not saved and night mode will be re-read
    // from settings when exiting car mode.
    private boolean shouldTransientNightWhenInCarMode() {
        int uid = Binder.getCallingUid();
        PackageManager packageManager = getContext().getPackageManager();
        String[] packagesForUid = packageManager.getPackagesForUid(uid);
        if (packagesForUid == null || packagesForUid.length == 0) {
            return false;
        }

        try {
            ApplicationInfo appInfo = packageManager.getApplicationInfoAsUser(
                    packagesForUid[0], 0, uid);

            return appInfo.targetSdkVersion >= Build.VERSION_CODES.Q;
        } catch (PackageManager.NameNotFoundException ignored) {
        }

        return false;
    }

    void setCarModeLocked(boolean enabled, int flags) {
        if (mCarModeEnabled != enabled) {
            mCarModeEnabled = enabled;

            // When transient night mode and exiting car mode, restore night mode from settings
            if (shouldTransientNightWhenInCarMode() && !mCarModeEnabled) {
            // When exiting car mode, restore night mode from settings
            if (!mCarModeEnabled) {
                Context context = getContext();
                updateNightModeFromSettings(context,
                        context.getResources(),
@@ -534,9 +510,8 @@ final class UiModeManagerService extends SystemService {
            uiMode |= mNightMode << 4;
        }

        // Override night mode in power save mode if not transient night mode or not in car mode
        boolean shouldOverrideNight = !mCarModeEnabled || !shouldTransientNightWhenInCarMode();
        if (mPowerSave && shouldOverrideNight) {
        // Override night mode in power save mode if not in car mode
        if (mPowerSave && !mCarModeEnabled) {
            uiMode &= ~Configuration.UI_MODE_NIGHT_NO;
            uiMode |= Configuration.UI_MODE_NIGHT_YES;
        }