Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
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
Administrator
Magisk
Commits
959ed7f8
Commit
959ed7f8
authored
Jan 26, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement logging and bug fixes
parent
a5c0411b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
8 deletions
+120
-8
Global.java
app/src/main/java/com/topjohnwu/magisk/Global.java
+3
-1
Policy.java
app/src/main/java/com/topjohnwu/magisk/superuser/Policy.java
+1
-1
SuDatabaseHelper.java
...java/com/topjohnwu/magisk/superuser/SuDatabaseHelper.java
+1
-1
SuLogDatabaseHelper.java
...a/com/topjohnwu/magisk/superuser/SuLogDatabaseHelper.java
+62
-0
SuLogEntry.java
.../main/java/com/topjohnwu/magisk/superuser/SuLogEntry.java
+42
-0
SuReceiver.java
.../main/java/com/topjohnwu/magisk/superuser/SuReceiver.java
+8
-3
SuRequestActivity.java
...ava/com/topjohnwu/magisk/superuser/SuRequestActivity.java
+3
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/Global.java
View file @
959ed7f8
...
@@ -46,6 +46,8 @@ public class Global {
...
@@ -46,6 +46,8 @@ public class Global {
public
static
boolean
isDarkTheme
;
public
static
boolean
isDarkTheme
;
public
static
boolean
shellLogging
;
public
static
boolean
shellLogging
;
public
static
boolean
devLogging
;
public
static
boolean
devLogging
;
public
static
int
suRequestTimeout
=
10
;
public
static
int
suLogTimeout
=
14
;
}
}
...
@@ -59,7 +61,7 @@ public class Global {
...
@@ -59,7 +61,7 @@ public class Global {
static
void
updateMagiskInfo
()
{
static
void
updateMagiskInfo
()
{
List
<
String
>
ret
=
Shell
.
sh
(
"getprop magisk.version"
);
List
<
String
>
ret
=
Shell
.
sh
(
"getprop magisk.version"
);
if
(
Utils
.
isValidShellResponse
(
ret
))
{
if
(
!
Utils
.
isValidShellResponse
(
ret
))
{
Info
.
magiskVersion
=
-
1
;
Info
.
magiskVersion
=
-
1
;
}
else
{
}
else
{
try
{
try
{
...
...
app/src/main/java/com/topjohnwu/magisk/superuser/Policy.java
View file @
959ed7f8
...
@@ -45,7 +45,7 @@ public class Policy {
...
@@ -45,7 +45,7 @@ public class Policy {
values
.
put
(
"uid"
,
uid
);
values
.
put
(
"uid"
,
uid
);
values
.
put
(
"package_name"
,
packageName
);
values
.
put
(
"package_name"
,
packageName
);
values
.
put
(
"app_name"
,
appName
);
values
.
put
(
"app_name"
,
appName
);
values
.
put
(
"policy"
,
policy
);
values
.
put
(
"policy"
,
policy
);
values
.
put
(
"until"
,
until
);
values
.
put
(
"until"
,
until
);
values
.
put
(
"logging"
,
logging
?
1
:
0
);
values
.
put
(
"logging"
,
logging
?
1
:
0
);
values
.
put
(
"notification"
,
notification
?
1
:
0
);
values
.
put
(
"notification"
,
notification
?
1
:
0
);
...
...
app/src/main/java/com/topjohnwu/magisk/superuser/SuDatabaseHelper.java
View file @
959ed7f8
...
@@ -62,7 +62,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
...
@@ -62,7 +62,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
Policy
policy
;
Policy
policy
;
// Clear outdated policies
// Clear outdated policies
db
.
delete
(
TABLE_NAME
,
"until > 0 and until < ?"
,
new
String
[]
{
String
.
valueOf
(
System
.
currentTimeMillis
())
});
db
.
delete
(
TABLE_NAME
,
"until > 0 and until < ?"
,
new
String
[]
{
String
.
valueOf
(
System
.
currentTimeMillis
())
});
try
(
Cursor
c
=
db
.
query
(
TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
"app_name"
))
{
try
(
Cursor
c
=
db
.
query
(
TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
"app_name
ASC
"
))
{
while
(
c
.
moveToNext
())
{
while
(
c
.
moveToNext
())
{
policy
=
new
Policy
(
c
);
policy
=
new
Policy
(
c
);
// Package is uninstalled
// Package is uninstalled
...
...
app/src/main/java/com/topjohnwu/magisk/superuser/SuLogDatabaseHelper.java
0 → 100644
View file @
959ed7f8
package
com
.
topjohnwu
.
magisk
.
superuser
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
com.topjohnwu.magisk.Global
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
SuLogDatabaseHelper
extends
SQLiteOpenHelper
{
private
static
final
int
DATABASE_VER
=
1
;
private
static
final
String
TABLE_NAME
=
"logs"
;
public
SuLogDatabaseHelper
(
Context
context
)
{
super
(
context
,
"sulog.db"
,
null
,
DATABASE_VER
);
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS "
+
TABLE_NAME
+
" (id INTEGER PRIMARY KEY AUTOINCREMENT, "
+
"from_uid INT, package_name TEXT, app_name TEXT, from_pid INT, "
+
"to_uid INT, action INT, time INT, command TEXT)"
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
// Currently new database, no upgrading
}
public
void
addLog
(
SuLogEntry
log
)
{
SQLiteDatabase
db
=
getWritableDatabase
();
db
.
insert
(
TABLE_NAME
,
null
,
log
.
getContentValues
());
db
.
close
();
}
public
List
<
SuLogEntry
>
getLogList
()
{
return
getLogList
(
null
);
}
public
List
<
SuLogEntry
>
getLogList
(
int
uid
)
{
return
getLogList
(
"uid="
+
uid
);
}
public
List
<
SuLogEntry
>
getLogList
(
String
selection
)
{
List
<
SuLogEntry
>
ret
=
new
ArrayList
<>();
SQLiteDatabase
db
=
getWritableDatabase
();
// Clear outdated logs
db
.
delete
(
TABLE_NAME
,
"time < ?"
,
new
String
[]
{
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
-
Global
.
Configs
.
suLogTimeout
*
86400
)
});
try
(
Cursor
c
=
db
.
query
(
TABLE_NAME
,
null
,
selection
,
null
,
null
,
null
,
"time DESC"
))
{
while
(
c
.
moveToNext
())
ret
.
add
(
new
SuLogEntry
(
c
));
}
db
.
close
();
return
ret
;
}
}
app/src/main/java/com/topjohnwu/magisk/superuser/SuLogEntry.java
0 → 100644
View file @
959ed7f8
package
com
.
topjohnwu
.
magisk
.
superuser
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
public
class
SuLogEntry
{
public
int
fromUid
,
toUid
,
fromPid
;
public
String
packageName
,
appName
,
command
;
public
boolean
action
;
public
long
time
;
public
SuLogEntry
(
Policy
policy
)
{
fromUid
=
policy
.
uid
;
packageName
=
policy
.
packageName
;
appName
=
policy
.
appName
;
}
public
SuLogEntry
(
Cursor
c
)
{
fromUid
=
c
.
getInt
(
c
.
getColumnIndex
(
"from_uid"
));
fromPid
=
c
.
getInt
(
c
.
getColumnIndex
(
"from_pid"
));
toUid
=
c
.
getInt
(
c
.
getColumnIndex
(
"to_uid"
));
packageName
=
c
.
getString
(
c
.
getColumnIndex
(
"package_name"
));
appName
=
c
.
getString
(
c
.
getColumnIndex
(
"app_name"
));
command
=
c
.
getString
(
c
.
getColumnIndex
(
"command"
));
action
=
c
.
getInt
(
c
.
getColumnIndex
(
"action"
))
!=
0
;
time
=
c
.
getLong
(
c
.
getColumnIndex
(
"until"
));
}
public
ContentValues
getContentValues
()
{
ContentValues
values
=
new
ContentValues
();
values
.
put
(
"from_uid"
,
fromUid
);
values
.
put
(
"package_name"
,
packageName
);
values
.
put
(
"app_name"
,
appName
);
values
.
put
(
"from_pid"
,
fromPid
);
values
.
put
(
"command"
,
command
);
values
.
put
(
"to_uid"
,
toUid
);
values
.
put
(
"action"
,
action
);
values
.
put
(
"time"
,
time
);
return
values
;
}
}
app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java
View file @
959ed7f8
...
@@ -24,8 +24,8 @@ public class SuReceiver extends BroadcastReceiver {
...
@@ -24,8 +24,8 @@ public class SuReceiver extends BroadcastReceiver {
action
=
intent
.
getStringExtra
(
"action"
);
action
=
intent
.
getStringExtra
(
"action"
);
if
(
action
==
null
)
return
;
if
(
action
==
null
)
return
;
SuDatabaseHelper
d
bHelper
=
new
SuDatabaseHelper
(
context
);
SuDatabaseHelper
suD
bHelper
=
new
SuDatabaseHelper
(
context
);
policy
=
d
bHelper
.
getPolicy
(
fromUid
);
policy
=
suD
bHelper
.
getPolicy
(
fromUid
);
if
(
policy
==
null
)
try
{
if
(
policy
==
null
)
try
{
policy
=
new
Policy
(
fromUid
,
context
.
getPackageManager
());
policy
=
new
Policy
(
fromUid
,
context
.
getPackageManager
());
}
catch
(
Throwable
throwable
)
{
}
catch
(
Throwable
throwable
)
{
...
@@ -53,7 +53,12 @@ public class SuReceiver extends BroadcastReceiver {
...
@@ -53,7 +53,12 @@ public class SuReceiver extends BroadcastReceiver {
if
(
pid
<
0
)
return
;
if
(
pid
<
0
)
return
;
command
=
intent
.
getStringExtra
(
"command"
);
command
=
intent
.
getStringExtra
(
"command"
);
if
(
command
==
null
)
return
;
if
(
command
==
null
)
return
;
// TODO: Place info into logs
SuLogEntry
log
=
new
SuLogEntry
(
policy
);
log
.
toUid
=
toUid
;
log
.
fromPid
=
pid
;
log
.
command
=
command
;
SuLogDatabaseHelper
logDbHelper
=
new
SuLogDatabaseHelper
(
context
);
logDbHelper
.
addLog
(
log
);
}
}
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java
View file @
959ed7f8
...
@@ -18,6 +18,7 @@ import android.widget.LinearLayout;
...
@@ -18,6 +18,7 @@ import android.widget.LinearLayout;
import
android.widget.Spinner
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
java.io.DataInputStream
;
import
java.io.DataInputStream
;
...
@@ -46,7 +47,7 @@ public class SuRequestActivity extends AppCompatActivity {
...
@@ -46,7 +47,7 @@ public class SuRequestActivity extends AppCompatActivity {
private
PackageManager
pm
;
private
PackageManager
pm
;
private
PackageInfo
info
;
private
PackageInfo
info
;
private
int
uid
,
countdown
=
10
;
private
int
uid
;
private
String
appName
,
packageName
;
private
String
appName
,
packageName
;
private
CountDownTimer
timer
;
private
CountDownTimer
timer
;
...
@@ -73,7 +74,7 @@ public class SuRequestActivity extends AppCompatActivity {
...
@@ -73,7 +74,7 @@ public class SuRequestActivity extends AppCompatActivity {
appNameView
.
setText
(
appName
);
appNameView
.
setText
(
appName
);
packageNameView
.
setText
(
packageName
);
packageNameView
.
setText
(
packageName
);
timer
=
new
CountDownTimer
(
countdown
*
1000
,
1000
)
{
timer
=
new
CountDownTimer
(
Global
.
Configs
.
suRequestTimeout
*
1000
,
1000
)
{
@Override
@Override
public
void
onTick
(
long
millisUntilFinished
)
{
public
void
onTick
(
long
millisUntilFinished
)
{
deny_btn
.
setText
(
getString
(
R
.
string
.
deny
,
"("
+
millisUntilFinished
/
1000
+
")"
));
deny_btn
.
setText
(
getString
(
R
.
string
.
deny
,
"("
+
millisUntilFinished
/
1000
+
")"
));
...
...
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