Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
majora-adr
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
majora
majora-adr
Commits
0ccaee01
Commit
0ccaee01
authored
Sep 11, 2021
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重播
parent
02f5bfc2
Pipeline
#2434
canceled with stages
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
6 deletions
+84
-6
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+8
-6
KeepAliveService.java
...src/main/java/com/virjar/majora/adr/KeepAliveService.java
+22
-0
Shell.java
app/src/main/java/com/virjar/majora/adr/Shell.java
+54
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
0ccaee01
...
...
@@ -3,12 +3,6 @@
xmlns:tools=
"http://schemas.android.com/tools"
package=
"com.virjar.majora.adr"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<!-- 前台服务,保持安排的优先级 -->
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<application
android:name=
".TheApp"
android:allowBackup=
"false"
...
...
@@ -25,10 +19,18 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".SettingsActivity"
/>
<service
android:name=
"com.virjar.majora.adr.KeepAliveService"
android:enabled=
"true"
android:exported=
"false"
/>
</application>
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<!-- 前台服务,保持安排的优先级 -->
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
</manifest>
\ No newline at end of file
app/src/main/java/com/virjar/majora/adr/KeepAliveService.java
View file @
0ccaee01
...
...
@@ -22,10 +22,15 @@ import android.preference.PreferenceManager;
import
com.virjar.majora.client.sdk.client.MajoraClient
;
import
com.virjar.majora.client.sdk.log.MajoraLogger
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
static
android
.
app
.
PendingIntent
.
FLAG_UPDATE_CURRENT
;
public
class
KeepAliveService
extends
Service
{
private
static
boolean
start
=
false
;
// 重播任务定时器
private
Timer
timer
=
new
Timer
(
"reDial"
);
public
static
void
startService
(
Context
context
)
{
if
(
start
)
{
...
...
@@ -89,10 +94,27 @@ public class KeepAliveService extends Service {
Notification
notification
=
builder
.
build
();
notification
.
defaults
=
Notification
.
DEFAULT_SOUND
;
startForeground
(
110
,
notification
);
startProxyService
();
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
reDial
();
}
},
5
*
60
*
1000
,
5
*
60
*
1000
);
start
=
true
;
}
private
void
reDial
()
{
try
{
Shell
.
executeCmd
(
"am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true"
);
Thread
.
sleep
(
5000
);
Shell
.
executeCmd
(
"am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false"
);
}
catch
(
Exception
e
)
{
MajoraLogger
.
getLogger
().
info
(
"reDial error"
,
e
);
}
}
private
void
startProxyService
()
{
SharedPreferences
spf
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
String
serverHost
=
spf
.
getString
(
"server_host"
,
"majora.virjar.com"
);
...
...
app/src/main/java/com/virjar/majora/adr/Shell.java
0 → 100644
View file @
0ccaee01
package
com
.
virjar
.
majora
.
adr
;
import
com.virjar.majora.client.sdk.log.MajoraLogger
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
public
class
Shell
{
public
static
void
executeCmd
(
String
cmd
)
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
"su"
);
OutputStream
outputStream
=
process
.
getOutputStream
();
outputStream
.
write
(
cmd
.
getBytes
());
outputStream
.
write
(
"\n"
.
getBytes
());
StringBuffer
out
=
new
StringBuffer
();
StringBuffer
error
=
new
StringBuffer
();
autoFillOutput
(
process
.
getInputStream
(),
out
);
autoFillOutput
(
process
.
getErrorStream
(),
error
);
process
.
waitFor
();
}
catch
(
Throwable
throwable
)
{
MajoraLogger
.
getLogger
().
info
(
"executeCmd error"
,
throwable
);
}
}
private
static
void
autoFillOutput
(
final
InputStream
inputStream
,
final
StringBuffer
stringBuffer
)
{
new
Thread
()
{
@Override
public
void
run
()
{
try
{
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
stringBuffer
.
append
(
line
).
append
(
"\n"
);
}
bufferedReader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}.
start
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment