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
99c74b31
Commit
99c74b31
authored
Nov 05, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve dynamic permissions
parent
ce5b1382
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
21 deletions
+39
-21
MagiskManager.java
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
+5
-0
MainActivity.java
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
+6
-0
SplashActivity.java
app/src/main/java/com/topjohnwu/magisk/SplashActivity.java
+2
-4
Activity.java
...c/main/java/com/topjohnwu/magisk/components/Activity.java
+4
-8
Const.java
app/src/main/java/com/topjohnwu/magisk/utils/Const.java
+2
-0
ShowUI.java
app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
+7
-4
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+13
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
99c74b31
...
@@ -84,6 +84,7 @@ public class MagiskManager extends Application {
...
@@ -84,6 +84,7 @@ public class MagiskManager extends Application {
public
SuDatabaseHelper
suDB
;
public
SuDatabaseHelper
suDB
;
public
RepoDatabaseHelper
repoDB
;
public
RepoDatabaseHelper
repoDB
;
public
Shell
shell
;
public
Shell
shell
;
public
Runnable
permissionGrantCallback
=
null
;
private
static
Handler
mHandler
=
new
Handler
();
private
static
Handler
mHandler
=
new
Handler
();
...
@@ -203,4 +204,8 @@ public class MagiskManager extends Application {
...
@@ -203,4 +204,8 @@ public class MagiskManager extends Application {
magiskHide
=
true
;
magiskHide
=
true
;
}
}
}
}
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
permissionGrantCallback
=
callback
;
}
}
}
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
99c74b31
...
@@ -6,6 +6,7 @@ import android.os.Bundle;
...
@@ -6,6 +6,7 @@ import android.os.Bundle;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.NonNull
;
import
android.support.design.widget.NavigationView
;
import
android.support.design.widget.NavigationView
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v4.widget.DrawerLayout
;
...
@@ -52,6 +53,11 @@ public class MainActivity extends Activity
...
@@ -52,6 +53,11 @@ public class MainActivity extends Activity
finish
();
finish
();
}
}
String
perm
=
getIntent
().
getStringExtra
(
Const
.
Key
.
INTENT_PERM
);
if
(
perm
!=
null
)
{
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]
{
perm
},
0
);
}
prefs
=
mm
.
prefs
;
prefs
=
mm
.
prefs
;
if
(
mm
.
isDarkTheme
)
{
if
(
mm
.
isDarkTheme
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/SplashActivity.java
View file @
99c74b31
...
@@ -130,10 +130,8 @@ public class SplashActivity extends Activity {
...
@@ -130,10 +130,8 @@ public class SplashActivity extends Activity {
mm
.
hasInit
=
true
;
mm
.
hasInit
=
true
;
Intent
intent
=
new
Intent
(
this
,
MainActivity
.
class
);
Intent
intent
=
new
Intent
(
this
,
MainActivity
.
class
);
String
section
=
getIntent
().
getStringExtra
(
Const
.
Key
.
OPEN_SECTION
);
intent
.
putExtra
(
Const
.
Key
.
OPEN_SECTION
,
getIntent
().
getStringExtra
(
Const
.
Key
.
OPEN_SECTION
));
if
(
section
!=
null
)
{
intent
.
putExtra
(
Const
.
Key
.
INTENT_PERM
,
getIntent
().
getStringExtra
(
Const
.
Key
.
INTENT_PERM
));
intent
.
putExtra
(
Const
.
Key
.
OPEN_SECTION
,
section
);
}
startActivity
(
intent
);
startActivity
(
intent
);
finish
();
finish
();
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/components/Activity.java
View file @
99c74b31
...
@@ -18,7 +18,6 @@ import com.topjohnwu.magisk.utils.Utils;
...
@@ -18,7 +18,6 @@ import com.topjohnwu.magisk.utils.Utils;
public
class
Activity
extends
AppCompatActivity
{
public
class
Activity
extends
AppCompatActivity
{
private
Runnable
permissionGrantCallback
=
null
;
private
AssetManager
mAssetManager
=
null
;
private
AssetManager
mAssetManager
=
null
;
private
Resources
mResources
=
null
;
private
Resources
mResources
=
null
;
...
@@ -47,12 +46,13 @@ public class Activity extends AppCompatActivity {
...
@@ -47,12 +46,13 @@ public class Activity extends AppCompatActivity {
@Override
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
MagiskManager
mm
=
getMagiskManager
();
if
(
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
permissionGrantCallback
!=
null
)
{
if
(
mm
.
permissionGrantCallback
!=
null
)
{
permissionGrantCallback
.
run
();
mm
.
permissionGrantCallback
.
run
();
}
}
}
}
permissionGrantCallback
=
null
;
mm
.
permissionGrantCallback
=
null
;
}
}
@Override
@Override
...
@@ -65,10 +65,6 @@ public class Activity extends AppCompatActivity {
...
@@ -65,10 +65,6 @@ public class Activity extends AppCompatActivity {
return
mResources
==
null
?
super
.
getResources
()
:
mResources
;
return
mResources
==
null
?
super
.
getResources
()
:
mResources
;
}
}
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
permissionGrantCallback
=
callback
;
}
public
MagiskManager
getMagiskManager
()
{
public
MagiskManager
getMagiskManager
()
{
return
(
MagiskManager
)
super
.
getApplicationContext
();
return
(
MagiskManager
)
super
.
getApplicationContext
();
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
99c74b31
...
@@ -80,11 +80,13 @@ public class Const {
...
@@ -80,11 +80,13 @@ public class Const {
public
static
final
String
OPEN_SECTION
=
"section"
;
public
static
final
String
OPEN_SECTION
=
"section"
;
public
static
final
String
INTENT_SET_VERSION
=
"version"
;
public
static
final
String
INTENT_SET_VERSION
=
"version"
;
public
static
final
String
INTENT_SET_LINK
=
"link"
;
public
static
final
String
INTENT_SET_LINK
=
"link"
;
public
static
final
String
INTENT_PERM
=
"perm_dialog"
;
public
static
final
String
FLASH_ACTION
=
"action"
;
public
static
final
String
FLASH_ACTION
=
"action"
;
public
static
final
String
FLASH_SET_BOOT
=
"boot"
;
public
static
final
String
FLASH_SET_BOOT
=
"boot"
;
public
static
final
String
FLASH_SET_ENC
=
"enc"
;
public
static
final
String
FLASH_SET_ENC
=
"enc"
;
public
static
final
String
FLASH_SET_VERITY
=
"verity"
;
public
static
final
String
FLASH_SET_VERITY
=
"verity"
;
// others
// others
public
static
final
String
UPDATE_NOTIFICATION
=
"notification"
;
public
static
final
String
UPDATE_NOTIFICATION
=
"notification"
;
public
static
final
String
UPDATE_CHANNEL
=
"update_channel"
;
public
static
final
String
UPDATE_CHANNEL
=
"update_channel"
;
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
View file @
99c74b31
package
com
.
topjohnwu
.
magisk
.
utils
;
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
...
@@ -216,10 +217,12 @@ public class ShowUI {
...
@@ -216,10 +217,12 @@ public class ShowUI {
mm
.
remoteManagerVersionString
+
".apk"
)))
mm
.
remoteManagerVersionString
+
".apk"
)))
.
setCancelable
(
true
)
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
{
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
{
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
Utils
.
runWithPermission
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
()
->
{
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_VERSION
,
mm
.
remoteManagerVersionString
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
mm
.
sendBroadcast
(
intent
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_VERSION
,
mm
.
remoteManagerVersionString
);
mm
.
sendBroadcast
(
intent
);
});
})
})
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
show
();
.
show
();
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
99c74b31
...
@@ -4,6 +4,7 @@ import android.Manifest;
...
@@ -4,6 +4,7 @@ import android.Manifest;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.DownloadManager
;
import
android.app.DownloadManager
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.IntentFilter
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
...
@@ -24,6 +25,7 @@ import android.widget.Toast;
...
@@ -24,6 +25,7 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
...
@@ -193,11 +195,17 @@ public class Utils {
...
@@ -193,11 +195,17 @@ public class Utils {
public
static
void
runWithPermission
(
Context
context
,
String
permission
,
Runnable
callback
)
{
public
static
void
runWithPermission
(
Context
context
,
String
permission
,
Runnable
callback
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
permission
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
permission
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
// Passed in context should be an activity if not granted, need to show dialog!
// Passed in context should be an activity if not granted, need to show dialog!
if
(!(
context
instanceof
com
.
topjohnwu
.
magisk
.
components
.
Activity
))
Utils
.
getMagiskManager
(
context
).
setPermissionGrantCallback
(
callback
);
return
;
if
(!(
context
instanceof
com
.
topjohnwu
.
magisk
.
components
.
Activity
))
{
com
.
topjohnwu
.
magisk
.
components
.
Activity
activity
=
(
com
.
topjohnwu
.
magisk
.
components
.
Activity
)
context
;
// Start activity to show dialog
activity
.
setPermissionGrantCallback
(
callback
);
Intent
intent
=
new
Intent
(
context
,
SplashActivity
.
class
);
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]
{
permission
},
0
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_PERM
,
permission
);
context
.
startActivity
(
intent
);
}
else
{
ActivityCompat
.
requestPermissions
((
Activity
)
context
,
new
String
[]
{
permission
},
0
);
}
}
else
{
}
else
{
callback
.
run
();
callback
.
run
();
}
}
...
...
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