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

Commit 17026864 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Ensure Binder in-calls to UiModeManagerService are guarded." into jb-mr1-dev

parents 46fb9e9f 487bb6e2
Loading
Loading
Loading
Loading
+146 −129
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ import com.android.internal.R;
import com.android.internal.app.DisableCarModeActivity;
import com.android.server.TwilightService.TwilightState;

class UiModeManagerService extends IUiModeManager.Stub {
final class UiModeManagerService extends IUiModeManager.Stub {
    private static final String TAG = UiModeManager.class.getSimpleName();
    private static final boolean LOG = false;

@@ -186,32 +186,50 @@ class UiModeManagerService extends IUiModeManager.Stub {
        mTwilightService.registerListener(mTwilightListener, mHandler);
    }

    @Override // Binder call
    public void disableCarMode(int flags) {
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
                setCarModeLocked(false);
                if (mSystemReady) {
                    updateLocked(0, flags);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override // Binder call
    public void enableCarMode(int flags) {
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
                setCarModeLocked(true);
                if (mSystemReady) {
                    updateLocked(flags, 0);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override // Binder call
    public int getCurrentModeType() {
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
                return mCurUiMode & Configuration.UI_MODE_TYPE_MASK;
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    public void setNightMode(int mode) throws RemoteException {
        synchronized (mLock) {
    @Override // Binder call
    public void setNightMode(int mode) {
        switch (mode) {
            case UiModeManager.MODE_NIGHT_NO:
            case UiModeManager.MODE_NIGHT_YES:
@@ -220,24 +238,28 @@ class UiModeManagerService extends IUiModeManager.Stub {
            default:
                throw new IllegalArgumentException("Unknown mode: " + mode);
        }
            if (!isDoingNightMode()) {
                return;
            }

            if (mNightMode != mode) {
                long ident = Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
                if (isDoingNightModeLocked() && mNightMode != mode) {
                    Settings.Secure.putInt(mContext.getContentResolver(),
                            Settings.Secure.UI_NIGHT_MODE, mode);
                Binder.restoreCallingIdentity(ident);
                    mNightMode = mode;
                    updateLocked(0, 0);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    public int getNightMode() throws RemoteException {
    @Override // Binder call
    public int getNightMode() {
        synchronized (mLock) {
            return mNightMode;
        }
    }

    void systemReady() {
        synchronized (mLock) {
@@ -248,17 +270,17 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    boolean isDoingNightMode() {
    private boolean isDoingNightModeLocked() {
        return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
    }

    void setCarModeLocked(boolean enabled) {
    private void setCarModeLocked(boolean enabled) {
        if (mCarModeEnabled != enabled) {
            mCarModeEnabled = enabled;
        }
    }

    void updateDockState(int newState) {
    private void updateDockState(int newState) {
        synchronized (mLock) {
            if (newState != mDockState) {
                mDockState = newState;
@@ -270,7 +292,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    final static boolean isDeskDockState(int state) {
    private static boolean isDeskDockState(int state) {
        switch (state) {
            case Intent.EXTRA_DOCK_STATE_DESK:
            case Intent.EXTRA_DOCK_STATE_LE_DESK:
@@ -281,7 +303,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    final void updateConfigurationLocked() {
    private void updateConfigurationLocked() {
        int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType;
        if (mCarModeEnabled) {
            uiMode = Configuration.UI_MODE_TYPE_CAR;
@@ -315,7 +337,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    final void sendConfigurationLocked() {
    private void sendConfigurationLocked() {
        if (mSetUiMode != mConfiguration.uiMode) {
            mSetUiMode = mConfiguration.uiMode;

@@ -327,10 +349,7 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    final void updateLocked(int enableFlags, int disableFlags) {
        long ident = Binder.clearCallingIdentity();

        try {
    private void updateLocked(int enableFlags, int disableFlags) {
        String action = null;
        String oldAction = null;
        if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
@@ -424,9 +443,6 @@ class UiModeManagerService extends IUiModeManager.Stub {
                mWakeLock.release();
            }
        }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private void updateAfterBroadcastLocked(String action, int enableFlags, int disableFlags) {
@@ -500,7 +516,7 @@ class UiModeManagerService extends IUiModeManager.Stub {

        // If we did not start a dock app, then start dreaming if supported.
        if (category != null && !dockAppStarted
                && isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) {
                && isScreenSaverEnabledLocked() && isScreenSaverActivatedOnDockLocked()) {
            Slog.i(TAG, "Activating dream while docked.");
            try {
                IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
@@ -522,13 +538,13 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }
    }

    private boolean isScreenSaverEnabled() {
    private boolean isScreenSaverEnabledLocked() {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREENSAVER_ENABLED, DEFAULT_SCREENSAVER_ENABLED,
                UserHandle.USER_CURRENT) != 0;
    }

    private boolean isScreenSaverActivatedOnDock() {
    private boolean isScreenSaverActivatedOnDockLocked() {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
                DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK, UserHandle.USER_CURRENT) != 0;
@@ -536,7 +552,8 @@ class UiModeManagerService extends IUiModeManager.Stub {

    private void adjustStatusBarCarModeLocked() {
        if (mStatusBarManager == null) {
            mStatusBarManager = (StatusBarManager) mContext.getSystemService(Context.STATUS_BAR_SERVICE);
            mStatusBarManager = (StatusBarManager)
                    mContext.getSystemService(Context.STATUS_BAR_SERVICE);
        }

        // Fear not: StatusBarManagerService manages a list of requests to disable
@@ -581,7 +598,7 @@ class UiModeManagerService extends IUiModeManager.Stub {

    private void updateTwilight() {
        synchronized (mLock) {
            if (isDoingNightMode() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
            if (isDoingNightModeLocked() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
                updateComputedNightModeLocked();
                updateLocked(0, 0);
            }