-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New, overhauled data storage management #1954
Conversation
|
||
String keyPath = getAppContext().getFilesDir().getAbsolutePath() + | ||
File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair"; | ||
File privateKey = new File(keyPath + File.separator + "push_key.priv"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equivalent of: File privateKey = new File(keyPath, "push_key.priv");
same for the line up and down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be so kind to improve in the branch directly all things you think need improving? :)
File publicKey = new File(keyPath + File.separator + "push_key.pub"); | ||
|
||
if (oldPrivateKey.exists() && oldPublicKey.exists()) { | ||
if (oldPrivateKey.renameTo(privateKey) && oldPublicKey.renameTo(publicKey)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't handle the scenario when first rename succeeds and other fails.
} | ||
// Add private internal storage data directory. | ||
result.add(new StoragePoint(defaultStringDesc, | ||
MainApp.getAppContext().getFilesDir().getAbsolutePath())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of this storage point using context. IMO there should be a method in MainApp
which directly returns the files dir and use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we use this at a couple other places, so not worried about this much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would indeed be better to centralize this, but I agree with @mario that this does not need to be done now.
Feel free to improve directly in the branch?:)
…On Thu, 11 Jan 2018 at 21:55, Bartosz Przybylski ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/main/java/com/owncloud/android/MainApp.java
<#1954 (comment)>:
> @@ -236,6 +236,31 @@ public static void initAutoUpload() {
}
}
+ public static void migratePushKeys() {
+ Context context = getAppContext();
+
+ if (!PreferenceManager.getKeysMigration(context)) {
+ String oldKeyPath = getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
+ File oldPrivateKey = new File(oldKeyPath + File.separator + "push_key.priv");
+ File oldPublicKey = new File(oldKeyPath + File.separator + "push_key.pub");
+
+ String keyPath = getAppContext().getFilesDir().getAbsolutePath() +
+ File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
+ File privateKey = new File(keyPath + File.separator + "push_key.priv");
Equivalent of: File privateKey = new File(keyPath, "push_key.priv");
same for the line up and down
------------------------------
In src/main/java/com/owncloud/android/MainApp.java
<#1954 (comment)>:
> @@ -236,6 +236,31 @@ public static void initAutoUpload() {
}
}
+ public static void migratePushKeys() {
+ Context context = getAppContext();
+
+ if (!PreferenceManager.getKeysMigration(context)) {
+ String oldKeyPath = getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
+ File oldPrivateKey = new File(oldKeyPath + File.separator + "push_key.priv");
+ File oldPublicKey = new File(oldKeyPath + File.separator + "push_key.pub");
+
+ String keyPath = getAppContext().getFilesDir().getAbsolutePath() +
+ File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
+ File privateKey = new File(keyPath + File.separator + "push_key.priv");
+ File publicKey = new File(keyPath + File.separator + "push_key.pub");
+
+ if (oldPrivateKey.exists() && oldPublicKey.exists()) {
+ if (oldPrivateKey.renameTo(privateKey) && oldPublicKey.renameTo(publicKey)) {
This doesn't handle the scenario when first rename succeeds and other
fails.
------------------------------
In
src/main/java/com/owncloud/android/datastorage/providers/SystemDefaultStoragePointProvider.java
<#1954 (comment)>:
> @@ -44,16 +41,9 @@ public boolean canProvideStoragePoints() {
Vector<StoragePoint> result = new Vector<>();
final String defaultStringDesc = MainApp.getAppContext().getString(R.string.storage_description_default);
- File path;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
- path = MainApp.getAppContext().getExternalMediaDirs()[0];
- } else {
- path = getExternalStorageDirectory();
- }
-
- if (path != null && path.canWrite()) {
- result.add(new StoragePoint(defaultStringDesc, path.getAbsolutePath()));
- }
+ // Add private internal storage data directory.
+ result.add(new StoragePoint(defaultStringDesc,
+ MainApp.getAppContext().getFilesDir().getAbsolutePath()));
I am not a fan of this storage point using context. IMO there should be a
method in MainApp which directly returns the files dir and use that.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1954 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAWssYdqFmMe4R9rBtAukFyqofOwRHeks5tJnVXgaJpZM4RbXi8>
.
|
Fixed everything @przybylski except for the context thing which I'm unsure if we should fix. |
1d879ee
to
10923fb
Compare
@@ -286,6 +287,11 @@ public static boolean getLegacyClean(Context context) { | |||
return getDefaultSharedPreferences(context).getBoolean(PREF__LEGACY_CLEAN, false); | |||
} | |||
|
|||
public static boolean getKeysMigration(Context context) { | |||
return getDefaultSharedPreferences(context).getBoolean(PREF__KEYS_MIGRATION, false); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we wanted to start using ArbitraryDataProvider for stuff like this instead of shared preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but later. Not less than a day before RC :P
PreferenceManager.setKeysMigration(context, true); | ||
} else { | ||
if (oldPrivateKey.exists()) { | ||
oldPrivateKey.renameTo(privateKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is renameTo working if used across filesystem boundary, e.g. from external sdcard to internal storage? As far as I remember this does not work, but we have to copy and delete instead.
Edit: doc says:
Both paths be on the same mount point. On Android, applications are most likely to hit this restriction when attempting to copy between internal storage and an SD card.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will investigate.
oldPublicKey.renameTo(publicKey); | ||
} | ||
|
||
if (privateKey.exists() && publicKey.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check will always be true as those files are created at Line 245/246, or? A more sane check would be if length > 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not always. Maybe just one file was created :)
|
||
// Add external storage directory if available. | ||
if (isExternalStorageWritable()) { | ||
mCachedStoragePoints.add(new StoragePoint(MainApp.getAppContext().getExternalFilesDir(null).getAbsolutePath(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"getExternalFilesDir(null)" can be null:
May return null if shared storage is not currently available.
So this should be checked, otherwise we get a NPE
selection = "(?)"; | ||
selectionArgs = new String[]{selection}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done to prevent sql injections: instead of querying the args directly those are inserted via "(?):
select * where test = " + $foo; (foo can be dangerous)
becomes to
"select * where test = (?)", $foo --> then we have use of built in sql prevention.
Changing this, would mean that selectionArgs is always "(?)" which is not what we want to have: if args is null, then we want to "force" selection to use "(?)":
selection: "1=1"
--> select * from xy where "1=1"
becomes
--> select * from xy where (?), "1" and this sql injection save
So this must be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then the Uploads view crashes for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When? With which uploads? Do you have a stacktrace?
This is for quite a time in dev version and I never experienced a crash on upload view (except of the TimSort exception).
Or it is a new thing with this branch...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, was a problem with master. The Uploads view. But no stacktrace :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sql prevention stuff needs to be changed/discussed.
19e8b0b
to
a71e3aa
Compare
There is another severe bug:
(works on master) |
I will definitely take a look, but what about the Uploads? That is crashing for me (sometimes) on master, and my change fixes it. |
As said, give me a stacktrace/way to reproduce. |
@tobiasKaminsky ok, will revert the fix for now and we'll see in RC :) |
@tobiasKaminsky just tried, works. so this PR is ready. |
2150617
to
6d5e79e
Compare
Will test it with real device with external storage on monday. |
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: tobiaskaminsky <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
@@ -236,6 +243,53 @@ public static void initAutoUpload() { | |||
} | |||
} | |||
|
|||
public static void migratePushKeys() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only use in PushUtils on gplay flavor, so this can be moved there, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. :) Or just leave it here and don't worry :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be moved to not have the dependency in the f-droid build where this might be an issue then, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it already :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be a problem because it's just moving files, no Google Play deps 📦
Signed-off-by: tobiasKaminsky <[email protected]>
6d5e79e
to
88498e4
Compare
👍 |
👍 only one minor comment about the f-droid build and the PushUtils dependency: #1954 (comment) |
Welcome back @AndyScherzinger 🎉 |
@@ -335,4 +336,44 @@ private static int saveKeyToFile(Key key, String path) { | |||
|
|||
return -1; | |||
} | |||
|
|||
public static void migratePushKeys() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be private void migratePushKeys() then :P
@@ -99,8 +99,9 @@ public static String bytesToHex(byte[] bytes) { | |||
} | |||
|
|||
private static int generateRsa2048KeyPair() { | |||
String keyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator | |||
+ KEYPAIR_FOLDER; | |||
MainApp.migratePushKeys(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this won't work if you remove it from the MainApp :P
fix modified, but will soon be removed Signed-off-by: tobiasKaminsky <[email protected]>
Improved & rebased version of the awesome community PR found here:
#1836
We don't do files migration automatically yet, I'd suggest we implement that for 2.2 since it needs some UI as well, but push keys are properly migrated if they exist.