├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── scopes │ └── scope_settings.xml ├── vcs.xml └── workspace.xml ├── app ├── build.gradle ├── libs │ └── XposedBridgeApi.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── xposed_init │ ├── java │ └── net │ │ └── typeblog │ │ └── netlock │ │ ├── mod │ │ └── ModNetLock.java │ │ └── ui │ │ └── MainActivity.java │ └── res │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── main.xml │ └── values │ └── strings.xml ├── build.gradle ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | gen/ 3 | obj/ 4 | libs/*/*.so 5 | .gradle 6 | build 7 | *.iml 8 | signing.properties 9 | 10 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | My Application -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 150 | 174 | 556 | 561 | 812 | 813 | 814 | 821 | 822 | 823 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 863 | 864 | 865 | 866 | 869 | 870 | 873 | 874 | 875 | 876 | 879 | 880 | 883 | 884 | 887 | 888 | 889 | 890 | 893 | 894 | 897 | 898 | 901 | 902 | 905 | 906 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 933 | 934 | 935 | 946 | 947 | 948 | 966 | 973 | 974 | 987 | 988 | 989 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1027 | 1028 | 1029 | 1049 | 1050 | 1051 | 1052 | 1053 | 1055 | 1056 | localhost 1057 | 5050 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1404820975431 1065 | 1404820975431 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1108 | 1111 | 1112 | 1113 | 1115 | 1116 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "21.1.2" 6 | 7 | defaultConfig { 8 | applicationId "net.typeblog.netlock" 9 | minSdkVersion 21 10 | targetSdkVersion 21 11 | versionCode 2 12 | versionName "1.1" 13 | } 14 | 15 | signingConfigs { 16 | release 17 | } 18 | 19 | buildTypes { 20 | release { 21 | signingConfig signingConfigs.release 22 | //runProguard false 23 | //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | provided files("libs/XposedBridgeApi.jar") 30 | } 31 | 32 | def propFile = file('../signing.properties') 33 | if( propFile.canRead() ) { 34 | def Properties p = new Properties() 35 | p.load(new FileInputStream(propFile)) 36 | 37 | if( p!=null 38 | && p.containsKey('STORE_FILE') 39 | && p.containsKey('STORE_PASSWORD') 40 | && p.containsKey('KEY_ALIAS') 41 | && p.containsKey('KEY_PASSWORD') 42 | ) { 43 | println "RELEASE_BUILD: Signing..." 44 | 45 | android.signingConfigs.release.storeFile = file( p['STORE_FILE'] ) 46 | android.signingConfigs.release.storePassword = p['STORE_PASSWORD'] 47 | android.signingConfigs.release.keyAlias = p['KEY_ALIAS'] 48 | android.signingConfigs.release.keyPassword = p['KEY_PASSWORD'] 49 | 50 | } else { 51 | println "RELEASE_BUILD: Required properties in signing.properties are missing" 52 | android.buildTypes.release.signingConfig = null 53 | } 54 | 55 | } else { 56 | println "RELEASE_BUILD: signing.properties not found" 57 | android.buildTypes.release.signingConfig = null 58 | } 59 | -------------------------------------------------------------------------------- /app/libs/XposedBridgeApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterCxy/LockNetworkType/46d1849e230ab94260ae138ace15c27c2ba951aa/app/libs/XposedBridgeApi.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 12 | 15 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/assets/xposed_init: -------------------------------------------------------------------------------- 1 | net.typeblog.netlock.mod.ModNetLock 2 | -------------------------------------------------------------------------------- /app/src/main/java/net/typeblog/netlock/mod/ModNetLock.java: -------------------------------------------------------------------------------- 1 | package net.typeblog.netlock.mod; 2 | 3 | import android.os.Message; 4 | 5 | import de.robv.android.xposed.IXposedHookLoadPackage; 6 | import de.robv.android.xposed.IXposedHookZygoteInit; 7 | import de.robv.android.xposed.XposedBridge; 8 | import de.robv.android.xposed.XposedHelpers; 9 | import de.robv.android.xposed.XC_MethodHook; 10 | import de.robv.android.xposed.XSharedPreferences; 11 | import de.robv.android.xposed.callbacks.XC_LoadPackage; 12 | 13 | import static net.typeblog.netlock.BuildConfig.DEBUG; 14 | 15 | public class ModNetLock implements IXposedHookZygoteInit 16 | { 17 | 18 | private static final String TAG = ModNetLock.class.getSimpleName() + ":"; 19 | 20 | public static final String PREF_XML = "network"; 21 | public static final String PREF_NAME = "lock"; 22 | 23 | private XSharedPreferences mPref; 24 | 25 | @Override 26 | public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable { 27 | // Create preference first 28 | mPref = new XSharedPreferences("net.typeblog.netlock", PREF_XML); 29 | mPref.makeWorldReadable(); 30 | 31 | Class RIL = XposedHelpers.findClass("com.android.internal.telephony.RIL", null); 32 | if (RIL == null) { 33 | if (DEBUG) XposedBridge.log(TAG + "cannot get RIL class"); 34 | return; 35 | } 36 | 37 | XposedBridge.hookAllConstructors(RIL, new XC_MethodHook() { 38 | @Override 39 | protected void beforeHookedMethod(XC_MethodHook.MethodHookParam mhparams) throws Throwable { 40 | if (DEBUG) XposedBridge.log(TAG + "RIL Instance created"); 41 | mPref.reload(); 42 | mhparams.args[1] = mPref.getInt(PREF_NAME, 0); 43 | } 44 | }); 45 | 46 | XposedHelpers.findAndHookMethod(RIL, "setPreferredNetworkType", int.class, Message.class, new XC_MethodHook() { 47 | @Override 48 | protected void beforeHookedMethod(XC_MethodHook.MethodHookParam mhparams) throws Throwable { 49 | 50 | if (DEBUG) XposedBridge.log(TAG + "setPreferredNetworkType called."); 51 | 52 | mPref.reload(); 53 | mhparams.args[0] = mPref.getInt(PREF_NAME, 0); 54 | } 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/net/typeblog/netlock/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package net.typeblog.netlock.ui; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.AdapterView; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.Button; 11 | import android.widget.Spinner; 12 | import android.widget.Toast; 13 | 14 | import net.typeblog.netlock.R; 15 | import net.typeblog.netlock.mod.ModNetLock; 16 | 17 | public class MainActivity extends Activity implements View.OnClickListener { 18 | private Spinner mNetworks; 19 | private ArrayAdapter mAdapter; 20 | private SharedPreferences mPref; 21 | private Button mLock; 22 | 23 | @Override 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.main); 27 | 28 | mPref = getSharedPreferences(ModNetLock.PREF_XML, Context.MODE_WORLD_READABLE); 29 | 30 | mNetworks = (Spinner) findViewById(R.id.main_spinner); 31 | mAdapter = ArrayAdapter.createFromResource(this, R.array.networks, android.R.layout.simple_spinner_item); 32 | mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 33 | mNetworks.setAdapter(mAdapter); 34 | 35 | mLock = (Button) findViewById(R.id.main_lock); 36 | 37 | mNetworks.post(new Runnable() { 38 | @Override 39 | public void run() { 40 | mNetworks.setSelection(mPref.getInt(ModNetLock.PREF_NAME, 0)); 41 | mLock.setOnClickListener(MainActivity.this); 42 | } 43 | }); 44 | } 45 | 46 | @Override 47 | public void onClick(View v) { 48 | if (v != mLock) throw new RuntimeException("WHAT???"); 49 | 50 | mPref.edit().putInt(ModNetLock.PREF_NAME, mNetworks.getSelectedItemPosition()).commit(); 51 | Toast.makeText(this, R.string.tip, Toast.LENGTH_SHORT).show(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterCxy/LockNetworkType/46d1849e230ab94260ae138ace15c27c2ba951aa/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 12 | 13 |