Allow correcting inferred IDs (#103)

This commit is contained in:
Imran Remtulla
2023-06-23 11:52:49 -04:00
parent e0c4ec5028
commit 423ba07fad
4 changed files with 26 additions and 12 deletions

View File

@@ -56,7 +56,7 @@ class InstallError extends ObtainiumError {
} }
class IDChangedError extends ObtainiumError { class IDChangedError extends ObtainiumError {
IDChangedError() : super(tr('appIdMismatch')); IDChangedError(String newId) : super('${tr('appIdMismatch')} - $newId');
} }
class NotImplementedError extends ObtainiumError { class NotImplementedError extends ObtainiumError {

View File

@@ -329,7 +329,8 @@ class _AppPageState extends State<AppPage> {
try { try {
HapticFeedback.heavyImpact(); HapticFeedback.heavyImpact();
var res = await appsProvider.downloadAndInstallLatestApps( var res = await appsProvider.downloadAndInstallLatestApps(
[app!.app.id], globalNavigatorKey.currentContext); app?.app.id != null ? [app!.app.id] : [],
globalNavigatorKey.currentContext);
if (res.isNotEmpty && mounted) { if (res.isNotEmpty && mounted) {
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
@@ -426,8 +427,10 @@ class _AppPageState extends State<AppPage> {
onPressed: app?.downloadProgress != null onPressed: app?.downloadProgress != null
? null ? null
: () { : () {
appsProvider.removeAppsWithModal( appsProvider
context, [app!.app]).then((value) { .removeAppsWithModal(
context, app != null ? [app.app] : [])
.then((value) {
if (value == true) { if (value == true) {
Navigator.of(context).pop(); Navigator.of(context).pop();
} }

View File

@@ -202,16 +202,18 @@ class AppsProvider with ChangeNotifier {
// The former case should be handled (give the App its real ID), the latter is a security issue // The former case should be handled (give the App its real ID), the latter is a security issue
if (app.id != newInfo.packageName) { if (app.id != newInfo.packageName) {
var isTempId = SourceProvider().isTempId(app); var isTempId = SourceProvider().isTempId(app);
if (apps[app.id] != null && !isTempId) { if (apps[app.id] != null && !isTempId && !app.allowIdChange) {
throw IDChangedError(); throw IDChangedError(newInfo.packageName);
} }
var idChangeWasAllowed = app.allowIdChange;
app.allowIdChange = false;
var originalAppId = app.id; var originalAppId = app.id;
app.id = newInfo.packageName; app.id = newInfo.packageName;
downloadedFile = downloadedFile.renameSync( downloadedFile = downloadedFile.renameSync(
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}'); '${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
if (apps[originalAppId] != null) { if (apps[originalAppId] != null) {
await removeApps([originalAppId]); await removeApps([originalAppId]);
await saveApps([app], onlyIfExists: !isTempId); await saveApps([app], onlyIfExists: !isTempId && !idChangeWasAllowed);
} }
} }
return downloadedFile; return downloadedFile;

View File

@@ -163,6 +163,7 @@ class App {
late DateTime? releaseDate; late DateTime? releaseDate;
late String? changeLog; late String? changeLog;
late String? overrideSource; late String? overrideSource;
bool allowIdChange = false;
App( App(
this.id, this.id,
this.url, this.url,
@@ -178,7 +179,8 @@ class App {
{this.categories = const [], {this.categories = const [],
this.releaseDate, this.releaseDate,
this.changeLog, this.changeLog,
this.overrideSource}); this.overrideSource,
this.allowIdChange = false});
@override @override
String toString() { String toString() {
@@ -209,7 +211,8 @@ class App {
categories: categories, categories: categories,
changeLog: changeLog, changeLog: changeLog,
releaseDate: releaseDate, releaseDate: releaseDate,
overrideSource: overrideSource); overrideSource: overrideSource,
allowIdChange: allowIdChange);
factory App.fromJson(Map<String, dynamic> json) { factory App.fromJson(Map<String, dynamic> json) {
json = appJSONCompatibilityModifiers(json); json = appJSONCompatibilityModifiers(json);
@@ -241,7 +244,8 @@ class App {
: DateTime.fromMicrosecondsSinceEpoch(json['releaseDate']), : DateTime.fromMicrosecondsSinceEpoch(json['releaseDate']),
changeLog: changeLog:
json['changeLog'] == null ? null : json['changeLog'] as String, json['changeLog'] == null ? null : json['changeLog'] as String,
overrideSource: json['overrideSource']); overrideSource: json['overrideSource'],
allowIdChange: json['allowIdChange'] ?? false);
} }
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
@@ -259,7 +263,8 @@ class App {
'categories': categories, 'categories': categories,
'releaseDate': releaseDate?.microsecondsSinceEpoch, 'releaseDate': releaseDate?.microsecondsSinceEpoch,
'changeLog': changeLog, 'changeLog': changeLog,
'overrideSource': overrideSource 'overrideSource': overrideSource,
'allowIdChange': allowIdChange
}; };
} }
@@ -613,7 +618,11 @@ class SourceProvider {
categories: currentApp?.categories ?? const [], categories: currentApp?.categories ?? const [],
releaseDate: apk.releaseDate, releaseDate: apk.releaseDate,
changeLog: apk.changeLog, changeLog: apk.changeLog,
overrideSource: overrideSource ?? currentApp?.overrideSource); overrideSource: overrideSource ?? currentApp?.overrideSource,
allowIdChange: currentApp?.allowIdChange ??
source.appIdInferIsOptional &&
inferAppIdIfOptional // Optional ID inferring may be incorrect - allow correction on first install
);
} }
// Returns errors in [results, errors] instead of throwing them // Returns errors in [results, errors] instead of throwing them