mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-15 11:28:10 +02:00
Better error for some incompatible APK cases (#981)
This commit is contained in:
@@ -263,25 +263,29 @@ class AppsProvider with ChangeNotifier {
|
|||||||
return downloadedFile;
|
return downloadedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> handleAPKIDChange(App app, PackageInfo newInfo,
|
Future<File> handleAPKIDChange(App app, PackageInfo? newInfo,
|
||||||
File downloadedFile, String downloadUrl) async {
|
File downloadedFile, String downloadUrl) async {
|
||||||
// If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed
|
// If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed
|
||||||
// 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) {
|
var isTempId = SourceProvider().isTempId(app);
|
||||||
var isTempId = SourceProvider().isTempId(app);
|
if (newInfo != null) {
|
||||||
if (apps[app.id] != null && !isTempId && !app.allowIdChange) {
|
if (app.id != newInfo.packageName) {
|
||||||
throw IDChangedError(newInfo.packageName!);
|
if (apps[app.id] != null && !isTempId && !app.allowIdChange) {
|
||||||
}
|
throw IDChangedError(newInfo.packageName!);
|
||||||
var idChangeWasAllowed = app.allowIdChange;
|
}
|
||||||
app.allowIdChange = false;
|
var idChangeWasAllowed = app.allowIdChange;
|
||||||
var originalAppId = app.id;
|
app.allowIdChange = false;
|
||||||
app.id = newInfo.packageName!;
|
var originalAppId = app.id;
|
||||||
downloadedFile = downloadedFile.renameSync(
|
app.id = newInfo.packageName!;
|
||||||
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
|
downloadedFile = downloadedFile.renameSync(
|
||||||
if (apps[originalAppId] != null) {
|
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
|
||||||
await removeApps([originalAppId]);
|
if (apps[originalAppId] != null) {
|
||||||
await saveApps([app], onlyIfExists: !isTempId && !idChangeWasAllowed);
|
await removeApps([originalAppId]);
|
||||||
|
await saveApps([app], onlyIfExists: !isTempId && !idChangeWasAllowed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (isTempId) {
|
||||||
|
throw ObtainiumError('Could not get ID from APK');
|
||||||
}
|
}
|
||||||
return downloadedFile;
|
return downloadedFile;
|
||||||
}
|
}
|
||||||
@@ -344,7 +348,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
await pm.getPackageArchiveInfo(archiveFilePath: apks.first.path);
|
await pm.getPackageArchiveInfo(archiveFilePath: apks.first.path);
|
||||||
}
|
}
|
||||||
downloadedFile =
|
downloadedFile =
|
||||||
await handleAPKIDChange(app, newInfo!, downloadedFile, downloadUrl);
|
await handleAPKIDChange(app, newInfo, downloadedFile, downloadUrl);
|
||||||
// Delete older versions of the file if any
|
// Delete older versions of the file if any
|
||||||
for (var file in downloadedFile.parent.listSync()) {
|
for (var file in downloadedFile.parent.listSync()) {
|
||||||
var fn = file.path.split('/').last;
|
var fn = file.path.split('/').last;
|
||||||
|
Reference in New Issue
Block a user