Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 36ad771

Browse files
committed
Support newest Androidacy API.
1 parent 4a9db36 commit 36ad771

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737
public class AndroidacyActivity extends CompatActivity {
3838
private static final String TAG = "AndroidacyActivity";
39-
private static final String REFERRER = "utm_source=FoxMMM&utm_medium=app";
4039

4140
static {
4241
if (BuildConfig.DEBUG) {
@@ -71,12 +70,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
7170
this.forceBackPressed();
7271
return;
7372
}
74-
if (!url.endsWith(REFERRER) && (url.startsWith("https://www.androidacy.com/") ||
75-
url.startsWith("https://api.androidacy.com/magisk/"))) {
73+
if (!url.endsWith(AndroidacyUtil.REFERRER)) {
7674
if (url.lastIndexOf('/') < url.lastIndexOf('?')) {
77-
url = url + '&' + REFERRER;
75+
url = url + '&' + AndroidacyUtil.REFERRER;
7876
} else {
79-
url = url + '?' + REFERRER;
77+
url = url + '?' + AndroidacyUtil.REFERRER;
8078
}
8179
}
8280
boolean allowInstall = intent.getBooleanExtra(

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected boolean prepare() {
7474
if (this.androidacyBlockade > time) return false;
7575
this.androidacyBlockade = time + 30_000L;
7676
String cookies = AndroidacyRepoData.getCookies();
77-
int start = cookies == null ? -1 : cookies.indexOf("USER=");
77+
int start = cookies == null ? -1 : cookies.indexOf("USER=") + 5;
7878
String token = null;
7979
if (start != -1) {
8080
int end = cookies.indexOf(";", start);
@@ -184,6 +184,8 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
184184
repoModule.notesUrl = // Fallback url in case the API doesn't have notesUrl
185185
"https://api.androidacy.com/magisk/readme/?module=" + moduleId;
186186
}
187+
repoModule.zipUrl = this.injectToken(repoModule.zipUrl);
188+
repoModule.notesUrl = this.injectToken(repoModule.notesUrl);
187189
repoModule.qualityText = R.string.module_downloads;
188190
repoModule.qualityValue = jsonObject.optInt("downloads", 0);
189191
String checksum = jsonObject.optString("checksum", "");
@@ -211,6 +213,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
211213
moduleInfo.minMagisk = 0;
212214
}
213215
moduleInfo.needRamdisk = jsonObject.optBoolean("needRamdisk", false);
216+
moduleInfo.changeBoot = jsonObject.optBoolean("changeBoot", false);
214217
moduleInfo.support = filterURL(jsonObject.optString("support"));
215218
moduleInfo.donate = filterURL(jsonObject.optString("donate"));
216219
String config = jsonObject.optString("config", "");
@@ -258,4 +261,19 @@ public String getUrl() {
258261
return this.token == null ? this.url :
259262
this.url + "?token=" + this.token;
260263
}
264+
265+
private String injectToken(String url) {
266+
// Do not inject token for non Androidacy urls
267+
if (!AndroidacyUtil.isAndroidacyLink(url))
268+
return url;
269+
String token = "token=" + this.token;
270+
if (!url.contains(token)) {
271+
if (url.lastIndexOf('/') < url.lastIndexOf('?')) {
272+
return url + '&' + token;
273+
} else {
274+
return url + '?' + token;
275+
}
276+
}
277+
return url;
278+
}
261279
}

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import androidx.annotation.Nullable;
77

88
public class AndroidacyUtil {
9+
public static final String REFERRER = "utm_source=FoxMMM&utm_medium=app";
10+
911
public static boolean isAndroidacyLink(@Nullable Uri uri) {
1012
return uri != null && isAndroidacyLink(uri.toString(), uri);
1113
}

0 commit comments

Comments
 (0)