1
0
forked from firka/firka

android: copy device build info

When start up the app attempt to fetch the device's build info (like model name, android version name and sdk number), if it fails or the user is on iOS fall back to a placeholder value
This commit is contained in:
2025-08-23 15:36:40 +02:00
parent d9d79e760d
commit 94ca5f4edc
4 changed files with 56 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package app.firka.naplo
import android.content.ComponentName
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import io.flutter.embedding.android.FlutterActivity
@@ -32,6 +33,11 @@ class MainActivity : FlutterActivity() {
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler {
call, result ->
when (call.method) {
"get_info" -> {
result.success("${Build.MODEL};" +
"${Build.VERSION.RELEASE};" +
"${Build.VERSION.SDK_INT}")
}
"set_icon" -> {
try {
val pn = context.packageName

View File

@@ -2,10 +2,16 @@ import 'dart:convert';
import 'dart:math';
import 'package:crypto/crypto.dart';
import 'package:firka/main.dart';
class Constants {
static const clientId = "kreta-ellenorzo-student-mobile-android";
static const userAgent = "hu.ekreta.student/5.7.0/SM-A705FN/11/30";
static const applicationId = "hu.ekreta.student";
static const applicationVersion = "5.7.0";
static String userAgent = "$applicationId/$applicationVersion"
"/${initData.devInfo.model}"
"/${initData.devInfo.versionRelease}"
"/${initData.devInfo.versionSdkInt}";
}
class KretaEndpoints {

View File

@@ -6,7 +6,7 @@ import '../../main.dart';
import 'consts.dart';
Future<TokenGrantResponse> getAccessToken(String code) async {
final headers = const <String, String>{
final headers = <String, String>{
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"accept": "*/*",
"user-agent": Constants.userAgent,
@@ -40,7 +40,7 @@ Future<TokenGrantResponse> getAccessToken(String code) async {
}
Future<TokenGrantResponse> extendToken(TokenModel model) async {
final headers = const <String, String>{
final headers = <String, String>{
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"accept": "*/*",
"user-agent": Constants.userAgent,

View File

@@ -39,8 +39,24 @@ late AppInitialization initData;
final dio = Dio();
class DeviceInfo {
String model;
String versionRelease;
String versionSdkInt;
DeviceInfo(this.model, this.versionRelease, this.versionSdkInt);
@override
String toString() {
return "DeviceInfo(model = \"$model\", versionRelease = \"$versionRelease\""
", versionSdkInt = \"$versionSdkInt\"";
}
}
class AppInitialization {
final Isar isar;
final DeviceInfo devInfo;
late KretaClient client;
int tokenCount;
bool hasWatchListener = false;
@@ -50,6 +66,7 @@ class AppInitialization {
AppInitialization({
required this.isar,
required this.devInfo,
required this.tokenCount,
required this.settings,
required this.l10n,
@@ -112,8 +129,32 @@ Future<AppInitialization> initializeApp() async {
print('Token count: $tokenCount');
}
var devInfoFetched = false;
var devInfo = DeviceInfo("SM-A705FN", "11", "30");
try {
if (Platform.isAndroid) {
const channel = MethodChannel("firka.app/main");
final rawInfo =
((await channel.invokeMethod("get_info")) as String).split(";");
devInfo = DeviceInfo(rawInfo[0], rawInfo[1], rawInfo[2]);
devInfoFetched = true;
}
} catch (e) {
if (e is Error) {
debugPrintStack(stackTrace: e.stackTrace, label: e.toString());
} else {
debugPrint(e.toString());
}
}
debugPrint("Fetched device info: ${devInfoFetched ? "yes" : "no"}");
debugPrint("Using device info: ${devInfo.toString()}");
var init = AppInitialization(
isar: isar,
devInfo: devInfo,
tokenCount: tokenCount,
settings: SettingsStore(AppLocalizationsHu()),
l10n: AppLocalizationsHu(),