Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Thumbs.db
# Alternative builds
.altbuild

# Mods
# Test stuffs
BedrockTools-main
tntimer-main
tntimer-main
MinecraftAuth
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ android {

dependencies {
implementation project(':minecraft')
implementation project(':minecraft-msftauth')
implementation libs.minecraftauth
implementation libs.commons.httpclient
implementation libs.commons.gson
implementation platform(libs.firebase.bom)
implementation libs.firebase.analytics
implementation libs.firebase.crashlytics
Expand Down
57 changes: 0 additions & 57 deletions app/src/main/java/org/levimc/launcher/core/auth/AuthConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.levimc.launcher.core.auth.storage.XalStorageManager;
import org.levimc.launcher.util.JsonIOUtils;

import java.io.File;
Expand All @@ -21,26 +21,26 @@ public class MsftAccountStore {
public static class MsftAccount {
public String id;
public String msUserId;
public transient String refreshToken;
public String xboxGamertag;
public String minecraftUsername;
public String xuid;
public String xboxAvatarUrl;
public long lastUpdated;
public boolean active;
public String serializedAuthManager;

public MsftAccount() {}

public MsftAccount(String id, String msUserId, String refreshToken, String xboxGamertag, String minecraftUsername, String xuid, String xboxAvatarUrl, long lastUpdated, boolean active) {
public MsftAccount(String id, String msUserId, String xboxGamertag, String minecraftUsername, String xuid, String xboxAvatarUrl, long lastUpdated, boolean active, String serializedAuthManager) {
this.id = id;
this.msUserId = msUserId;
this.refreshToken = refreshToken;
this.xboxGamertag = xboxGamertag;
this.minecraftUsername = minecraftUsername;
this.xuid = xuid;
this.xboxAvatarUrl = xboxAvatarUrl;
this.lastUpdated = lastUpdated;
this.active = active;
this.serializedAuthManager = serializedAuthManager;
}
}

Expand All @@ -49,7 +49,8 @@ public MsftAccount(String id, String msUserId, String refreshToken, String xboxG
private static final Type LIST_TYPE = new TypeToken<List<MsftAccount>>(){}.getType();

private static File getFile(Context ctx) {
File dir = XalStorageManager.getXalDir(ctx);
File dir = new File(ctx.getFilesDir(), "xal");
if (!dir.exists()) dir.mkdirs();
return new File(dir, FILENAME);
}

Expand All @@ -58,12 +59,12 @@ public static synchronized List<MsftAccount> list(Context ctx) {
if (!f.exists()) return new ArrayList<>();
try {
String json = JsonIOUtils.read(f);
if (android.text.TextUtils.isEmpty(json)) return new java.util.ArrayList<>();
java.util.List<MsftAccount> list = GSON.fromJson(json, LIST_TYPE);
return list != null ? list : new java.util.ArrayList<>();
if (TextUtils.isEmpty(json)) return new ArrayList<>();
List<MsftAccount> list = GSON.fromJson(json, LIST_TYPE);
return list != null ? list : new ArrayList<>();
} catch (Exception ex) {
android.util.Log.w("XALExport", "Failed to read " + f.getAbsolutePath(), ex);
return new java.util.ArrayList<>();
Log.w("XALExport", "Failed to read " + f.getAbsolutePath(), ex);
return new ArrayList<>();
}
}

Expand All @@ -72,19 +73,11 @@ private static synchronized void save(Context ctx, List<MsftAccount> list) {
try {
JsonIOUtils.write(f, GSON.toJson(list));
} catch (Exception ex) {
android.util.Log.w("XALExport", "Failed to write " + f.getAbsolutePath(), ex);
Log.w("XALExport", "Failed to write " + f.getAbsolutePath(), ex);
}
}

public static synchronized MsftAccount addOrUpdate(Context ctx, String msUserId, String refreshToken, String gamertag) {
return addOrUpdate(ctx, msUserId, refreshToken, gamertag, null, null);
}

public static synchronized MsftAccount addOrUpdate(Context ctx, String msUserId, String refreshToken, String gamertag, String minecraftUsername, String xuid) {
return addOrUpdate(ctx, msUserId, refreshToken, gamertag, minecraftUsername, xuid, null);
}

public static synchronized MsftAccount addOrUpdate(Context ctx, String msUserId, String refreshToken, String gamertag, String minecraftUsername, String xuid, String avatarUrl) {
public static synchronized MsftAccount addOrUpdate(Context ctx, String msUserId, String gamertag, String minecraftUsername, String xuid, String avatarUrl, String serializedAuthManager) {
List<MsftAccount> list = list(ctx);
MsftAccount target = null;
for (MsftAccount a : list) {
Expand All @@ -93,42 +86,36 @@ public static synchronized MsftAccount addOrUpdate(Context ctx, String msUserId,
}
}
if (target == null) {
target = new MsftAccount(UUID.randomUUID().toString(), msUserId, refreshToken, gamertag, minecraftUsername, xuid, avatarUrl, System.currentTimeMillis(), list.isEmpty());
target = new MsftAccount(UUID.randomUUID().toString(), msUserId, gamertag, minecraftUsername, xuid, avatarUrl, System.currentTimeMillis(), list.isEmpty(), serializedAuthManager);
list.add(target);
} else {
target.refreshToken = refreshToken;
if (!TextUtils.isEmpty(gamertag)) target.xboxGamertag = gamertag;
if (!TextUtils.isEmpty(minecraftUsername)) target.minecraftUsername = minecraftUsername;
if (!TextUtils.isEmpty(xuid)) target.xuid = xuid;
if (!TextUtils.isEmpty(avatarUrl)) target.xboxAvatarUrl = avatarUrl;
if (serializedAuthManager != null) target.serializedAuthManager = serializedAuthManager;
target.lastUpdated = System.currentTimeMillis();
}
save(ctx, list);
org.levimc.launcher.core.auth.storage.XalExporter.exportActiveAccount(ctx);
return target;
}

public static synchronized void remove(Context ctx, String id) {
List<MsftAccount> list = list(ctx);
Iterator<MsftAccount> it = list.iterator();
MsftAccount removed = null;
while (it.hasNext()) {
MsftAccount a = it.next();
if (a.id.equals(id)) {
removed = a;
it.remove();
}
}

if (removed != null && removed.msUserId != null && !removed.msUserId.isEmpty()) {
try {
org.levimc.launcher.core.auth.storage.XalStorageManager.deleteUserDir(ctx, removed.msUserId);
} catch (Exception ignored) {}
}

boolean hasActive = false;
for (MsftAccount a : list) if (a.active) { hasActive = true; break; }
if (!hasActive && !list.isEmpty()) list.get(0).active = true;
save(ctx, list);
org.levimc.launcher.core.auth.storage.XalExporter.exportActiveAccount(ctx);
}

public static synchronized void setActive(Context ctx, String id) {
Expand All @@ -137,6 +124,7 @@ public static synchronized void setActive(Context ctx, String id) {
a.active = a.id.equals(id);
}
save(ctx, list);
org.levimc.launcher.core.auth.storage.XalExporter.exportActiveAccount(ctx);
}

public static synchronized MsftAccount find(Context ctx, String id) {
Expand Down
Loading
Loading