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
c5a7ab24
Commit
c5a7ab24
authored
Jun 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move runWithPermission method
parent
3dd5a6f3
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
54 additions
and
53 deletions
+54
-53
MagiskLogFragment.java
src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
+1
-3
ModulesFragment.java
src/full/java/com/topjohnwu/magisk/ModulesFragment.java
+1
-3
SettingsActivity.java
src/full/java/com/topjohnwu/magisk/SettingsActivity.java
+1
-1
ProcessRepoZip.java
...full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+2
-2
Fragment.java
src/full/java/com/topjohnwu/magisk/components/Fragment.java
+4
-0
ShowUI.java
src/full/java/com/topjohnwu/magisk/utils/ShowUI.java
+1
-1
Activity.java
src/main/java/com/topjohnwu/magisk/components/Activity.java
+37
-4
Application.java
...ain/java/com/topjohnwu/magisk/components/Application.java
+0
-6
Utils.java
src/main/java/com/topjohnwu/magisk/utils/Utils.java
+6
-32
SplashActivity.java
src/stub/java/com/topjohnwu/magisk/SplashActivity.java
+1
-1
No files found.
src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
View file @
c5a7ab24
...
...
@@ -21,7 +21,6 @@ import com.topjohnwu.magisk.asyncs.ParallelTask;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.CallbackList
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -88,8 +87,7 @@ public class MagiskLogFragment extends Fragment {
new
LogManager
().
read
();
return
true
;
case
R
.
id
.
menu_save
:
Utils
.
runWithPermission
(
getActivity
(),
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
new
LogManager
().
save
());
return
true
;
case
R
.
id
.
menu_clear
:
...
...
src/full/java/com/topjohnwu/magisk/ModulesFragment.java
View file @
c5a7ab24
...
...
@@ -21,7 +21,6 @@ import com.topjohnwu.magisk.components.Fragment;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.ArrayList
;
...
...
@@ -40,8 +39,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
@BindView
(
R
.
id
.
empty_rv
)
TextView
emptyRv
;
@OnClick
(
R
.
id
.
fab
)
public
void
selectFile
()
{
Utils
.
runWithPermission
(
getActivity
(),
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},()
->
{
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
intent
.
setType
(
"application/zip"
);
startActivityForResult
(
intent
,
Const
.
ID
.
FETCH_ZIP
);
...
...
src/full/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
c5a7ab24
...
...
@@ -166,7 +166,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
}
else
{
if
(
Utils
.
checkNetworkStatus
())
{
restoreManager
.
setOnPreferenceClickListener
((
pref
)
->
{
Utils
.
runWithPermission
(
getActivity
(),
runWithPermission
(
getActivity
(),
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
...
...
src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
c5a7ab24
...
...
@@ -14,7 +14,6 @@ import com.topjohnwu.magisk.MagiskManager;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -158,7 +157,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
@Override
public
ParallelTask
<
Void
,
Object
,
Boolean
>
exec
(
Void
...
voids
)
{
Utils
.
runWithPermission
(
getActivity
(),
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
com
.
topjohnwu
.
magisk
.
components
.
Activity
.
runWithPermission
(
getActivity
(),
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
super
.
exec
(
voids
));
return
this
;
}
...
...
src/full/java/com/topjohnwu/magisk/components/Fragment.java
View file @
c5a7ab24
...
...
@@ -36,4 +36,8 @@ public class Fragment extends android.support.v4.app.Fragment {
public
void
startActivityForResult
(
Intent
intent
,
int
requestCode
,
Activity
.
ActivityResultListener
listener
)
{
((
Activity
)
getActivity
()).
startActivityForResult
(
intent
,
requestCode
,
listener
);
}
public
void
runWithPermission
(
String
[]
permissions
,
Runnable
callback
)
{
Activity
.
runWithPermission
(
getActivity
(),
permissions
,
callback
);
}
}
src/full/java/com/topjohnwu/magisk/utils/ShowUI.java
View file @
c5a7ab24
...
...
@@ -255,7 +255,7 @@ public class ShowUI {
.
setMessage
(
mm
.
getString
(
R
.
string
.
repo_install_msg
,
filename
))
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
{
Utils
.
runWithPermission
(
activity
,
com
.
topjohnwu
.
magisk
.
components
.
Activity
.
runWithPermission
(
activity
,
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
...
...
src/main/java/com/topjohnwu/magisk/components/Activity.java
View file @
c5a7ab24
package
com
.
topjohnwu
.
magisk
.
components
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.utils.Const
;
public
abstract
class
Activity
extends
FlavorActivity
{
private
static
Runnable
permissionGrantCallback
;
private
ActivityResultListener
activityResultListener
;
public
Activity
()
{
...
...
@@ -20,6 +27,33 @@ public abstract class Activity extends FlavorActivity {
applyOverrideConfiguration
(
configuration
);
}
public
static
void
runWithPermission
(
Context
context
,
String
[]
permissions
,
Runnable
callback
)
{
boolean
granted
=
true
;
for
(
String
perm
:
permissions
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
perm
)
!=
PackageManager
.
PERMISSION_GRANTED
)
granted
=
false
;
}
if
(
granted
)
{
callback
.
run
();
}
else
{
// Passed in context should be an activity if not granted, need to show dialog!
permissionGrantCallback
=
callback
;
if
(!(
context
instanceof
Activity
))
{
// Start activity to show dialog
Intent
intent
=
new
Intent
(
context
,
SplashActivity
.
class
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_PERM
,
permissions
);
context
.
startActivity
(
intent
);
}
else
{
ActivityCompat
.
requestPermissions
((
android
.
app
.
Activity
)
context
,
permissions
,
0
);
}
}
}
public
void
runWithPermission
(
String
[]
permissions
,
Runnable
callback
)
{
runWithPermission
(
this
,
permissions
,
callback
);
}
@Override
public
Application
getApplicationContext
()
{
return
(
Application
)
super
.
getApplicationContext
();
...
...
@@ -32,15 +66,14 @@ public abstract class Activity extends FlavorActivity {
if
(
result
!=
PackageManager
.
PERMISSION_GRANTED
)
grant
=
false
;
}
Application
app
=
getApplicationContext
();
if
(
grant
)
{
if
(
app
.
permissionGrantCallback
!=
null
)
{
app
.
permissionGrantCallback
.
run
();
if
(
permissionGrantCallback
!=
null
)
{
permissionGrantCallback
.
run
();
}
}
else
{
MagiskManager
.
toast
(
R
.
string
.
no_rw_storage
,
Toast
.
LENGTH_LONG
);
}
app
.
permissionGrantCallback
=
null
;
permissionGrantCallback
=
null
;
}
@Override
...
...
src/main/java/com/topjohnwu/magisk/components/Application.java
View file @
c5a7ab24
...
...
@@ -14,8 +14,6 @@ public abstract class Application extends android.app.Application {
private
static
Handler
mHandler
=
new
Handler
();
public
Runnable
permissionGrantCallback
=
null
;
public
Application
()
{
weakSelf
=
new
WeakReference
<>(
this
);
}
...
...
@@ -26,10 +24,6 @@ public abstract class Application extends android.app.Application {
locale
=
defaultLocale
=
Locale
.
getDefault
();
}
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
permissionGrantCallback
=
callback
;
}
public
static
void
toast
(
CharSequence
msg
,
int
duration
)
{
mHandler
.
post
(()
->
Toast
.
makeText
(
weakSelf
.
get
(),
msg
,
duration
).
show
());
}
...
...
src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
c5a7ab24
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.DownloadManager
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.database.Cursor
;
import
android.net.ConnectivityManager
;
...
...
@@ -15,13 +12,11 @@ import android.net.NetworkInfo;
import
android.net.Uri
;
import
android.provider.OpenableColumns
;
import
android.support.annotation.StringRes
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.
Splash
Activity
;
import
com.topjohnwu.magisk.
components.
Activity
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
java.io.File
;
...
...
@@ -39,7 +34,8 @@ public class Utils {
if
(
isDownloading
)
return
;
runWithPermission
(
context
,
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Activity
.
runWithPermission
(
context
,
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
File
file
=
new
File
(
Const
.
EXTERNAL_PATH
,
getLegalFilename
(
filename
));
if
((!
file
.
getParentFile
().
exists
()
&&
!
file
.
getParentFile
().
mkdirs
())
...
...
@@ -47,7 +43,7 @@ public class Utils {
return
;
}
Toast
.
makeText
(
context
,
context
.
getString
(
R
.
string
.
downloading_toast
,
filename
),
Toast
.
LENGTH_LONG
).
show
(
);
MagiskManager
.
toast
(
context
.
getString
(
R
.
string
.
downloading_toast
,
filename
),
Toast
.
LENGTH_LONG
);
isDownloading
=
true
;
DownloadManager
.
Request
request
=
new
DownloadManager
...
...
@@ -56,7 +52,8 @@ public class Utils {
DownloadManager
dm
=
(
DownloadManager
)
context
.
getSystemService
(
Context
.
DOWNLOAD_SERVICE
);
receiver
.
setDownloadID
(
dm
.
enqueue
(
request
)).
setFile
(
file
);
context
.
getApplicationContext
().
registerReceiver
(
receiver
,
new
IntentFilter
(
DownloadManager
.
ACTION_DOWNLOAD_COMPLETE
));
context
.
getApplicationContext
().
registerReceiver
(
receiver
,
new
IntentFilter
(
DownloadManager
.
ACTION_DOWNLOAD_COMPLETE
));
});
}
...
...
@@ -142,29 +139,6 @@ public class Utils {
return
locales
;
}
public
static
void
runWithPermission
(
Context
context
,
String
[]
permissions
,
Runnable
callback
)
{
boolean
granted
=
true
;
for
(
String
perm
:
permissions
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
perm
)
!=
PackageManager
.
PERMISSION_GRANTED
)
granted
=
false
;
}
if
(
granted
)
{
callback
.
run
();
}
else
{
// Passed in context should be an activity if not granted, need to show dialog!
getMagiskManager
(
context
).
setPermissionGrantCallback
(
callback
);
if
(!(
context
instanceof
com
.
topjohnwu
.
magisk
.
components
.
Activity
))
{
// Start activity to show dialog
Intent
intent
=
new
Intent
(
context
,
SplashActivity
.
class
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_PERM
,
permissions
);
context
.
startActivity
(
intent
);
}
else
{
ActivityCompat
.
requestPermissions
((
Activity
)
context
,
permissions
,
0
);
}
}
}
public
static
int
dpInPx
(
int
dp
)
{
Context
context
=
MagiskManager
.
get
();
float
scale
=
context
.
getResources
().
getDisplayMetrics
().
density
;
...
...
src/stub/java/com/topjohnwu/magisk/SplashActivity.java
View file @
c5a7ab24
...
...
@@ -45,7 +45,7 @@ public class SplashActivity extends Activity {
.
setTitle
(
R
.
string
.
app_name
)
.
setMessage
(
R
.
string
.
upgrade_msg
)
.
setPositiveButton
(
R
.
string
.
yes
,
(
d
,
w
)
->
{
Utils
.
runWithPermission
(
this
,
new
String
[]
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Intent
intent
=
new
Intent
(
this
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
apkLink
);
...
...
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