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
61e2c344
Commit
61e2c344
authored
Jan 11, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove token, use ETag to prevent multiple queries
parent
5363b0f8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
51 deletions
+60
-51
Repo.java
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
+2
-2
Async.java
app/src/main/java/com/topjohnwu/magisk/utils/Async.java
+1
-1
ModuleHelper.java
...rc/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java
+23
-8
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+0
-13
WebService.java
app/src/main/java/com/topjohnwu/magisk/utils/WebService.java
+33
-26
strings.xml
app/src/main/res/values/strings.xml
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
View file @
61e2c344
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Web
Request
;
import
com.topjohnwu.magisk.utils.Web
Service
;
import
java.util.Date
;
...
...
@@ -22,7 +22,7 @@ public class Repo extends BaseModule {
public
void
update
()
throws
CacheModException
{
Logger
.
dev
(
"Repo: Re-fetch prop"
);
String
props
=
Web
Request
.
makeWebServiceCall
(
mManifestUrl
,
WebRequest
.
GET
,
true
);
String
props
=
Web
Service
.
request
(
mManifestUrl
,
WebService
.
GET
,
true
);
String
lines
[]
=
props
.
split
(
"\\n"
);
parseProps
(
lines
);
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Async.java
View file @
61e2c344
...
...
@@ -56,7 +56,7 @@ public class Async {
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
String
jsonStr
=
Web
Request
.
makeWebServiceCall
(
UPDATE_JSON
,
WebRequest
.
GET
);
String
jsonStr
=
Web
Service
.
request
(
UPDATE_JSON
,
WebService
.
GET
);
try
{
JSONObject
json
=
new
JSONObject
(
jsonStr
);
JSONObject
magisk
=
json
.
getJSONObject
(
"magisk"
);
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java
View file @
61e2c344
...
...
@@ -31,6 +31,7 @@ public class ModuleHelper {
private
static
final
String
FILE_KEY
=
"RepoMap"
;
private
static
final
String
REPO_KEY
=
"repomap"
;
private
static
final
String
VERSION_KEY
=
"version"
;
private
static
final
String
ETAG_KEY
=
"ETag"
;
private
static
final
int
DATABASE_VER
=
1
;
private
static
ValueSortedMap
<
String
,
Repo
>
repoMap
=
new
ValueSortedMap
<>();
...
...
@@ -57,10 +58,11 @@ public class ModuleHelper {
public
static
void
createRepoMap
(
Context
context
)
{
Logger
.
dev
(
"ModuleHelper: Loading repos"
);
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
FILE_KEY
,
Context
.
MODE_PRIVATE
);
repoMap
.
clear
();
Gson
gson
=
new
Gson
();
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
FILE_KEY
,
Context
.
MODE_PRIVATE
);
String
jsonString
;
int
cachedVersion
=
prefs
.
getInt
(
VERSION_KEY
,
0
);
...
...
@@ -74,20 +76,31 @@ public class ModuleHelper {
ValueSortedMap
<
String
,
Repo
>
cached
=
null
;
if
(
jsonString
!=
null
)
{
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
ValueSortedMap
<
String
,
Repo
>
>(){}.
getType
());
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
ValueSortedMap
<
String
,
Repo
>
>(){}.
getType
());
}
if
(
cached
==
null
)
{
cached
=
new
ValueSortedMap
<>();
}
// Making a request to url and getting response
jsonString
=
WebRequest
.
makeWebServiceCall
(
context
.
getString
(
R
.
string
.
url_main
),
WebRequest
.
GET
);
// Get cached ETag to add in the request header
String
etag
=
prefs
.
getString
(
ETAG_KEY
,
""
);
HashMap
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"If-None-Match"
,
etag
);
if
(
jsonString
!=
null
&&
!
jsonString
.
isEmpty
())
{
// Have internet access
// Making a request to main URL for repo info
jsonString
=
WebService
.
request
(
context
.
getString
(
R
.
string
.
url_main
),
WebService
.
GET
,
null
,
header
,
false
);
if
(!
jsonString
.
isEmpty
())
{
try
{
JSONArray
jsonArray
=
new
JSONArray
(
jsonString
);
// If it gets to this point, the response is valid, update ETag
etag
=
WebService
.
getLastResponseHeader
().
get
(
ETAG_KEY
).
get
(
0
);
// Maybe bug in Android build tools, sometimes the ETag has crap in it...
etag
=
etag
.
substring
(
etag
.
indexOf
(
'\"'
),
etag
.
lastIndexOf
(
'\"'
)
+
1
);
// Update repo info
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
id
=
jsonobject
.
getString
(
"description"
);
...
...
@@ -106,7 +119,7 @@ public class ModuleHelper {
Logger
.
dev
(
"ModuleHelper: Create new repo "
+
id
);
repo
=
new
Repo
(
context
,
name
,
updatedDate
);
}
else
{
Logger
.
dev
(
"ModuleHelper:
C
ached repo "
+
id
);
Logger
.
dev
(
"ModuleHelper:
Update c
ached repo "
+
id
);
repo
.
update
(
updatedDate
);
}
if
(
repo
.
getId
()
!=
null
)
{
...
...
@@ -118,13 +131,15 @@ public class ModuleHelper {
e
.
printStackTrace
();
}
}
else
{
// Use cached if no internet
// Use cached if no internet or no updates
Logger
.
dev
(
"ModuleHelper: No updates, use cached"
);
repoMap
.
putAll
(
cached
);
}
prefs
.
edit
()
.
putInt
(
VERSION_KEY
,
DATABASE_VER
)
.
putString
(
REPO_KEY
,
gson
.
toJson
(
repoMap
))
.
putString
(
ETAG_KEY
,
etag
)
.
apply
();
Logger
.
dev
(
"ModuleHelper: Repo load done"
);
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
61e2c344
...
...
@@ -10,7 +10,6 @@ import android.net.Uri;
import
android.os.Environment
;
import
android.support.v4.app.ActivityCompat
;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.R
;
...
...
@@ -19,20 +18,8 @@ import com.topjohnwu.magisk.receivers.DownloadReceiver;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.UnsupportedEncodingException
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.spec.InvalidKeySpecException
;
import
java.util.List
;
import
javax.crypto.BadPaddingException
;
import
javax.crypto.Cipher
;
import
javax.crypto.IllegalBlockSizeException
;
import
javax.crypto.NoSuchPaddingException
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.spec.DESKeySpec
;
public
class
Utils
{
public
static
boolean
isDownloading
=
false
;
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Web
Request
.java
→
app/src/main/java/com/topjohnwu/magisk/utils/Web
Service
.java
View file @
61e2c344
...
...
@@ -8,21 +8,17 @@ import java.io.OutputStreamWriter;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.
HashMap
;
import
java.util.
List
;
import
java.util.Map
;
import
javax.net.ssl.HttpsURLConnection
;
public
class
Web
Request
{
public
class
Web
Service
{
static
String
response
=
null
;
public
final
static
int
GET
=
1
;
public
final
static
int
POST
=
2
;
//Constructor with no parameter
public
WebRequest
()
{
}
private
static
Map
<
String
,
List
<
String
>>
responseHeader
;
/**
* Making web service call
...
...
@@ -30,15 +26,12 @@ public class WebRequest {
* @url - url to make request
* @requestmethod - http request method
*/
public
static
String
makeWebServiceCall
(
String
url
,
int
requestmethod
)
{
return
makeWebServiceCall
(
url
,
requestmethod
,
null
,
false
);
public
static
String
request
(
String
url
,
int
method
)
{
return
request
(
url
,
method
,
null
,
null
,
false
);
}
public
static
String
makeWebServiceCall
(
String
url
,
int
requestmethod
,
boolean
addNewLines
)
{
return
makeWebServiceCall
(
url
,
requestmethod
,
null
,
addNewLines
);
public
static
String
request
(
String
url
,
int
method
,
boolean
newline
)
{
return
request
(
url
,
method
,
null
,
null
,
newline
);
}
/**
...
...
@@ -47,26 +40,35 @@ public class WebRequest {
* @url - url to make request
* @requestmethod - http request method
* @params - http request params
* @header - http request header
* @newline - true to append a newline each line
*/
public
static
String
makeWebServiceCall
(
String
urladdress
,
int
requestmethod
,
HashMap
<
String
,
String
>
params
,
boolean
addNewLines
)
{
Logger
.
dev
(
"WebRequest: Service call "
+
urladdress
);
public
static
String
request
(
String
urlAddress
,
int
method
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
header
,
boolean
newline
)
{
Logger
.
dev
(
"WebService: Service call "
+
urlAddress
);
URL
url
;
String
response
=
""
;
String
Builder
response
=
new
StringBuilder
()
;
try
{
url
=
new
URL
(
url
a
ddress
);
url
=
new
URL
(
url
A
ddress
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
15000
);
conn
.
setConnectTimeout
(
15000
);
conn
.
setDoInput
(
true
);
if
(
request
method
==
POST
)
{
if
(
method
==
POST
)
{
conn
.
setRequestMethod
(
"POST"
);
}
else
if
(
request
method
==
GET
)
{
}
else
if
(
method
==
GET
)
{
conn
.
setRequestMethod
(
"GET"
);
}
if
(
header
!=
null
)
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
header
.
entrySet
())
{
conn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
if
(
params
!=
null
)
{
OutputStream
os
=
conn
.
getOutputStream
();
BufferedWriter
writer
=
new
BufferedWriter
(
...
...
@@ -98,20 +100,25 @@ public class WebRequest {
String
line
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
while
((
line
=
br
.
readLine
())
!=
null
)
{
if
(
addNewLines
)
{
response
+=
line
+
"\n"
;
if
(
newline
)
{
response
.
append
(
line
).
append
(
"\n"
)
;
}
else
{
response
+=
line
;
response
.
append
(
line
)
;
}
}
responseHeader
=
conn
.
getHeaderFields
();
}
else
{
response
=
""
;
response
Header
=
null
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
response
;
return
response
.
toString
();
}
public
static
Map
<
String
,
List
<
String
>>
getLastResponseHeader
()
{
return
responseHeader
;
}
}
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
61e2c344
...
...
@@ -111,7 +111,7 @@
<string
name=
"check_release_notes"
>
Check release notes
</string>
<!--URL Templates-->
<string
name=
"url_main"
translatable=
"false"
>
https://api.github.com/orgs/Magisk-Modules-Repo/repos
?access_token=8f3c379fbeb80754b45b02486482584893af142a
</string>
<string
name=
"url_main"
translatable=
"false"
>
https://api.github.com/orgs/Magisk-Modules-Repo/repos
</string>
<string
name=
"file_url"
translatable=
"false"
>
https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s
</string>
<string
name=
"zip_url"
translatable=
"false"
>
https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip
</string>
...
...
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