|
17 | 17 |
|
18 | 18 | import androidx.appcompat.app.AppCompatActivity; |
19 | 19 | import androidx.core.content.ContextCompat; |
20 | | -import androidx.core.content.FileProvider; |
21 | 20 | import java.util.Locale; |
22 | 21 |
|
23 | 22 | final class OtaController { |
@@ -141,7 +140,7 @@ private void showProgressDialog(OtaUpdateManager.UpdateInfo info, long downloadI |
141 | 140 | activity, |
142 | 141 | activity.getString(R.string.ota_dialog_download_started_message, info.latestVersion), |
143 | 142 | () -> retryDownload(downloadId), |
144 | | - () -> installUpdate(downloadId) |
| 143 | + this::openDownloadsFolder |
145 | 144 | ); |
146 | 145 | progressDialog = handle.dialog; |
147 | 146 | progressDialog.setOnDismissListener(d -> stopProgressWatcher()); |
@@ -293,48 +292,25 @@ private void startVerification(long downloadId, TextView statusView, View instal |
293 | 292 | // Install |
294 | 293 | // ------------------------------------------------------------------------- |
295 | 294 |
|
296 | | - private void installUpdate(long downloadId) { |
| 295 | + private void openDownloadsFolder() { |
297 | 296 | try { |
298 | | - Uri apkUri = resolveInstallApkUri(downloadId); |
299 | | - Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); |
300 | | - installIntent.setData(apkUri); |
301 | | - installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); |
302 | | - installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, false); |
| 297 | + Intent downloadsIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
| 298 | + downloadsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
303 | 299 |
|
304 | 300 | android.content.pm.PackageManager pm = activity.getPackageManager(); |
305 | | - if (pm != null && installIntent.resolveActivity(pm) != null) { |
306 | | - activity.startActivity(installIntent); |
| 301 | + if (pm != null && downloadsIntent.resolveActivity(pm) != null) { |
| 302 | + activity.startActivity(downloadsIntent); |
307 | 303 | return; |
308 | 304 | } |
309 | | - Intent fallback = new Intent(Intent.ACTION_VIEW); |
310 | | - fallback.setDataAndType(apkUri, "application/vnd.android.package-archive"); |
311 | | - fallback.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); |
312 | | - activity.startActivity(fallback); |
| 305 | + throw new IllegalStateException("Downloads app not available"); |
313 | 306 | } catch (Exception e) { |
314 | 307 | OtaDialogs.showMessageDialog( |
315 | 308 | activity, |
316 | | - activity.getString(R.string.ota_dialog_install_failed_message, e.getClass().getSimpleName()) |
| 309 | + activity.getString(R.string.ota_dialog_open_downloads_failed_message, e.getClass().getSimpleName()) |
317 | 310 | ); |
318 | 311 | } |
319 | 312 | } |
320 | 313 |
|
321 | | - private Uri resolveInstallApkUri(long downloadId) throws Exception { |
322 | | - Uri downloadedUri = resolveDownloadedApkUri(downloadId); |
323 | | - if (downloadedUri != null && !"file".equalsIgnoreCase(downloadedUri.getScheme())) { |
324 | | - return downloadedUri; |
325 | | - } |
326 | | - |
327 | | - java.io.File apkFile = resolveDownloadedApkFile(downloadId); |
328 | | - if (apkFile == null || !apkFile.exists()) { |
329 | | - throw new IllegalStateException("Downloaded APK not found"); |
330 | | - } |
331 | | - return FileProvider.getUriForFile( |
332 | | - activity, |
333 | | - BuildConfig.APPLICATION_ID + ".fileprovider", |
334 | | - apkFile |
335 | | - ); |
336 | | - } |
337 | | - |
338 | 314 | private java.io.File resolveDownloadedApkFile(long downloadId) throws Exception { |
339 | 315 | DownloadManager dm = activity.getSystemService(DownloadManager.class); |
340 | 316 | if (dm == null) return null; |
|
0 commit comments