Skip to content

Commit

Permalink
Fix downloaded apk URI resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
threethan committed Feb 12, 2024
1 parent 15537f2 commit 93b71f0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
11 changes: 11 additions & 0 deletions Launcher/App/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@

<meta-data android:name="com.oculus.supportedDevices" android:value="all"/>

<!-- Required for resolving URIs for APK installation -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

<!-- Main activity, called by the launcher & shortcut apk (Quest) -->
<activity
android:name=".launcher.LauncherActivitySearchable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void storeLatestVersionAndPromptUpdate(String newVersionName) {
Log.i(TAG, "App is up to date :)");
updateAvailable = false;
// Clear downloaded APKs
FileLib.delete(activity.getCacheDir()+APK_FOLDER);
FileLib.delete(activity.getExternalCacheDir()+"/"+APK_FOLDER);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
*/
public class RemotePackageUpdater {
/**
* The id of the provider which implements/has the name of
* The 'android:authority' of the provider which implements/has the name of
* "android.support.v4.content.FileProvider"
* The package name is included automatically, so typically this will be "provider" -
* referring to "android:authorities="${applicationId}.provider"" in the manifest;
* but may be different if a library uses a similar provider.
* <p>
* This is the only application-specific parameter in this class
* (The package name is prepended automatically)
*/
private static final String PROVIDER = "imagepicker.provider";
private static final String PROVIDER = /*packageName +*/".fileprovider";

/**
* Stores information for a package which may be downloaded using RemotePackageUpdater
Expand Down Expand Up @@ -77,9 +73,9 @@ public String toString() {
protected static final String TAG = "Remote Package Updater";

/**
* Temp directory for downloaded apks (May be cleared unexpectedly0
* Temp directory for downloaded apks in external cache dir., may be cleared unexpectedly
*/
public static final String APK_FOLDER = "TemporaryDownloadedApk";
public static final String APK_FOLDER = "downloadedApk";
protected final PackageManager packageManager;
protected final Activity activity;

Expand Down Expand Up @@ -110,7 +106,7 @@ protected void downloadPackage(RemotePackage remotePackage) {
request.setTitle("Lightning Launcher Auto-Updater");

final String apkFileName = remotePackage+remotePackage.latestVersion+".apk";
final File apkFile = new File(activity.getExternalCacheDir()+APK_FOLDER, apkFileName);
final File apkFile = new File(activity.getExternalCacheDir()+"/"+APK_FOLDER, apkFileName);

FileLib.delete(apkFile.getParent());

Expand All @@ -125,8 +121,8 @@ protected void downloadPackage(RemotePackage remotePackage) {
updateDialogBuilder.setTitle(activity.getString(R.string.update_downloading_title, remotePackage));
updateDialogBuilder.setMessage(R.string.update_downloading_content);
updateDialogBuilder.setNegativeButton(R.string.update_hide_button, (dialog, which) -> dialog.cancel());
updateDialogBuilder.show();
downloadingDialog = updateAlertDialog;
updateDialogBuilder.setOnDismissListener(d -> downloadingDialog = null);
downloadingDialog = updateDialogBuilder.show();
} catch (Exception ignored) {} // May rarely fail if window is invalid
}

Expand All @@ -136,7 +132,7 @@ protected void downloadPackage(RemotePackage remotePackage) {
activity.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (updateAlertDialog != null) updateAlertDialog.dismiss();
if (downloadingDialog != null) downloadingDialog.dismiss();
installApk(apkFile);
activity.unregisterReceiver(this);
}
Expand All @@ -145,7 +141,6 @@ public void onReceive(Context context, Intent intent) {
// Start the download
manager.enqueue(request);
}
AlertDialog updateAlertDialog;

/**
* Installs an apk from a file. May be called externally.
Expand All @@ -156,9 +151,8 @@ public void onReceive(Context context, Intent intent) {
public void installApk(File apkFile) {
Log.v(TAG, "Installing from apk at "+apkFile.getAbsolutePath());
if (apkFile.exists()) {
// provider is already included in the imagepicker lib
Uri apkURI = FileProvider.getUriForFile(activity,
activity.getApplicationContext().getPackageName() + "." + PROVIDER,
activity.getApplicationContext().getPackageName() + PROVIDER,
apkFile);
Intent intent = new Intent(Intent.ACTION_VIEW);

Expand Down
5 changes: 5 additions & 0 deletions Launcher/App/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths><external-cache-path
name="DownloadedApks"
path="downloadedApk"/>
</paths>

0 comments on commit 93b71f0

Please sign in to comment.