Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
1.添加更为友好的提示
Browse files Browse the repository at this point in the history
2.减少切换lte only的时间(之前10s现在8s)
3.优化代码结构
  • Loading branch information
jrsen committed Sep 7, 2016
1 parent 77e234d commit b16bbf7
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 152 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/libraries/animated_vector_drawable_23_4_0.xml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/libraries/appcompat_v7_23_4_0.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/libraries/support_annotations_23_4_0.xml

This file was deleted.

16 changes: 0 additions & 16 deletions .idea/libraries/support_v4_23_4_0.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/libraries/support_vector_drawable_23_4_0.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name=".DaemonService" />
</application>

</manifest>
111 changes: 111 additions & 0 deletions app/src/main/java/com/jrsen/lte/DaemonService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.jrsen.lte;

import android.app.Notification;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.IBinder;
import android.widget.Toast;

import com.jrsen.ltepatch.LteDaemon;

import java.io.File;
import java.io.OutputStream;
import java.util.StringTokenizer;

/**
* Created by jrsen on 16-9-7.
*/
public final class DaemonService extends Service {

@Override
public void onCreate() {
if (isRooted()) {
tryAutoSetPreferredNetwork();
} else {
tryManualSetPreferredNetwork();
Toast.makeText(this, "没有su权限,请手动切换到lte网络.", Toast.LENGTH_LONG).show();
stopSelf();
}
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

private void tryManualSetPreferredNetwork() {
try {
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.RadioInfo");
intent.setComponent(componentName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (Exception ignore) {
}
}

private void tryAutoSetPreferredNetwork() {
new AsyncTask<Void, Void, Integer>() {

@Override
protected void onPreExecute() {
startForeground(1, new Notification());
Toast.makeText(DaemonService.this, "正在检测是否支持lte网络...", Toast.LENGTH_LONG).show();
}

@Override
protected Integer doInBackground(Void... params) {
try {
final String[] COMMANDS = {
"export CLASSPATH=" + getPackageCodePath(),
"app_process /system/bin " + LteDaemon.class.getName()
};
Runtime runtime = Runtime.getRuntime();
Process su = runtime.exec("su");
OutputStream os = su.getOutputStream();
for (String command : COMMANDS) {
os.write((command + "\n").getBytes());
}
os.flush();
os.close();
return su.waitFor();
} catch (Exception ignore) {
}
return LteDaemon.ERROR_UNKNOW;
}

@Override
protected void onPostExecute(Integer result) {
if (result == 0) {
Toast.makeText(DaemonService.this, "已成功切换到lte网络!", Toast.LENGTH_LONG).show();
} else if (result == LteDaemon.ERROR_UNKNOW) {
tryManualSetPreferredNetwork();
Toast.makeText(DaemonService.this, "自动切换失败,请手动切换到lte网络。", Toast.LENGTH_LONG).show();
} else if (result == LteDaemon.ERROR_NO_LTE) {
tryManualSetPreferredNetwork();
Toast.makeText(DaemonService.this, "目前位置可能不支持lte网络,请尝试手动切换到lte网络。", Toast.LENGTH_LONG).show();
}
stopForeground(true);
stopSelf();
}
}.execute();
}

public static boolean isRooted() {
String path = System.getenv("PATH");//获取环境变量,eg:/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/vendor/bin
if (path == null) {
return false;
}
StringTokenizer stok = new StringTokenizer(path, ":");
while (stok.hasMoreTokens()) {
File su = new File(stok.nextToken(), "su");
if (su.exists()) {
return true;
}
}
return false;
}

}
53 changes: 2 additions & 51 deletions app/src/main/java/com/jrsen/lte/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,16 @@


import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.jrsen.ltepatch.LteDaemon;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class SettingsActivity extends Activity {
public final class SettingsActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isRooted()) {
try {
final String[] COMMANDS = {
"export CLASSPATH=" + getPackageCodePath(),
"app_process /system/bin " + LteDaemon.class.getName()
};
Runtime runtime = Runtime.getRuntime();
Process su = runtime.exec("su");
OutputStream os = su.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
for (String command : COMMANDS) {
bw.write(command + "\n");
bw.flush();
}
bw.close();
} catch (IOException ignore) {
}
Toast.makeText(this, "自动切换到lte网络", Toast.LENGTH_LONG).show();
} else {
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.RadioInfo");
intent.setComponent(componentName);
startActivity(intent);
Toast.makeText(this, "手动切换到lte网络", Toast.LENGTH_LONG).show();
}
startService(new Intent(this, DaemonService.class));
finish();
}

public static boolean isRooted() {
String path = System.getenv("PATH");//获取环境变量,eg:/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/vendor/bin
if (path == null) {
return false;
}
StringTokenizer stok = new StringTokenizer(path, ":");
while (stok.hasMoreTokens()) {
File su = new File(stok.nextToken(), "su");
if (su.exists()) {
return true;
}
}
return false;
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri Jun 24 14:16:05 CST 2016
#Wed Sep 07 15:04:20 CST 2016
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.http.proxyPort=8118
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Wed Sep 07 15:14:51 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
1 change: 0 additions & 1 deletion ltepatch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':reflect-lib')
}
2 changes: 2 additions & 0 deletions ltepatch/src/main/java/com/jrsen/ltepatch/ITelephony_L.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public final class ITelephony_L {
@ClassParams({int.class})
public static Method<Boolean> setPreferredNetworkType;

public static Method<Integer> getNetworkType;

static {
Reflection.init("com.android.internal.telephony.ITelephony", ITelephony_L.class);
}
Expand Down
Loading

0 comments on commit b16bbf7

Please sign in to comment.