[MOD][Xposed] Disable Desk Dock

Search This thread

MohammadAG

Inactive Recognized Developer
Sep 7, 2009
1,080
5,504
28
Jerusalem
mohammadag.xceleo.org
Requires Xposed Framework!

This module disables the desk dock feature on your device.
If anyone's wondering how this is useful, I made it for my Xperia Z1's magnetic cable, Sony sells the cable in a dock, so using the cable by itself puts the device in dock mode, which forces rotation regardless of my choice, and if the cable disconnects while my device is in car mode, it switches off car mode, which is kind of annoying while driving.

Compatibility:
Tested on my Z1, I coded it with 4.2 in mind, may or may not work on 4.1 / 4.3, trying it won't do any harm.

Source:
The mod is open source: https://github.com/MohammadAG/Xposed-Disable-Desk-Dock
You may not publish this on the Play Store or any other market.

Download:
http://dl-count.xposed.info/modules/com.mohammadag.disabledeskdock_v1_8f4e5c.apk

Changelog:
[1.0]
  • Initial release.

Support development:
If you found this mod useful, consider donating with PayPal.
 

tobbbie

Senior Member
Jan 5, 2007
1,452
252
Stuttgart
This finally solved the annoying problem with my GT-P3110 (Galaxy Tab 2 7") with Go Launcher (pro). I use Go Launcher also on my tablet to stay consistent with my Xperia Ray - where it works flawlessly. On the GT-P3110 I have to adjust the environment with "App Settings" to be DPI 240 and font-size = 99% and then Go Launcher can be used perfectly for my taste.

The problem with Go Launcher and the GT-P3110 was that Go Launcher restarted every time I have set the tablet in the original dock or when I put it out of it. So any transition from or to desk-dock mode gave me a break until Go Launcher has reloaded all apps :(
Reporting the problem to Go Development team (twice actually) has not revealed a solution over months - but your module did it - thanks!
 

HeavyMoertel

Senior Member
Jul 6, 2013
50
21
Exactly what I've been looking for!
I ran into the problem of some apps closing down due to dock mode, but this seems to be not a problem anymore.
 

jfriend33

Senior Member
Oct 7, 2010
1,532
149
Illinois
Tried this on my droid maxx xt1080m. It's still bringing up car dock.

My issue is walking around with my phone stacked on top of my tablet in my hand. I guess I could freeze car mode. Any ideas?
 

xltb

New member
Mar 4, 2013
1
0
Well this made my day thanks! working for me on omnirom 4.4.4 xperia z c6603
 

dawaldi

New member
Feb 3, 2013
3
2
Berlin
finally the solution. everytime i dock the S4, the currently running app closes and needs to be started again. CM11 btw.
 

eresac

Senior Member
Jan 24, 2009
197
21
Full Uninstall help

I know by myself it's kind of a stange question but, since I'm facing a very courious issue, I'm here to ask if there's any suggetion on how to full disble and remove this module.
I have the phone going into a sort of bootloop when swithced off (only way to recover is "power + vol up" long press combo).
And this is one of the last modifications I made, plus this happens only when I connect the magnetic cable.
Thank you all for your support.
 

bballer182

Senior Member
Feb 15, 2011
246
68
Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.
 
Last edited:

mw2fan

Senior Member
Apr 1, 2014
52
5
bballer182
Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.

bballer182
I have the same issue. I really hope MohammadAG can find a solution for us.
 
Last edited:

attachsnow

Senior Member
Feb 1, 2008
84
13
Taipei
jim.youler.com
Working for me on Android 4.4.4 stock rom Xperia Z3.
and not working on Android 5.0.2 CM rom.
Is there any solution on Android LL (5.0.2)?
It's very useful tool but it can't run on Lollipop.
Thank you.
 

jassalmithu

Senior Member
Apr 13, 2009
196
35
The developer doesn't look active on XDA anymore since february. Maybe another developer can look at source and adapt it to lollipop.
 

NickKarpow

Member
Apr 21, 2015
6
35
My DisableDock.java:

Code:
package com.mohammadag.disabledeskdock;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getIntField;
import static de.robv.android.xposed.XposedHelpers.setIntField;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import android.content.IntentFilter;
import android.content.res.Configuration;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;


public class DisableDock implements IXposedHookLoadPackage {

    private UiModeManager mUiModeManager = null;
    private boolean mIsInCarMode = false;

    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("android"))
            return;

        findAndHookMethod("com.android.server.UiModeManagerService", lpparam.classLoader,
                "isDeskDockState", int.class, XC_MethodReplacement.returnConstant(false));

        Class<?> DockObserver = findClass("com.android.server.DockObserver", lpparam.classLoader);

        XposedBridge.hookAllConstructors(DockObserver, new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
                mUiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);

                IntentFilter iF = new IntentFilter();
                iF.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
                iF.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);

                context.registerReceiver(new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(intent.getAction())) {
                            mIsInCarMode = true;
                        } else if (UiModeManager.ACTION_EXIT_CAR_MODE.equals(intent.getAction())) {
                            mIsInCarMode = false;
                        }
                    }
                }, iF);
            }
        });

        findAndHookMethod(DockObserver, "handleDockStateChange", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                int mActualDockState = getIntField(param.thisObject, "mActualDockState");
                int mReportedDockState = getIntField(param.thisObject, "mReportedDockState");
                int mPreviousDockState = getIntField(param.thisObject, "mPreviousDockState");

                int newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
                switch (mActualDockState) {
                    case Intent.EXTRA_DOCK_STATE_DESK:
                    case Intent.EXTRA_DOCK_STATE_HE_DESK:
                    case Intent.EXTRA_DOCK_STATE_LE_DESK:
                    default:
                        newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
                        break;
                    case Intent.EXTRA_DOCK_STATE_CAR:
                        newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
                        break;
                }
                if (mUiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR || mIsInCarMode) {
                    newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
                    setIntField(param.thisObject, "mActualDockState", newFakeState);
                    // Prevent sound playback
                    param.setResult(null);
                }


				String debugString = String.format("Act: %s Prv: %s Rep: %s Fak: %s Car: %s",
						getStringFromDockState(mActualDockState), getStringFromDockState(mPreviousDockState),getStringFromDockState(mReportedDockState),
						getStringFromDockState(newFakeState), String.valueOf(mIsInCarMode));

			//	Toast.makeText( context, debugString, Toast.LENGTH_LONG).show();
                XposedBridge.log(debugString);

                setIntField(param.thisObject, "mActualDockState", newFakeState);
                setIntField(param.thisObject, "mReportedDockState", newFakeState);
            }
        });


    }

    private static String getStringFromDockState(int dockState) {
        switch (dockState) {
            case Intent.EXTRA_DOCK_STATE_DESK:
                return "Intent.EXTRA_DOCK_STATE_DESK";
            case Intent.EXTRA_DOCK_STATE_HE_DESK:
                return "Intent.EXTRA_DOCK_STATE_HE_DESK";
            case Intent.EXTRA_DOCK_STATE_LE_DESK:
                return "Intent.EXTRA_DOCK_STATE_LE_DESK";
            case Intent.EXTRA_DOCK_STATE_CAR:
                return "Intent.EXTRA_DOCK_STATE_CAR";
            case Intent.EXTRA_DOCK_STATE_UNDOCKED:
            default:
                return "Intent.EXTRA_DOCK_STATE_UNDOCKED";
        }
    }
}
 

Top Liked Posts

  • There are no posts matching your filters.
  • 19
    I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
    11
    Requires Xposed Framework!

    This module disables the desk dock feature on your device.
    If anyone's wondering how this is useful, I made it for my Xperia Z1's magnetic cable, Sony sells the cable in a dock, so using the cable by itself puts the device in dock mode, which forces rotation regardless of my choice, and if the cable disconnects while my device is in car mode, it switches off car mode, which is kind of annoying while driving.

    Compatibility:
    Tested on my Z1, I coded it with 4.2 in mind, may or may not work on 4.1 / 4.3, trying it won't do any harm.

    Source:
    The mod is open source: https://github.com/MohammadAG/Xposed-Disable-Desk-Dock
    You may not publish this on the Play Store or any other market.

    Download:
    http://dl-count.xposed.info/modules/com.mohammadag.disabledeskdock_v1_8f4e5c.apk

    Changelog:
    [1.0]
    • Initial release.

    Support development:
    If you found this mod useful, consider donating with PayPal.
    9
    hey nick,

    can you maybe compile the same for sdk23 android 6.0?

    Thanks a lot
    Try this. I have no 6.0 devices for testing.
    5
    I got an 5.1.1 upgrade and my APK works fine without recompiling with SDK22
    I use xposed-v74-sdk22-arm.zip and XposedInstaller_3.0_alpha4.apk
    If my APKdoes not work for you, give me xposed log, I'll try to help ...
    2
    My DisableDock.java:

    Code:
    package com.mohammadag.disabledeskdock;
    
    import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
    import static de.robv.android.xposed.XposedHelpers.findClass;
    import static de.robv.android.xposed.XposedHelpers.getIntField;
    import static de.robv.android.xposed.XposedHelpers.setIntField;
    import android.app.UiModeManager;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    import android.content.IntentFilter;
    import android.content.res.Configuration;
    
    import de.robv.android.xposed.IXposedHookLoadPackage;
    import de.robv.android.xposed.IXposedHookZygoteInit;
    import de.robv.android.xposed.XC_MethodHook;
    import de.robv.android.xposed.XC_MethodReplacement;
    import de.robv.android.xposed.XposedBridge;
    import de.robv.android.xposed.XposedHelpers;
    import de.robv.android.xposed.callbacks.XC_LoadPackage;
    
    
    public class DisableDock implements IXposedHookLoadPackage {
    
        private UiModeManager mUiModeManager = null;
        private boolean mIsInCarMode = false;
    
        public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
            if (!lpparam.packageName.equals("android"))
                return;
    
            findAndHookMethod("com.android.server.UiModeManagerService", lpparam.classLoader,
                    "isDeskDockState", int.class, XC_MethodReplacement.returnConstant(false));
    
            Class<?> DockObserver = findClass("com.android.server.DockObserver", lpparam.classLoader);
    
            XposedBridge.hookAllConstructors(DockObserver, new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
                    mUiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    
                    IntentFilter iF = new IntentFilter();
                    iF.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
                    iF.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
    
                    context.registerReceiver(new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(intent.getAction())) {
                                mIsInCarMode = true;
                            } else if (UiModeManager.ACTION_EXIT_CAR_MODE.equals(intent.getAction())) {
                                mIsInCarMode = false;
                            }
                        }
                    }, iF);
                }
            });
    
            findAndHookMethod(DockObserver, "handleDockStateChange", new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    int mActualDockState = getIntField(param.thisObject, "mActualDockState");
                    int mReportedDockState = getIntField(param.thisObject, "mReportedDockState");
                    int mPreviousDockState = getIntField(param.thisObject, "mPreviousDockState");
    
                    int newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
                    switch (mActualDockState) {
                        case Intent.EXTRA_DOCK_STATE_DESK:
                        case Intent.EXTRA_DOCK_STATE_HE_DESK:
                        case Intent.EXTRA_DOCK_STATE_LE_DESK:
                        default:
                            newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
                            break;
                        case Intent.EXTRA_DOCK_STATE_CAR:
                            newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
                            break;
                    }
                    if (mUiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR || mIsInCarMode) {
                        newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
                        setIntField(param.thisObject, "mActualDockState", newFakeState);
                        // Prevent sound playback
                        param.setResult(null);
                    }
    
    
    				String debugString = String.format("Act: %s Prv: %s Rep: %s Fak: %s Car: %s",
    						getStringFromDockState(mActualDockState), getStringFromDockState(mPreviousDockState),getStringFromDockState(mReportedDockState),
    						getStringFromDockState(newFakeState), String.valueOf(mIsInCarMode));
    
    			//	Toast.makeText( context, debugString, Toast.LENGTH_LONG).show();
                    XposedBridge.log(debugString);
    
                    setIntField(param.thisObject, "mActualDockState", newFakeState);
                    setIntField(param.thisObject, "mReportedDockState", newFakeState);
                }
            });
    
    
        }
    
        private static String getStringFromDockState(int dockState) {
            switch (dockState) {
                case Intent.EXTRA_DOCK_STATE_DESK:
                    return "Intent.EXTRA_DOCK_STATE_DESK";
                case Intent.EXTRA_DOCK_STATE_HE_DESK:
                    return "Intent.EXTRA_DOCK_STATE_HE_DESK";
                case Intent.EXTRA_DOCK_STATE_LE_DESK:
                    return "Intent.EXTRA_DOCK_STATE_LE_DESK";
                case Intent.EXTRA_DOCK_STATE_CAR:
                    return "Intent.EXTRA_DOCK_STATE_CAR";
                case Intent.EXTRA_DOCK_STATE_UNDOCKED:
                default:
                    return "Intent.EXTRA_DOCK_STATE_UNDOCKED";
            }
        }
    }