Skip to content

Commit b9f0ab6

Browse files
manny-jimenezManny Jimenez
andauthored
FAD fixing file provider path bug (#2972)
* fixing file provider path bug * Mimicing functionality that NAUTM uses Co-authored-by: Manny Jimenez <[email protected]>
1 parent 41715ed commit b9f0ab6

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

firebase-app-distribution/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444

4545
<provider
4646
android:name="androidx.core.content.FileProvider"
47-
android:authorities="${applicationId}.provider"
47+
android:authorities="${applicationId}.appdistro.fileprovider"
4848
android:exported="false"
4949
android:grantUriPermissions="true">
5050
<meta-data
5151
android:name="android.support.FILE_PROVIDER_PATHS"
52-
android:resource="@xml/provider_paths" />
52+
android:resource="@xml/appdistro_provider_paths" />
5353
</provider>
5454
</application>
5555
</manifest>

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/InstallActivity.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ protected void onCreate(@NonNull Bundle savedInstanceState) {
4545
String path = originalIntent.getStringExtra("INSTALL_PATH");
4646
Intent intent = new Intent(Intent.ACTION_VIEW);
4747
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
48-
Uri apkUri =
49-
FileProvider.getUriForFile(
50-
getApplicationContext(),
51-
getApplicationContext().getPackageName() + ".provider",
52-
new File(path));
48+
File apkFile = new File(path);
5349
String APK_MIME_TYPE = "application/vnd.android.package-archive";
54-
intent.setDataAndType(apkUri, APK_MIME_TYPE);
55-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
50+
51+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
52+
Uri apkUri =
53+
FileProvider.getUriForFile(
54+
getApplicationContext(),
55+
getApplicationContext().getPackageName() + ".appdistro.fileprovider",
56+
apkFile);
57+
intent.setDataAndType(apkUri, APK_MIME_TYPE);
58+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
59+
} else {
60+
LogWrapper.getInstance().d("Requesting a vanilla URI");
61+
intent.setDataAndType(Uri.fromFile(apkFile), APK_MIME_TYPE);
62+
}
63+
5664
mStartForResult.launch(intent);
5765
}
5866

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/UpdateApkClient.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ private void downloadToDisk(
178178
long bytesDownloaded = 0;
179179
try (BufferedOutputStream outputStream =
180180
new BufferedOutputStream(
181-
firebaseApp.getApplicationContext().openFileOutput(fileName, Context.MODE_PRIVATE))) {
181+
firebaseApp
182+
.getApplicationContext()
183+
.openFileOutput(
184+
fileName,
185+
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N
186+
? Context.MODE_PRIVATE
187+
: Context.MODE_WORLD_READABLE))) {
182188

183189
byte[] data = new byte[8 * 1024];
184190
int readSize = input.read(data);

0 commit comments

Comments
 (0)