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 {
IDChangedError() : super(tr('appIdMismatch'));
IDChangedError(String newId) : super('${tr('appIdMismatch')} - $newId');
}
class NotImplementedError extends ObtainiumError {

View File

@ -329,7 +329,8 @@ class _AppPageState extends State<AppPage> {
try {
HapticFeedback.heavyImpact();
var res = await appsProvider.downloadAndInstallLatestApps(
[app!.app.id], globalNavigatorKey.currentContext);
app?.app.id != null ? [app!.app.id] : [],
globalNavigatorKey.currentContext);
if (res.isNotEmpty && mounted) {
Navigator.of(context).pop();
}
@ -426,8 +427,10 @@ class _AppPageState extends State<AppPage> {
onPressed: app?.downloadProgress != null
? null
: () {
appsProvider.removeAppsWithModal(
context, [app!.app]).then((value) {
appsProvider
.removeAppsWithModal(
context, app != null ? [app.app] : [])
.then((value) {
if (value == true) {
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
if (app.id != newInfo.packageName) {
var isTempId = SourceProvider().isTempId(app);
if (apps[app.id] != null && !isTempId) {
throw IDChangedError();
if (apps[app.id] != null && !isTempId && !app.allowIdChange) {
throw IDChangedError(newInfo.packageName);
}
var idChangeWasAllowed = app.allowIdChange;
app.allowIdChange = false;
var originalAppId = app.id;
app.id = newInfo.packageName;
downloadedFile = downloadedFile.renameSync(
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
if (apps[originalAppId] != null) {
await removeApps([originalAppId]);
await saveApps([app], onlyIfExists: !isTempId);
await saveApps([app], onlyIfExists: !isTempId && !idChangeWasAllowed);
}
}
return downloadedFile;

View File

@ -163,6 +163,7 @@ class App {
late DateTime? releaseDate;
late String? changeLog;
late String? overrideSource;
bool allowIdChange = false;
App(
this.id,
this.url,
@ -178,7 +179,8 @@ class App {
{this.categories = const [],
this.releaseDate,
this.changeLog,
this.overrideSource});
this.overrideSource,
this.allowIdChange = false});
@override
String toString() {
@ -209,7 +211,8 @@ class App {
categories: categories,
changeLog: changeLog,
releaseDate: releaseDate,
overrideSource: overrideSource);
overrideSource: overrideSource,
allowIdChange: allowIdChange);
factory App.fromJson(Map<String, dynamic> json) {
json = appJSONCompatibilityModifiers(json);
@ -241,7 +244,8 @@ class App {
: DateTime.fromMicrosecondsSinceEpoch(json['releaseDate']),
changeLog:
json['changeLog'] == null ? null : json['changeLog'] as String,
overrideSource: json['overrideSource']);
overrideSource: json['overrideSource'],
allowIdChange: json['allowIdChange'] ?? false);
}
Map<String, dynamic> toJson() => {
@ -259,7 +263,8 @@ class App {
'categories': categories,
'releaseDate': releaseDate?.microsecondsSinceEpoch,
'changeLog': changeLog,
'overrideSource': overrideSource
'overrideSource': overrideSource,
'allowIdChange': allowIdChange
};
}
@ -613,7 +618,11 @@ class SourceProvider {
categories: currentApp?.categories ?? const [],
releaseDate: apk.releaseDate,
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