-1

I want to know if there is a way to fake network connection as disconnected or disabled on selected apps. As there are Xposed modules like "Fake Wifi Connection" is working, I believe this should be possible.

Thank you.

  • okay, please tell me if I'm being impolite or something not good before downvoting. So I know where I should not be asking. – Khamim Noise Jan 07 '17 at 04:17

1 Answers1

0

Usually we check network is connected or not by using something like this

        ConnectivityManager connectivityManager
                = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();

So you can hook method isConnectedOrConnectiong() of NetworkInfo class using Xposed and return true from it.

        XposedHelpers.findAndHookMethod(NetworkInfo.class, loadPackageParam.classLoader, "isConnectedOrConnecting", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
                param.setResult(false);

            }
        });

param.setResult(false) skips the call to the original method and returns false as a result of the call ( which is never made )

I hope this helps.

Edit: from the android docs

getActiveNetworkInfo Added in API level 1

NetworkInfo getActiveNetworkInfo ()

Returns details about the currently active default data network. When connected, this network is the default route for outgoing connections. You should always check isConnected() before initiating network traffic. This may return null when there is no default network.

So the call may return null when there is no default network. This will not work in that case.

Suraj
  • 184
  • 1
  • 14
  • if it helped you please accept it as answer or tell me what else do you want so that I can improve my answer. Thank you! – Suraj Jan 16 '17 at 13:32