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

Commit 53332883 authored by Tobias Haamel's avatar Tobias Haamel
Browse files

Manager for controlling the UI modes.

The ui modes can be controlled with the UiModeManager class, which
is can be retrieved as a system service via getSytemService(Context.UIMODE_SERVICE).

The class is necessary so that CarHome can be unbundled and other apps can
disable the car mode. Its currently a hidden class, since I'm not sure if this
is the best way to provide this functionality to the user.
parent 7e31e0c3
Loading
Loading
Loading
Loading
+88 −0
Original line number Diff line number Diff line
@@ -26277,6 +26277,83 @@
</parameter>
</method>
</interface>
<class name="UiModeManager"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="disableCarMode"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getNightMode"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="setNightMode"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="mode" type="int">
</parameter>
</method>
<field name="MODE_AUTO"
 type="int"
 transient="false"
 volatile="false"
 value="3"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="MODE_NIGHT"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="MODE_NOTNIGHT"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="WallpaperInfo"
 extends="java.lang.Object"
 abstract="false"
@@ -34549,6 +34626,17 @@
 visibility="public"
>
</field>
<field name="UIMODE_SERVICE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;uimode&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="VIBRATOR_SERVICE"
 type="java.lang.String"
 transient="false"
+12 −0
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ class ContextImpl extends Context {
    private AccountManager mAccountManager; // protected by mSync
    private DropBoxManager mDropBoxManager = null;
    private DevicePolicyManager mDevicePolicyManager = null;
    private UiModeManager mUiModeManager = null;

    private final Object mSync = new Object();

@@ -960,6 +961,8 @@ class ContextImpl extends Context {
            return getDropBoxManager();
        } else if (DEVICE_POLICY_SERVICE.equals(name)) {
            return getDevicePolicyManager();
        } else if (UIMODE_SERVICE.equals(name)) {
            return getUiModeManager();
        }

        return null;
@@ -1153,6 +1156,15 @@ class ContextImpl extends Context {
        return mDevicePolicyManager;
    }

    private UiModeManager getUiModeManager() {
        synchronized (mSync) {
            if (mUiModeManager == null) {
                mUiModeManager = new UiModeManager();
            }
        }
        return mUiModeManager;
    }

    @Override
    public int checkPermission(String permission, int pid, int uid) {
        if (permission == null) {
+83 −0
Original line number Diff line number Diff line
package android.app;

import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

/**
 * This class provides access to the system uimode services.  These services
 * allow applications to control UI modes of the device.
 * It provides functionality to disable the car mode and it gives access to the
 * night mode settings.
 *
 * <p>You do not instantiate this class directly; instead, retrieve it through
 * {@link android.content.Context#getSystemService
 * Context.getSystemService(Context.UIMODE_SERVICE)}.
 */
public class UiModeManager {
    private static final String TAG = "UiModeManager";

    public static final int MODE_NOTNIGHT = 1;
    public static final int MODE_NIGHT = 2;
    public static final int MODE_AUTO = 3;

    private IUiModeManager mService;

    /*package*/ UiModeManager() {
        mService = IUiModeManager.Stub.asInterface(
                ServiceManager.getService("uimode"));
    }

    /**
     * Disables the car mode.
     */
    public void disableCarMode() {
        if (mService != null) {
            try {
                mService.disableCarMode();
            } catch (RemoteException e) {
                Log.e(TAG, "disableCarMode: RemoteException", e);
            }
        }
    }

    /**
     * Sets the night mode.  Changes to the night mode are only effective when
     * the car mode is enabled on a device.
     *
     * <p>The mode can be one of:
     * <ul>
     *   <li><em>{@link #MODE_NOTNIGHT}<em> - sets the device into notnight
     *       mode.</li>
     *   <li><em>{@link #MODE_NIGHT}</em> - sets the device into night mode.
     *   </li>
     *   <li><em>{@link #MODE_AUTO}</em> - automatic night/notnight switching
     *       depending on the location and certain other sensors.</li>
     */
    public void setNightMode(int mode) {
        if (mService != null) {
            try {
                mService.setNightMode(mode);
            } catch (RemoteException e) {
                Log.e(TAG, "setNightMode: RemoteException", e);
            }
        }
    }

    /**
     * Returns the currently configured night mode.
     *
     * @return {@link #MODE_NOTNIGHT}, {@link #MODE_NIGHT} or {@link #MODE_AUTO}
     *         When an error occurred -1 is returned.
     */
    public int getNightMode() {
        if (mService != null) {
            try {
                return mService.getNightMode();
            } catch (RemoteException e) {
                Log.e(TAG, "getNightMode: RemoteException", e);
            }
        }
        return -1;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -1204,6 +1204,8 @@ public abstract class Context {
     * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
     * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
     * for management of input methods.
     * <dt> {@link #UI_MODE_SERVICE} ("uimode")
     * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
     * </dl>
     * 
     * <p>Note:  System services obtained via this API may be closely associated with
@@ -1249,6 +1251,8 @@ public abstract class Context {
     * @see android.telephony.TelephonyManager
     * @see #INPUT_METHOD_SERVICE
     * @see android.view.inputmethod.InputMethodManager
     * @see #UI_MODE_SERVICE
     * @see android.app.UiModeManager
     */
    public abstract Object getSystemService(String name);

@@ -1510,6 +1514,14 @@ public abstract class Context {
     */
    public static final String DEVICE_POLICY_SERVICE = "device_policy";

    /**
     * Use with {@link #getSystemService} to retrieve a
     * {@link android.app.UiModeManager} for controlling UI modes.
     *
     * @see #getSystemService
     */
    public static final String UI_MODE_SERVICE = "uimode";

    /**
     * Determine whether the given permission is allowed for a particular
     * process and user ID running in the system.