1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 11:35:48 +01:00

Fix installing pbw files from different URIs than local files on Firmware 3.x. Fixes #183

This commit is contained in:
Andreas Shimokawa 2015-12-06 17:17:46 +01:00
parent 9ebb320e10
commit 79f92b8495
3 changed files with 27 additions and 3 deletions

View File

@ -1,6 +1,8 @@
###Changelog
####Next Version
* Pebble: fix regression in 0.6.7 when installing pbw/pbz files from content providers (eg. download manager)
* Pebble: fix installation of pbw files on firmware 3.x when using content providers (eg. download manager)
+ Treat Signal notifications as chat notifications
* Fix crash when contacts cannot be read on Android 6.0 (non-granted pemissions)

View File

@ -108,11 +108,10 @@ public class PBWInstallHandler implements InstallHandler {
}
GBDeviceApp app = mPBWReader.getGBDeviceApp();
File pbwFile = new File(mUri.getPath());
try {
File destDir = new File(FileUtils.getExternalFilesDir() + "/pbw-cache");
destDir.mkdirs();
FileUtils.copyFile(pbwFile, new File(destDir + "/" + app.getUUID().toString() + ".pbw"));
FileUtils.copyURItoFile(mContext, mUri, new File(destDir + "/" + app.getUUID().toString() + ".pbw"));
} catch (IOException e) {
LOG.error("Installation failed: " + e.getMessage(), e);
}

View File

@ -1,10 +1,13 @@
package nodomain.freeyourgadget.gadgetbridge.util;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -42,6 +45,25 @@ public class FileUtils {
}
}
public static void copyURItoFile(Context ctx, Uri uri, File destFile) throws IOException {
ContentResolver cr = ctx.getContentResolver();
InputStream fin;
try {
fin = new BufferedInputStream(cr.openInputStream(uri));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
FileOutputStream fout = new FileOutputStream(destFile);
byte[] buf = new byte[4096];
while (fin.available() > 0) {
int bytes = fin.read(buf);
fout.write(buf, 0, bytes);
}
fin.close();
fout.close();
}
/**
* Returns the existing external storage dir. The directory is guaranteed to
* exist and to be writable.
@ -78,9 +100,10 @@ public class FileUtils {
* Returns a list of directories to write to. The list is sorted by priority,
* i.e. the first directory should be preferred, the last one is the least
* preferred one.
*
* <p/>
* Note that the directories may not exist, so it is not guaranteed that you
* can actually write to them. But when created, they *should* be writable.
*
* @return the list of writable directories
* @throws IOException
*/