Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions FakeWifiConnection/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto">
<TextView android:textAppearance="?android:textAppearanceMedium" android:id="@id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select apps that should believe they're on Wifi" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" />
<ListView android:id="@id/appList" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/button1" android:layout_below="@id/masterswitch" android:layout_alignParentLeft="true" />
<Button android:id="@id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Invert" android:layout_toLeftOf="@id/button2" android:layout_toRightOf="@id/button3" android:layout_alignParentBottom="true" android:onClick="invert" />
<Button android:id="@id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:onClick="save" />
<Button android:id="@+id/scheduleChooser" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Schedule" android:layout_alignParentBottom="true"/>
<Button android:id="@id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Invert" android:layout_toLeftOf="@id/button2" android:layout_toRightOf="@id/button3" android:onClick="invert" android:layout_above="@id/scheduleChooser" />
<Button android:id="@id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save" android:layout_alignParentRight="true" android:onClick="save" android:layout_above="@id/scheduleChooser" />
<Switch android:id="@id/masterswitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="Master Switch" android:layout_below="@id/textView1" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" />
<Button android:id="@id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select All" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:onClick="selectAll" />
<Button android:id="@id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select All" android:layout_alignParentLeft="true" android:onClick="selectAll" android:layout_above="@id/scheduleChooser" />
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package com.lemonsqueeze.fakewificonnection;

import de.robv.android.xposed.*;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import de.robv.android.xposed.XposedBridge;

//import android.content.Context;
//import android.content.SharedPreferences;
import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.SupplicantState;
import android.net.DhcpInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.util.Log;
import de.robv.android.xposed.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import java.net.NetworkInterface;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.*;
import java.net.NetworkInterface;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;


public class Main implements IXposedHookLoadPackage
{
private XSharedPreferences pref;
private LoadPackageParam lpparam;
private XC_LoadPackage.LoadPackageParam lpparam;

// debug level: 0=quiet, 1=log function calls, 2=also dump stack traces.
// install 'Preferences Manager' to change default (0)
Expand All @@ -38,11 +33,38 @@ private int debug_level()
return pref.getInt("debug_level", 0);
}

private boolean isTimeWithinSchedule() {
int scheduleStartHour = pref.getInt("scheduleStartHour", -1);
int scheduleStartMinute = pref.getInt("scheduleStartHour", -1);
int scheduleStartMinuteOfDay = scheduleStartHour * 60 + scheduleStartMinute;

if (scheduleStartHour == -1) {
return true;
}

int scheduleEndHour = pref.getInt("scheduleEndHour", -1);
int scheduleEndMinute = pref.getInt("scheduleEndMinute", -1);
int scheduleEndMinuteOfDay = scheduleEndHour * 60 + scheduleEndMinute;

int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
int minuteOfDay = hour * 60 + minute;

boolean isScheduleWithinOneDay = scheduleStartMinuteOfDay <= scheduleEndMinuteOfDay;

if (isScheduleWithinOneDay) {
return scheduleStartMinuteOfDay <= minuteOfDay && minuteOfDay <= scheduleEndMinuteOfDay;
} else {
return minuteOfDay >= scheduleStartHour || minuteOfDay <= scheduleEndHour;
}
}

public boolean hack_enabled()
{
boolean master_switch = pref.getBoolean("master", true);
boolean timeWithinSchedule = isTimeWithinSchedule();
boolean app_enabled = pref.getBoolean(lpparam.packageName, false);
return (master_switch && app_enabled);
return (master_switch && app_enabled && timeWithinSchedule);
}

public void dump_stack_trace()
Expand All @@ -66,15 +88,15 @@ public void log_call(String s)
if (debug < 1)
return;

//XposedBridge.log("FakeWifiConnection: " + s);
XposedBridge.log("FakeWifiConnection: " + s);
Log.d("FakeWifiConnection", lpparam.packageName + " " + s);
//Log.d("FakeWifiConnection", s);

if (debug > 1)
dump_stack_trace();
}

public void doit_networkinfo(String called, MethodHookParam param) throws Exception
public void doit_networkinfo(String called, XC_MethodHook.MethodHookParam param) throws Exception
{
if (!hack_enabled())
{
Expand Down Expand Up @@ -106,7 +128,7 @@ private static Object[] push(Object[] array, Object item)
return longer;
}

public void doit_allnetworkinfo(String called, MethodHookParam param) throws Exception
public void doit_allnetworkinfo(String called, XC_MethodHook.MethodHookParam param) throws Exception
{
if (!hack_enabled())
{
Expand Down Expand Up @@ -304,7 +326,7 @@ private void hook_method(String className, ClassLoader classLoader, String metho
}

@Override
public void handleLoadPackage(final LoadPackageParam lpp) throws Throwable
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpp) throws Throwable
{
pref = new XSharedPreferences(Main.class.getPackage().getName(), "pref");
lpparam = lpp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,26 @@
//import android.os.*;
//import android.view.*;
//import android.util.*;
import android.widget.*;
//import android.content.*;
//import android.net.*;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//import android.content.*;
//import android.net.*;

public class MainActivity extends Activity
{
Expand All @@ -43,6 +37,7 @@ class PInfo {
SharedPreferences pref;
ListView app_list; //listview with checkboxes which will contain apps
Switch masterSwitch;
Button scheduleChooser;

ArrayList<PInfo> pinfos; //PInfo object for each app

Expand Down Expand Up @@ -130,8 +125,86 @@ public void load()

masterSwitch = (Switch) findViewById(R.id.masterswitch);
masterSwitch.setChecked(pref.getBoolean("master", true));

scheduleChooser = (Button) findViewById(R.id.scheduleChooser);
loadSchedule();
scheduleChooser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scheduleClick();
}
});

scheduleChooser.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
pref.edit()
.putInt("scheduleStartHour", -1)
.putInt("scheduleStartMinute", -1)
.putInt("scheduleEndHour", -1)
.putInt("scheduleEndMinute", -1)
.apply();
loadSchedule();
return true;
}
});
}

private int scheduleStartHour = -1;
private int scheduleStartMinute = -1;
private int scheduleEndHour = -1;
private int scheduleEndMinute = -1;

private void loadSchedule() {
scheduleStartHour = pref.getInt("scheduleStartHour", -1);
scheduleStartMinute = pref.getInt("scheduleStartMinute", -1);
scheduleEndHour = pref.getInt("scheduleEndHour", -1);
scheduleEndMinute = pref.getInt("scheduleEndMinute", -1);

if (scheduleStartHour != -1) {
scheduleChooser.setText("Scheduled from " +
scheduleStartHour + ":" + String.format("%02d", scheduleStartMinute) + " to " +
scheduleEndHour + ":" + String.format("%02d", scheduleEndMinute));
} else {
scheduleChooser.setText("Schedule");
}
}

private void scheduleClick() {
TimePickerDialog startTimePicker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
final int newStartHour = hourOfDay;
final int newStartMinute = minute;

TimePickerDialog endTimePicker = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
scheduleStartHour = newStartHour;
scheduleStartMinute = newStartMinute;
scheduleEndHour = hourOfDay;
scheduleEndMinute = minute;

pref.edit()
.putInt("scheduleStartHour", scheduleStartHour)
.putInt("scheduleStartMinute", scheduleStartMinute)
.putInt("scheduleEndHour", scheduleEndHour)
.putInt("scheduleEndMinute", scheduleEndMinute)
.apply();

Toast.makeText(MainActivity.this, "Schedule is set. Long tap the button to clear.", Toast.LENGTH_LONG).show();

loadSchedule();
}
}, scheduleEndHour != -1 ? scheduleEndHour : 0, scheduleEndMinute != -1 ? scheduleEndMinute : 0, true);
endTimePicker.setTitle("Choose end time:");
endTimePicker.show();
}
}, scheduleStartHour != -1 ? scheduleStartHour : 0, scheduleStartMinute != -1 ? scheduleStartMinute : 0, true);
startTimePicker.setTitle("Choose start time:");
startTimePicker.show();
}

//prompt to prevent quit without save
@Override
public void onBackPressed()
Expand Down