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
9bbfcf32
Commit
9bbfcf32
authored
Aug 25, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not place files into /sdcard/MagiskManager
parent
3948e67c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
59 additions
and
67 deletions
+59
-67
FlashActivity.java
app/src/full/java/com/topjohnwu/magisk/FlashActivity.java
+21
-20
MagiskLogFragment.java
...src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
+4
-5
ReposAdapter.java
...full/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+3
-4
InstallMagisk.java
.../full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
+1
-17
ProcessRepoZip.java
...full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+12
-13
InstallMethodDialog.java
.../com/topjohnwu/magisk/components/InstallMethodDialog.java
+3
-1
MagiskInstallDialog.java
.../com/topjohnwu/magisk/components/MagiskInstallDialog.java
+1
-1
Repo.java
app/src/full/java/com/topjohnwu/magisk/container/Repo.java
+5
-0
BaseActivity.java
...in/java/com/topjohnwu/magisk/components/BaseActivity.java
+2
-0
Download.java
app/src/main/java/com/topjohnwu/magisk/utils/Download.java
+7
-6
No files found.
app/src/full/java/com/topjohnwu/magisk/FlashActivity.java
View file @
9bbfcf32
package
com
.
topjohnwu
.
magisk
;
import
android.Manifest
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.widget.Toolbar
;
import
android.text.TextUtils
;
...
...
@@ -57,25 +57,26 @@ public class FlashActivity extends BaseActivity {
@OnClick
(
R
.
id
.
save_logs
)
void
saveLogs
()
{
Calendar
now
=
Calendar
.
getInstance
();
String
filename
=
String
.
format
(
Locale
.
US
,
"install_log_%04d%02d%02d_%02d%02d%02d.log"
,
now
.
get
(
Calendar
.
YEAR
),
now
.
get
(
Calendar
.
MONTH
)
+
1
,
now
.
get
(
Calendar
.
DAY_OF_MONTH
),
now
.
get
(
Calendar
.
HOUR_OF_DAY
),
now
.
get
(
Calendar
.
MINUTE
),
now
.
get
(
Calendar
.
SECOND
));
File
logFile
=
new
File
(
Download
.
EXTERNAL_PATH
+
"/logs"
,
filename
);
logFile
.
getParentFile
().
mkdirs
();
try
(
FileWriter
writer
=
new
FileWriter
(
logFile
))
{
for
(
String
s
:
logs
)
{
writer
.
write
(
s
);
writer
.
write
(
'\n'
);
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Calendar
now
=
Calendar
.
getInstance
();
String
filename
=
String
.
format
(
Locale
.
US
,
"magisk_install_log_%04d%02d%02d_%02d%02d%02d.log"
,
now
.
get
(
Calendar
.
YEAR
),
now
.
get
(
Calendar
.
MONTH
)
+
1
,
now
.
get
(
Calendar
.
DAY_OF_MONTH
),
now
.
get
(
Calendar
.
HOUR_OF_DAY
),
now
.
get
(
Calendar
.
MINUTE
),
now
.
get
(
Calendar
.
SECOND
));
File
logFile
=
new
File
(
Download
.
EXTERNAL_PATH
,
filename
);
try
(
FileWriter
writer
=
new
FileWriter
(
logFile
))
{
for
(
String
s
:
logs
)
{
writer
.
write
(
s
);
writer
.
write
(
'\n'
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
;
}
Utils
.
toast
(
logFile
.
getPath
(),
Toast
.
LENGTH_LONG
);
Utils
.
toast
(
logFile
.
getPath
(),
Toast
.
LENGTH_LONG
);
});
}
@Override
...
...
@@ -158,7 +159,7 @@ public class FlashActivity extends BaseActivity {
@Override
protected
void
onPostExecute
(
Integer
result
)
{
if
(
result
==
1
)
{
new
Handler
()
.
postDelayed
(()
->
Data
.
mainHandler
.
postDelayed
(()
->
RootUtils
.
uninstallPkg
(
getActivity
().
getPackageName
()),
3000
);
}
else
{
super
.
onPostExecute
(
result
);
...
...
app/src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
View file @
9bbfcf32
...
...
@@ -108,16 +108,15 @@ public class MagiskLogFragment extends BaseFragment {
now
.
get
(
Calendar
.
DAY_OF_MONTH
),
now
.
get
(
Calendar
.
HOUR_OF_DAY
),
now
.
get
(
Calendar
.
MINUTE
),
now
.
get
(
Calendar
.
SECOND
));
File
targetFile
=
new
File
(
Download
.
EXTERNAL_PATH
+
"/logs"
,
filename
);
targetFile
.
getParentFile
().
mkdirs
();
File
logFile
=
new
File
(
Download
.
EXTERNAL_PATH
,
filename
);
try
{
target
File
.
createNewFile
();
log
File
.
createNewFile
();
}
catch
(
IOException
e
)
{
return
;
}
Shell
.
su
(
"cat "
+
Const
.
MAGISK_LOG
+
" > "
+
target
File
)
Shell
.
su
(
"cat "
+
Const
.
MAGISK_LOG
+
" > "
+
log
File
)
.
submit
(
result
->
SnackbarMaker
.
make
(
txtLog
,
target
File
.
getPath
(),
Snackbar
.
LENGTH_SHORT
).
show
());
SnackbarMaker
.
make
(
txtLog
,
log
File
.
getPath
(),
Snackbar
.
LENGTH_SHORT
).
show
());
}
public
void
clearLogs
()
{
...
...
app/src/full/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
9bbfcf32
...
...
@@ -100,16 +100,15 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
new
MarkDownWindow
((
BaseActivity
)
context
,
null
,
repo
.
getDetailUrl
()).
exec
());
holder
.
downloadImage
.
setOnClickListener
(
v
->
{
String
filename
=
repo
.
getName
()
+
"-"
+
repo
.
getVersion
()
+
".zip"
;
new
CustomAlertDialog
((
BaseActivity
)
context
)
.
setTitle
(
context
.
getString
(
R
.
string
.
repo_install_title
,
repo
.
getName
()))
.
setMessage
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
filename
))
.
setMessage
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
repo
.
getDownloadFilename
()
))
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
new
ProcessRepoZip
((
BaseActivity
)
context
,
repo
.
getZipUrl
(),
filename
,
true
).
exec
()
new
ProcessRepoZip
((
BaseActivity
)
context
,
repo
,
true
).
exec
()
)
.
setNeutralButton
(
R
.
string
.
download
,
(
d
,
i
)
->
new
ProcessRepoZip
((
BaseActivity
)
context
,
repo
.
getZipUrl
(),
filename
,
false
).
exec
())
new
ProcessRepoZip
((
BaseActivity
)
context
,
repo
,
false
).
exec
())
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
show
();
});
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
View file @
9bbfcf32
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.net.Uri
;
...
...
@@ -15,7 +14,6 @@ import com.topjohnwu.magisk.Data;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.BaseActivity
;
import
com.topjohnwu.magisk.container.TarEntry
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.Utils
;
...
...
@@ -79,11 +77,6 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
bootUri
=
boot
;
}
@Override
protected
BaseActivity
getActivity
()
{
return
(
BaseActivity
)
super
.
getActivity
();
}
@Override
protected
void
onPreExecute
()
{
if
(
mode
==
FIX_ENV_MODE
)
{
...
...
@@ -137,10 +130,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
}
private
void
extractFiles
(
String
arch
)
throws
IOException
{
String
filename
=
Utils
.
fmt
(
"Magisk-v%s(%d).zip"
,
Data
.
remoteMagiskVersionString
,
Data
.
remoteMagiskVersionCode
);
File
zip
=
new
File
(
Download
.
EXTERNAL_PATH
,
filename
);
zip
.
getParentFile
().
mkdirs
();
File
zip
=
new
File
(
mm
.
getFilesDir
(),
"magisk.zip"
);
BufferedInputStream
buf
;
if
(!
ShellUtils
.
checkSum
(
"MD5"
,
zip
,
Data
.
magiskMD5
))
{
...
...
@@ -404,10 +394,4 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
activity
.
buttonPanel
.
setVisibility
(
View
.
VISIBLE
);
}
}
@Override
public
void
exec
(
Void
...
voids
)
{
getActivity
().
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
super
::
exec
);
}
}
app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
9bbfcf32
...
...
@@ -4,15 +4,16 @@ import android.Manifest;
import
android.app.ProgressDialog
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Handler
;
import
android.support.annotation.NonNull
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.BaseActivity
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.container.Repo
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
...
...
@@ -38,17 +39,15 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
private
ProgressDialog
progressDialog
;
private
boolean
mInstall
;
private
String
mLink
;
private
File
mFile
;
private
Repo
mRepo
;
private
int
progress
=
0
,
total
=
-
1
;
private
Handler
mHandler
;
public
ProcessRepoZip
(
BaseActivity
context
,
String
link
,
String
filename
,
boolean
install
)
{
public
ProcessRepoZip
(
BaseActivity
context
,
Repo
repo
,
boolean
install
)
{
super
(
context
);
mLink
=
link
;
mFile
=
new
File
(
Download
.
EXTERNAL_PATH
,
Download
.
getLegalFilename
(
filename
));
mInstall
=
install
;
mHandler
=
new
Handler
();
mRepo
=
repo
;
mInstall
=
install
&&
Shell
.
rootAccess
();
mFile
=
new
File
(
Download
.
EXTERNAL_PATH
,
repo
.
getDownloadFilename
());
}
private
void
removeTopFolder
(
File
input
,
File
output
)
throws
IOException
{
...
...
@@ -93,7 +92,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
if
(
activity
==
null
)
return
null
;
try
{
// Request zip from Internet
HttpURLConnection
conn
=
WebService
.
mustRequest
(
m
Link
,
null
);
HttpURLConnection
conn
=
WebService
.
mustRequest
(
m
Repo
.
getZipUrl
()
,
null
);
total
=
conn
.
getContentLength
();
// Temp files
...
...
@@ -111,7 +110,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
}
conn
.
disconnect
();
m
Handler
.
post
(()
->
{
Data
.
main
Handler
.
post
(()
->
{
progressDialog
.
setTitle
(
R
.
string
.
zip_process_title
);
progressDialog
.
setMessage
(
getActivity
().
getString
(
R
.
string
.
zip_process_msg
));
});
...
...
@@ -140,7 +139,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
progressDialog
.
dismiss
();
if
(
result
)
{
Uri
uri
=
Uri
.
fromFile
(
mFile
);
if
(
Shell
.
rootAccess
()
&&
mInstall
)
{
if
(
mInstall
)
{
Intent
intent
=
new
Intent
(
activity
,
FlashActivity
.
class
);
intent
.
setData
(
uri
).
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
FLASH_ZIP
);
activity
.
startActivity
(
intent
);
...
...
@@ -175,7 +174,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
public
synchronized
int
read
()
throws
IOException
{
int
b
=
super
.
read
();
if
(
b
>
0
)
{
m
Handler
.
post
(()
->
updateDlProgress
(
1
));
Data
.
main
Handler
.
post
(()
->
updateDlProgress
(
1
));
}
return
b
;
}
...
...
@@ -189,7 +188,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
public
synchronized
int
read
(
@NonNull
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
read
=
super
.
read
(
b
,
off
,
len
);
if
(
read
>
0
)
{
m
Handler
.
post
(()
->
updateDlProgress
(
read
));
Data
.
main
Handler
.
post
(()
->
updateDlProgress
(
read
));
}
return
read
;
}
...
...
app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java
View file @
9bbfcf32
...
...
@@ -19,7 +19,7 @@ import java.util.List;
class
InstallMethodDialog
extends
AlertDialog
.
Builder
{
InstallMethodDialog
(
BaseActivity
activity
,
List
<
String
>
options
,
String
filename
)
{
InstallMethodDialog
(
BaseActivity
activity
,
List
<
String
>
options
)
{
super
(
activity
);
setTitle
(
R
.
string
.
select_method
);
setItems
(
options
.
toArray
(
new
String
[
0
]),
(
dialog
,
idx
)
->
{
...
...
@@ -45,6 +45,8 @@ class InstallMethodDialog extends AlertDialog.Builder {
});
break
;
case
0
:
String
filename
=
Utils
.
fmt
(
"Magisk-v%s(%d).zip"
,
Data
.
remoteMagiskVersionString
,
Data
.
remoteMagiskVersionCode
);
Download
.
receive
(
activity
,
new
DownloadReceiver
()
{
@Override
public
void
onDownloadDone
(
Context
context
,
Uri
uri
)
{
...
...
app/src/full/java/com/topjohnwu/magisk/components/MagiskInstallDialog.java
View file @
9bbfcf32
...
...
@@ -34,7 +34,7 @@ public class MagiskInstallDialog extends CustomAlertDialog {
if
(!
s
.
isEmpty
()
&&
Boolean
.
parseBoolean
(
s
))
{
options
.
add
(
mm
.
getString
(
R
.
string
.
install_inactive_slot
));
}
new
InstallMethodDialog
(
activity
,
options
,
filename
).
show
();
new
InstallMethodDialog
(
activity
,
options
).
show
();
});
setNegativeButton
(
R
.
string
.
no_thanks
,
null
);
if
(!
TextUtils
.
isEmpty
(
Data
.
magiskNoteLink
))
{
...
...
app/src/full/java/com/topjohnwu/magisk/container/Repo.java
View file @
9bbfcf32
...
...
@@ -4,6 +4,7 @@ import android.content.ContentValues;
import
android.database.Cursor
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
...
...
@@ -82,6 +83,10 @@ public class Repo extends BaseModule {
return
mLastUpdate
;
}
public
String
getDownloadFilename
()
{
return
Download
.
getLegalFilename
(
getName
()
+
"-"
+
getVersion
()
+
".zip"
);
}
public
class
IllegalRepoException
extends
Exception
{
IllegalRepoException
(
String
message
)
{
super
(
message
);
...
...
app/src/main/java/com/topjohnwu/magisk/components/BaseActivity.java
View file @
9bbfcf32
...
...
@@ -12,6 +12,7 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.NoUIActivity
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Download
;
public
abstract
class
BaseActivity
extends
FlavorActivity
{
...
...
@@ -26,6 +27,7 @@ public abstract class BaseActivity extends FlavorActivity {
granted
=
false
;
}
if
(
granted
)
{
Download
.
EXTERNAL_PATH
.
mkdirs
();
callback
.
run
();
}
else
{
// Passed in context should be an activity if not granted, need to show dialog!
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Download.java
View file @
9bbfcf32
...
...
@@ -10,6 +10,7 @@ import android.net.Uri;
import
android.os.Environment
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.BaseActivity
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
...
...
@@ -19,7 +20,11 @@ import java.io.File;
public
class
Download
{
public
static
final
File
EXTERNAL_PATH
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MagiskManager"
);
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
);
static
{
EXTERNAL_PATH
.
mkdirs
();
}
public
static
boolean
isDownloading
=
false
;
...
...
@@ -30,11 +35,7 @@ public class Download {
BaseActivity
.
runWithPermission
(
context
,
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
File
file
=
new
File
(
EXTERNAL_PATH
,
getLegalFilename
(
filename
));
if
((!
file
.
getParentFile
().
exists
()
&&
!
file
.
getParentFile
().
mkdirs
())
||
(
file
.
exists
()
&&
!
file
.
delete
()))
{
return
;
}
file
.
delete
();
Toast
.
makeText
(
context
,
context
.
getString
(
R
.
string
.
downloading_toast
,
filename
),
Toast
.
LENGTH_LONG
).
show
();
...
...
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