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
3fe5647a
Commit
3fe5647a
authored
Sep 19, 2016
by
d8ahazard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moar fun with autoroot
parent
fec12458
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
25 deletions
+32
-25
MonitorService.java
app/src/main/java/com/topjohnwu/magisk/MonitorService.java
+22
-21
RootFragment.java
app/src/main/java/com/topjohnwu/magisk/RootFragment.java
+2
-0
WelcomeActivity.java
app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
+8
-4
No files found.
app/src/main/java/com/topjohnwu/magisk/MonitorService.java
View file @
3fe5647a
...
@@ -36,7 +36,7 @@ public class MonitorService extends Service
...
@@ -36,7 +36,7 @@ public class MonitorService extends Service
private
Boolean
disableroot
;
private
Boolean
disableroot
;
private
Boolean
disablerootprev
;
private
Boolean
disablerootprev
;
private
int
counter
=
0
;
private
int
counter
=
0
;
private
String
mPackageName
;
private
String
mPackageName
=
""
;
@Nullable
@Nullable
@Override
@Override
...
@@ -46,8 +46,6 @@ public class MonitorService extends Service
...
@@ -46,8 +46,6 @@ public class MonitorService extends Service
@Override
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
checkProcesses
.
run
();
return
START_STICKY
;
return
START_STICKY
;
}
}
...
@@ -55,6 +53,7 @@ public class MonitorService extends Service
...
@@ -55,6 +53,7 @@ public class MonitorService extends Service
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
checkProcesses
.
run
();
Log
.
d
(
"Magisk"
,
"MonitorService: Service created"
);
Log
.
d
(
"Magisk"
,
"MonitorService: Service created"
);
}
}
...
@@ -94,7 +93,7 @@ public class MonitorService extends Service
...
@@ -94,7 +93,7 @@ public class MonitorService extends Service
//Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled"));
//Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled"));
}
}
handler
.
postDelayed
(
checkProcesses
,
10
00
);
handler
.
postDelayed
(
checkProcesses
,
5
00
);
}
}
};
};
...
@@ -182,29 +181,31 @@ public class MonitorService extends Service
...
@@ -182,29 +181,31 @@ public class MonitorService extends Service
protected
boolean
isAppForeground
(
String
packageName
)
{
protected
boolean
isAppForeground
(
String
packageName
)
{
UsageStatsManager
usageStatsManager
=
(
UsageStatsManager
)
getSystemService
(
Context
.
USAGE_STATS_SERVICE
);
UsageStatsManager
usageStatsManager
=
(
UsageStatsManager
)
getSystemService
(
Context
.
USAGE_STATS_SERVICE
);
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
List
<
UsageStats
>
stats
=
usageStatsManager
.
queryUsageStats
(
UsageStatsManager
.
INTERVAL_DAILY
,
time
-
1000
*
10
,
time
);
List
<
UsageStats
>
stats
=
usageStatsManager
.
queryUsageStats
(
UsageStatsManager
.
INTERVAL_DAILY
,
time
-
1000
*
10
,
time
);
String
topPackageName
=
""
;
String
topPackageName
=
""
;
if
(
stats
!=
null
)
{
if
(
stats
!=
null
)
{
SortedMap
<
Long
,
UsageStats
>
mySortedMap
=
new
TreeMap
<>();
SortedMap
<
Long
,
UsageStats
>
mySortedMap
=
new
TreeMap
<>();
for
(
UsageStats
usageStats
:
stats
)
{
for
(
UsageStats
usageStats
:
stats
)
{
mySortedMap
.
put
(
usageStats
.
getLastTimeUsed
(),
usageStats
);
mySortedMap
.
put
(
usageStats
.
getLastTimeUsed
(),
usageStats
);
}
if
(!
mySortedMap
.
isEmpty
())
{
topPackageName
=
mySortedMap
.
get
(
mySortedMap
.
lastKey
()).
getPackageName
();
if
(
topPackageName
.
equals
(
"com.topjohnwu.magisk"
))
{
mySortedMap
.
remove
(
mySortedMap
.
lastKey
());
topPackageName
=
mySortedMap
.
get
(
mySortedMap
.
lastKey
()).
getPackageName
();
mPackageName
=
getAppName
(
topPackageName
);
}
}
if
(!
mySortedMap
.
isEmpty
())
{
topPackageName
=
mySortedMap
.
get
(
mySortedMap
.
lastKey
()).
getPackageName
();
if
(
topPackageName
.
equals
(
"com.topjohnwu.magisk"
))
{
mySortedMap
.
remove
(
mySortedMap
.
lastKey
());
topPackageName
=
mySortedMap
.
get
(
mySortedMap
.
lastKey
()).
getPackageName
();
Log
.
d
(
"Magisk"
,
"MonitorService: Package is "
+
topPackageName
);
mPackageName
=
getAppName
(
topPackageName
);
}
}
}
}
}
return
topPackageName
.
equals
(
packageName
);
return
topPackageName
.
equals
(
packageName
);
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/RootFragment.java
View file @
3fe5647a
...
@@ -168,6 +168,8 @@ public class RootFragment extends Fragment {
...
@@ -168,6 +168,8 @@ public class RootFragment extends Fragment {
getActivity
().
startService
(
myServiceIntent
);
getActivity
().
startService
(
myServiceIntent
);
}
}
}
else
{
}
else
{
Intent
myIntent
=
new
Intent
(
getActivity
(),
MonitorService
.
class
);
getActivity
().
stopService
(
myIntent
);
rootToggle
.
setEnabled
(
true
);
rootToggle
.
setEnabled
(
true
);
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
View file @
3fe5647a
...
@@ -54,9 +54,14 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
...
@@ -54,9 +54,14 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
// Startups
// Startups
PreferenceManager
.
setDefaultValues
(
this
,
R
.
xml
.
defaultpref
,
false
);
PreferenceManager
.
setDefaultValues
(
this
,
R
.
xml
.
defaultpref
,
false
);
if
(!
Utils
.
isMyServiceRunning
(
MonitorService
.
class
,
getApplicationContext
()))
{
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
Intent
myIntent
=
new
Intent
(
getApplication
(),
MonitorService
.
class
);
if
(
prefs
.
contains
(
"autoRootEnable"
))
{
getApplication
().
startService
(
myIntent
);
if
(
prefs
.
getBoolean
(
"autoRootEnable"
,
false
))
{
if
(!
Utils
.
isMyServiceRunning
(
MonitorService
.
class
,
getApplicationContext
()))
{
Intent
myIntent
=
new
Intent
(
getApplication
(),
MonitorService
.
class
);
getApplication
().
startService
(
myIntent
);
}
}
}
}
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
...
@@ -66,7 +71,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
...
@@ -66,7 +71,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
new
Utils
.
Initialize
(
this
).
execute
();
new
Utils
.
Initialize
(
this
).
execute
();
new
Utils
.
CheckUpdates
(
this
).
execute
();
new
Utils
.
CheckUpdates
(
this
).
execute
();
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
RepoHelper
.
TaskDelegate
delegate
=
result
->
{
RepoHelper
.
TaskDelegate
delegate
=
result
->
{
//Do a thing here when we get a result we want
//Do a thing here when we get a result we want
};
};
...
...
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