This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.减少切换lte only的时间(之前10s现在8s) 3.优化代码结构
- Loading branch information
jrsen
committed
Sep 7, 2016
1 parent
77e234d
commit b16bbf7
Showing
16 changed files
with
148 additions
and
152 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.