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
0e239354
Commit
0e239354
authored
Sep 01, 2016
by
d8ahazard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some internets!
WIP, not done yet.
parent
4f62320e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
326 additions
and
5 deletions
+326
-5
ModulesAdapter.java
app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java
+1
-0
ModulesFragment.java
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
+20
-5
Module.java
app/src/main/java/com/topjohnwu/magisk/module/Module.java
+19
-0
ModuleRepo.java
...src/main/java/com/topjohnwu/magisk/module/ModuleRepo.java
+170
-0
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+11
-0
WebRequest.java
app/src/main/java/com/topjohnwu/magisk/utils/WebRequest.java
+105
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java
View file @
0e239354
...
@@ -10,6 +10,7 @@ import android.widget.ImageView;
...
@@ -10,6 +10,7 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.ModuleRepo
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
...
...
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
View file @
0e239354
...
@@ -12,6 +12,7 @@ import android.support.v4.app.Fragment;
...
@@ -12,6 +12,7 @@ import android.support.v4.app.Fragment;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentPagerAdapter
;
import
android.support.v4.app.FragmentPagerAdapter
;
import
android.support.v4.view.ViewPager
;
import
android.support.v4.view.ViewPager
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuInflater
;
...
@@ -21,14 +22,12 @@ import android.view.ViewGroup;
...
@@ -21,14 +22,12 @@ import android.view.ViewGroup;
import
android.widget.ProgressBar
;
import
android.widget.ProgressBar
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.
utils.Shell
;
import
com.topjohnwu.magisk.
module.ModuleRepo
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ExecutionException
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
...
@@ -37,6 +36,7 @@ public class ModulesFragment extends Fragment {
...
@@ -37,6 +36,7 @@ public class ModulesFragment extends Fragment {
public
static
List
<
Module
>
listModules
=
new
ArrayList
<>();
public
static
List
<
Module
>
listModules
=
new
ArrayList
<>();
public
static
List
<
Module
>
listModulesCache
=
new
ArrayList
<>();
public
static
List
<
Module
>
listModulesCache
=
new
ArrayList
<>();
public
static
List
<
Module
>
listModulesDownload
=
new
ArrayList
<>();
private
static
final
int
FILE_SELECT_CODE
=
0
;
private
static
final
int
FILE_SELECT_CODE
=
0
;
private
File
input
;
private
File
input
;
...
@@ -73,6 +73,7 @@ public class ModulesFragment extends Fragment {
...
@@ -73,6 +73,7 @@ public class ModulesFragment extends Fragment {
});
});
}
}
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
...
@@ -95,6 +96,7 @@ public class ModulesFragment extends Fragment {
...
@@ -95,6 +96,7 @@ public class ModulesFragment extends Fragment {
case
R
.
id
.
force_reload
:
case
R
.
id
.
force_reload
:
listModules
.
clear
();
listModules
.
clear
();
listModulesCache
.
clear
();
listModulesCache
.
clear
();
listModulesDownload
.
clear
();
progressBar
.
setVisibility
(
View
.
VISIBLE
);
progressBar
.
setVisibility
(
View
.
VISIBLE
);
viewPager
.
setAdapter
(
new
TabsAdapter
(
getChildFragmentManager
()));
viewPager
.
setAdapter
(
new
TabsAdapter
(
getChildFragmentManager
()));
tabLayout
.
setupWithViewPager
(
viewPager
);
tabLayout
.
setupWithViewPager
(
viewPager
);
...
@@ -123,6 +125,15 @@ public class ModulesFragment extends Fragment {
...
@@ -123,6 +125,15 @@ public class ModulesFragment extends Fragment {
}
}
}
}
public
static
class
DownloadModuleFragment
extends
BaseModuleFragment
{
@Override
protected
List
<
Module
>
listModules
()
{
return
listModulesDownload
;
}
}
private
class
updateUI
extends
AsyncTask
<
Void
,
Void
,
Void
>
{
private
class
updateUI
extends
AsyncTask
<
Void
,
Void
,
Void
>
{
...
@@ -145,7 +156,7 @@ public class ModulesFragment extends Fragment {
...
@@ -145,7 +156,7 @@ public class ModulesFragment extends Fragment {
private
class
TabsAdapter
extends
FragmentPagerAdapter
{
private
class
TabsAdapter
extends
FragmentPagerAdapter
{
String
[]
tabTitles
=
new
String
[]{
String
[]
tabTitles
=
new
String
[]{
getString
(
R
.
string
.
modules
),
getString
(
R
.
string
.
cache_modules
)
getString
(
R
.
string
.
modules
),
getString
(
R
.
string
.
cache_modules
)
,
"Download"
};
};
public
TabsAdapter
(
FragmentManager
fm
)
{
public
TabsAdapter
(
FragmentManager
fm
)
{
...
@@ -166,9 +177,13 @@ public class ModulesFragment extends Fragment {
...
@@ -166,9 +177,13 @@ public class ModulesFragment extends Fragment {
public
Fragment
getItem
(
int
position
)
{
public
Fragment
getItem
(
int
position
)
{
if
(
position
==
0
)
{
if
(
position
==
0
)
{
return
new
NormalModuleFragment
();
return
new
NormalModuleFragment
();
}
else
{
}
else
if
(
position
==
1
)
{
return
new
CacheModuleFragment
();
return
new
CacheModuleFragment
();
}
else
{
Log
.
d
(
"Magisk"
,
"DL Fragment picked here"
);
return
new
DownloadModuleFragment
();
}
}
}
}
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/module/Module.java
View file @
0e239354
...
@@ -74,6 +74,25 @@ public class Module {
...
@@ -74,6 +74,25 @@ public class Module {
}
}
public
Module
(
ModuleRepo
.
Repo
repo
)
{
mName
=
repo
.
getName
();
mVersion
=
repo
.
getVersion
();
mDescription
=
repo
.
getDescription
();
mId
=
"foo"
;
mVersionCode
=
111
;
mEnable
=
true
;
mRemove
=
false
;
}
public
String
getName
()
{
public
String
getName
()
{
return
mName
;
return
mName
;
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/module/ModuleRepo.java
0 → 100644
View file @
0e239354
package
com
.
topjohnwu
.
magisk
.
module
;
import
android.app.ListActivity
;
import
android.content.Context
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.util.Log
;
import
com.topjohnwu.magisk.utils.WebRequest
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
ModuleRepo
{
private
String
[]
result
;
private
static
String
url
=
"https://api.github.com/orgs/Magisk-Modules-Repo/repos"
;
private
static
List
<
Repo
>
repos
=
new
ArrayList
<
Repo
>();
private
static
final
String
TAG_ID
=
"id"
;
private
static
final
String
TAG_NAME
=
"name"
;
private
Context
activityContext
;
public
List
<
Repo
>
listRepos
()
{
MyAsyncTask
asynchTask
=
new
MyAsyncTask
();
Log
.
d
(
"Magisk"
,
"Gitagent init called"
);
asynchTask
.
execute
();
List
<
String
>
out
=
null
;
return
repos
;
}
public
JSONArray
fetchModuleArray
()
{
fetchRepoInfo
();
parseRepoInfo
();
JSONArray
moduleArray
=
enumerateModules
();
return
null
;
}
private
void
fetchRepoInfo
()
{
}
private
void
parseRepoInfo
()
{
}
private
JSONArray
enumerateModules
()
{
JSONArray
enumeratedModules
=
new
JSONArray
();
return
enumeratedModules
;
}
class
MyAsyncTask
extends
AsyncTask
<
String
,
String
,
Void
>
{
@Override
protected
void
onPreExecute
()
{
super
.
onPreExecute
();
}
@Override
protected
Void
doInBackground
(
String
...
params
)
{
Log
.
d
(
"Magisk"
,
"doInBackground running"
);
// Creating service handler class instance
WebRequest
webreq
=
new
WebRequest
();
// Making a request to url and getting response
String
jsonStr
=
webreq
.
makeWebServiceCall
(
url
,
WebRequest
.
GET
);
Log
.
d
(
"Response: "
,
"> "
+
jsonStr
);
try
{
repos
.
clear
();
JSONArray
jsonArray
=
new
JSONArray
(
jsonStr
);
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
name
=
jsonobject
.
getString
(
"name"
);
String
urlString
=
jsonobject
.
getString
(
"html_url"
);
try
{
URL
url
=
new
URL
(
urlString
);
if
(!
name
.
contains
(
"Repo.github.io"
))
{
repos
.
add
(
new
Repo
(
name
,
url
));
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
}
for
(
int
i
=
0
;
i
<
repos
.
size
();
i
++)
{
Repo
repo
=
repos
.
get
(
i
);
Log
.
d
(
"Magisk"
,
repo
.
name
+
" URL: "
+
repo
.
url
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
protected
void
onPostExecute
(
Void
v
)
{
}
// protected void onPostExecute(Void v)
}
//class MyAsyncTask extends AsyncTask<String, String, Void>
protected
void
onPreExecute
()
{
}
public
class
Repo
{
public
String
name
;
public
URL
url
;
public
String
manifest
,
version
,
moduleName
,
moduleDescription
,
moduleAuthor
,
moduleAuthorUrl
;
public
Boolean
usesRoot
,
usesXposed
;
public
Repo
(
String
name
,
URL
url
)
{
this
.
name
=
name
;
this
.
url
=
url
;
this
.
manifest
=
(
"https://raw.githubusercontent.com/Magisk-Modules-Repo/"
+
name
+
"/master/module.json"
);
WebRequest
webreq
=
new
WebRequest
();
// Making a request to url and getting response
String
manifestString
=
webreq
.
makeWebServiceCall
(
manifest
,
WebRequest
.
GET
);
Log
.
d
(
"Magisk"
,
"Inner fetch: "
+
manifestString
);
try
{
JSONObject
jsonobject
=
new
JSONObject
(
manifestString
);
Log
.
d
(
"Magisk"
,
"Object: "
+
jsonobject
.
toString
());
version
=
jsonobject
.
getString
(
"versionCode"
);
moduleName
=
jsonobject
.
getString
(
"moduleName"
);
moduleDescription
=
jsonobject
.
getString
(
"moduleDescription"
);
moduleAuthor
=
jsonobject
.
getString
(
"moduleAuthor"
);
moduleAuthorUrl
=
jsonobject
.
getString
(
"authorUrl"
);
usesRoot
=
Boolean
.
getBoolean
(
jsonobject
.
getString
(
"usesRoot"
));
usesXposed
=
Boolean
.
getBoolean
(
jsonobject
.
getString
(
"usesXposed"
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
Log
.
d
(
"Magisk"
,
"We're in! "
+
" "
+
version
+
" "
+
moduleName
+
" "
+
moduleAuthor
+
" "
+
moduleDescription
+
" "
+
moduleAuthorUrl
);
}
public
String
getName
()
{
return
moduleName
;
}
public
String
getVersion
()
{
return
version
;
}
public
String
getDescription
()
{
return
moduleDescription
;
}
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
0e239354
...
@@ -16,12 +16,14 @@ import android.os.Environment;
...
@@ -16,12 +16,14 @@ import android.os.Environment;
import
android.support.design.widget.Snackbar
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.ModulesFragment
;
import
com.topjohnwu.magisk.ModulesFragment
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.ModuleRepo
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -370,14 +372,23 @@ public class Utils {
...
@@ -370,14 +372,23 @@ public class Utils {
protected
Void
doInBackground
(
Void
...
voids
)
{
protected
Void
doInBackground
(
Void
...
voids
)
{
ModulesFragment
.
listModules
.
clear
();
ModulesFragment
.
listModules
.
clear
();
ModulesFragment
.
listModulesCache
.
clear
();
ModulesFragment
.
listModulesCache
.
clear
();
ModulesFragment
.
listModulesDownload
.
clear
();
List
<
String
>
magisk
=
getModList
(
MAGISK_PATH
);
List
<
String
>
magisk
=
getModList
(
MAGISK_PATH
);
Log
.
d
(
"Magisk"
,
String
.
valueOf
(
magisk
));
List
<
String
>
magiskCache
=
getModList
(
MAGISK_CACHE_PATH
);
List
<
String
>
magiskCache
=
getModList
(
MAGISK_CACHE_PATH
);
ModuleRepo
mr
=
new
ModuleRepo
();
List
<
ModuleRepo
.
Repo
>
magiskRepos
=
mr
.
listRepos
();
for
(
String
mod
:
magisk
)
{
for
(
String
mod
:
magisk
)
{
Log
.
d
(
"Magisk"
,
"Utils, listing modules "
+
mod
);
ModulesFragment
.
listModules
.
add
(
new
Module
(
mod
));
ModulesFragment
.
listModules
.
add
(
new
Module
(
mod
));
}
}
for
(
String
mod
:
magiskCache
)
{
for
(
String
mod
:
magiskCache
)
{
ModulesFragment
.
listModulesCache
.
add
(
new
Module
(
mod
));
ModulesFragment
.
listModulesCache
.
add
(
new
Module
(
mod
));
}
}
for
(
ModuleRepo
.
Repo
repo
:
magiskRepos
)
{
ModulesFragment
.
listModulesDownload
.
add
(
new
Module
(
repo
));
}
return
null
;
return
null
;
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/WebRequest.java
0 → 100644
View file @
0e239354
package
com
.
topjohnwu
.
magisk
.
utils
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.net.ssl.HttpsURLConnection
;
public
class
WebRequest
{
static
String
response
=
null
;
public
final
static
int
GET
=
1
;
public
final
static
int
POST
=
2
;
//Constructor with no parameter
public
WebRequest
()
{
}
/**
* Making web service call
*
* @url - url to make request
* @requestmethod - http request method
*/
public
String
makeWebServiceCall
(
String
url
,
int
requestmethod
)
{
return
this
.
makeWebServiceCall
(
url
,
requestmethod
,
null
);
}
/**
* Making service call
*
* @url - url to make request
* @requestmethod - http request method
* @params - http request params
*/
public
String
makeWebServiceCall
(
String
urladdress
,
int
requestmethod
,
HashMap
<
String
,
String
>
params
)
{
URL
url
;
String
response
=
""
;
try
{
url
=
new
URL
(
urladdress
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
15000
);
conn
.
setConnectTimeout
(
15000
);
conn
.
setDoInput
(
true
);
if
(
requestmethod
==
POST
)
{
conn
.
setRequestMethod
(
"POST"
);
}
else
if
(
requestmethod
==
GET
)
{
conn
.
setRequestMethod
(
"GET"
);
}
if
(
params
!=
null
)
{
OutputStream
os
=
conn
.
getOutputStream
();
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
os
,
"UTF-8"
));
StringBuilder
result
=
new
StringBuilder
();
boolean
first
=
true
;
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
entrySet
())
{
if
(
first
)
first
=
false
;
else
result
.
append
(
"&"
);
result
.
append
(
URLEncoder
.
encode
(
entry
.
getKey
(),
"UTF-8"
));
result
.
append
(
"="
);
result
.
append
(
URLEncoder
.
encode
(
entry
.
getValue
(),
"UTF-8"
));
}
writer
.
write
(
result
.
toString
());
writer
.
flush
();
writer
.
close
();
os
.
close
();
}
int
responseCode
=
conn
.
getResponseCode
();
if
(
responseCode
==
HttpsURLConnection
.
HTTP_OK
)
{
String
line
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
while
((
line
=
br
.
readLine
())
!=
null
)
{
response
+=
line
;
}
}
else
{
response
=
""
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
response
;
}
}
\ No newline at end of file
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