mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Compare commits
100 Commits
2.5.0.0bet
...
2.5.0.0bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7bbb47422 | ||
|
|
846bc7edb1 | ||
|
|
99a9842a1f | ||
|
|
33009138c3 | ||
|
|
c74b82ebd8 | ||
|
|
49ea92a4a5 | ||
|
|
6cc4eeaa30 | ||
|
|
1b89f79888 | ||
|
|
07d99de3ea | ||
|
|
ae757affa1 | ||
|
|
482b6296fc | ||
|
|
d37ce729f0 | ||
|
|
e92ce232bc | ||
|
|
78ae44b160 | ||
|
|
49ce87a8e0 | ||
|
|
d2fe5ce884 | ||
|
|
5e695756de | ||
|
|
0506a75417 | ||
|
|
34e1316144 | ||
|
|
18dffa6c75 | ||
|
|
03621c378e | ||
|
|
aff9312419 | ||
|
|
4651b1be96 | ||
|
|
32497a22d2 | ||
|
|
3b5ef56c16 | ||
|
|
d4cc3a58d8 | ||
|
|
afedbb38b2 | ||
|
|
fe70bf3877 | ||
|
|
f14ee6cf1c | ||
|
|
1791b15f85 | ||
|
|
6c5b3b3a0d | ||
|
|
6ea2287679 | ||
|
|
cad4ec22b4 | ||
|
|
f277983caf | ||
|
|
5e561e5321 | ||
|
|
ef83dbcae2 | ||
|
|
ab6c69adcb | ||
|
|
1c90747476 | ||
|
|
c3b3d8482c | ||
|
|
86b4d92599 | ||
|
|
1f6786b1f8 | ||
|
|
4cd2b153f4 | ||
|
|
27b0810688 | ||
|
|
94c72a4cf6 | ||
|
|
e634116e71 | ||
|
|
9021cb5bc8 | ||
|
|
3674900a54 | ||
|
|
9855ae79c3 | ||
|
|
fe1a4985f1 | ||
|
|
015a368a1d | ||
|
|
07f59e071d | ||
|
|
670e2bfe33 | ||
|
|
992b6382a3 | ||
|
|
c3ac550c93 | ||
|
|
acba7fc5de | ||
|
|
ccb500fdf4 | ||
|
|
44111507e7 | ||
|
|
5f14596ed2 | ||
|
|
4ad65c8f4a | ||
|
|
b4b215fe30 | ||
|
|
d8a8005d70 | ||
|
|
37ca15b77c | ||
|
|
6c18fe5591 | ||
|
|
fdcb05467c | ||
|
|
ef8db46ae7 | ||
|
|
14f56c77e8 | ||
|
|
44e21084e4 | ||
|
|
b7f1275789 | ||
|
|
b1be05db4d | ||
|
|
09c776fd7e | ||
|
|
e8a24790a5 | ||
|
|
8b3be79266 | ||
|
|
e5f0572c1c | ||
|
|
68df3bc6c3 | ||
|
|
a3da960c26 | ||
|
|
d9490f9840 | ||
|
|
3b24f9d821 | ||
|
|
bf35897e92 | ||
|
|
977705b42d | ||
|
|
459bc40515 | ||
|
|
eb8ca9355c | ||
|
|
31f7b0d5be | ||
|
|
7c54946c4b | ||
|
|
5aaf2c222a | ||
|
|
9424feefce | ||
|
|
a3917ccab6 | ||
|
|
5286a60142 | ||
|
|
d4459de49b | ||
|
|
05dba6668c | ||
|
|
c15a1c6eaa | ||
|
|
fe8c962f73 | ||
|
|
4192cf2403 | ||
|
|
1817f1aa9e | ||
|
|
afacf352ed | ||
|
|
d3ebbba2a1 | ||
|
|
460edf1745 | ||
|
|
dacb19d412 | ||
|
|
fe8158db85 | ||
|
|
a36e4fbcd0 | ||
|
|
9442c7ef07 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -71,6 +71,7 @@ app/app.iml
|
|||||||
# Art
|
# Art
|
||||||
art/screen*.png
|
art/screen*.png
|
||||||
art/logo_512.png
|
art/logo_512.png
|
||||||
|
art/store_screens/
|
||||||
|
|
||||||
# Dir linux
|
# Dir linux
|
||||||
.directory
|
.directory
|
||||||
|
|||||||
16
CHANGELOG
16
CHANGELOG
@@ -1,3 +1,19 @@
|
|||||||
|
KeepassDX (2.5.0.0beta11)
|
||||||
|
* Fix memory issue with parcelable (crash in beta12 version)
|
||||||
|
|
||||||
|
KeepassDX (2.5.0.0beta12)
|
||||||
|
* Added the Magikeyboard to fill the forms (settings still in development)
|
||||||
|
* Added move and copy for groups and entries
|
||||||
|
* New navigation in a single screen / new animations between activities
|
||||||
|
* New icons for the material pack / vectorization
|
||||||
|
* New adaptive launcher icon
|
||||||
|
* Icons depends now of setting of list items
|
||||||
|
* Added a setting to disable the open button when no password is identified
|
||||||
|
* Added a setting to disable the education screens
|
||||||
|
* Added a setting to disable the copy of protected custom fields
|
||||||
|
* Fix the fingerprint recognition (WARNING : The keystore is reinit, you must delete the old keys)
|
||||||
|
* Fix small bugs
|
||||||
|
|
||||||
KeepassDX (2.5.0.0beta11)
|
KeepassDX (2.5.0.0beta11)
|
||||||
* Fix crash in beta10 version
|
* Fix crash in beta10 version
|
||||||
|
|
||||||
|
|||||||
7
FAQ.md
7
FAQ.md
@@ -33,6 +33,11 @@ KeePass DX was created to meet the security and usability needs of a KeePass app
|
|||||||
**Yes** you can, but you **must first save the .kdb or .kdbx file from your database to an external storage** *(like a hardrive or a cloud)*.
|
**Yes** you can, but you **must first save the .kdb or .kdbx file from your database to an external storage** *(like a hardrive or a cloud)*.
|
||||||
We recommend you save your data after each modification so incase you loose your android device you could retrieve the data and import it into the new KeePass DX installed on the new android device.
|
We recommend you save your data after each modification so incase you loose your android device you could retrieve the data and import it into the new KeePass DX installed on the new android device.
|
||||||
|
|
||||||
|
## Why are updates not available at the same time on all stores?
|
||||||
|
|
||||||
|
- **PlayStore** only needs an APK generated and manually signed to be available on the store, it usually takes **20 minutes** to be available because it is deployed with fastlane. But the management of the APK and its data by the google servers is obscure.
|
||||||
|
- **F-Droid**, to **ensure that the code is open source**, checks the sources directly on git repository (by checking the presence of new tags) and builds itself the APK that the server signs during the compilation of code and dependencies. Updating the project will take **1-10 days** for F-Droid to analyze all available repositories, build sources and deploy the generated APK. So F-Droid is slower for deployment but it is run by **volunteers** and guaranteed a **clean APK**. :)
|
||||||
|
|
||||||
## Why not an online version?
|
## Why not an online version?
|
||||||
|
|
||||||
The offline and online client concepts only exists with Keepass2Android because the file access network tools are directly integrated into the code of the main application. Which is a very dubious choice knowing that **it is not normally the purpose of a password management application to take care of external file synchronization on clouds** (which can be under closed licensed and recover your data base), it is rather the purpose of the [file management application](https://developer.android.com/guide/topics/providers/document-provider).
|
The offline and online client concepts only exists with Keepass2Android because the file access network tools are directly integrated into the code of the main application. Which is a very dubious choice knowing that **it is not normally the purpose of a password management application to take care of external file synchronization on clouds** (which can be under closed licensed and recover your data base), it is rather the purpose of the [file management application](https://developer.android.com/guide/topics/providers/document-provider).
|
||||||
@@ -41,7 +46,7 @@ The offline and online client concepts only exists with Keepass2Android because
|
|||||||
|
|
||||||
**Yes**, we have integrated a secure openning option of fingerprint for android devices that support this feature, so no one can access the application without scanning his/her fingerprint or fill a master key.
|
**Yes**, we have integrated a secure openning option of fingerprint for android devices that support this feature, so no one can access the application without scanning his/her fingerprint or fill a master key.
|
||||||
|
|
||||||
## Can I open my database without my master key (master password and/or key file)?
|
## Can I open my database without my master key (master password and/or key file)?
|
||||||
|
|
||||||
**No**, you can not open a database file without the master password (and / or) the associated key file. Be sure to remember your master password and save the key file in a safe place.
|
**No**, you can not open a database file without the master password (and / or) the associated key file. Be sure to remember your master password and save the key file in a safe place.
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
* **Fingerprint** for fast unlocking
|
* **Fingerprint** for fast unlocking
|
||||||
* Material design with **themes**
|
* Material design with **themes**
|
||||||
* **AutoFill** and Integration
|
* **AutoFill** and Integration
|
||||||
|
* Field filling **keyboard**
|
||||||
* Precise management of **settings**
|
* Precise management of **settings**
|
||||||
|
|
||||||
Keepass DX is **open source** and **ad-free**.
|
Keepass DX is **open source** and **ad-free**.
|
||||||
@@ -33,8 +34,8 @@ Yes, KeePass DX is under **free license (OSI certified)** and **without advertis
|
|||||||
|
|
||||||
You can contribute in different ways to help us on our work.
|
You can contribute in different ways to help us on our work.
|
||||||
|
|
||||||
* Add features by a **pull request**.
|
* Add features by a **[pull request](https://help.github.com/articles/about-pull-requests/)**.
|
||||||
* Help to **translate** into your language
|
* Help to **[translate](https://hosted.weblate.org/projects/keepass-dx/strings/)** into your language (By using [Weblate](https://hosted.weblate.org/projects/keepass-dx/) or with a manual [pull request](https://help.github.com/articles/about-pull-requests/))
|
||||||
* **[Donate](https://www.kunzisoft.com/donation)** 人◕ ‿‿ ◕人Y for a better service and a quick development of your features.
|
* **[Donate](https://www.kunzisoft.com/donation)** 人◕ ‿‿ ◕人Y for a better service and a quick development of your features.
|
||||||
* Buy the **[Pro version](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.pro)** of KeePass DX
|
* Buy the **[Pro version](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.pro)** of KeePass DX
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ You can contribute in different ways to help us on our work.
|
|||||||
|
|
||||||
## F.A.Q.
|
## F.A.Q.
|
||||||
|
|
||||||
Other questions? You can read the [F.A.Q.](https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/FAQ.md)
|
Other questions? You can read the [F.A.Q.](https://github.com/Kunzisoft/KeePassDX/blob/master/FAQ.md)
|
||||||
|
|
||||||
## Other devices
|
## Other devices
|
||||||
|
|
||||||
|
|||||||
@@ -6,19 +6,15 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.kunzisoft.keepass"
|
applicationId "com.kunzisoft.keepass"
|
||||||
minSdkVersion 14
|
minSdkVersion 15
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode = 11
|
versionCode = 13
|
||||||
versionName = "2.5.0.0beta11"
|
versionName = "2.5.0.0beta13"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|
||||||
testApplicationId = "com.kunzisoft.keepass.tests"
|
testApplicationId = "com.kunzisoft.keepass.tests"
|
||||||
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
|
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
|
||||||
|
|
||||||
ndk {
|
|
||||||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
|
||||||
}
|
|
||||||
|
|
||||||
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
|
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +105,11 @@ dependencies {
|
|||||||
implementation 'commons-collections:commons-collections:3.2.1'
|
implementation 'commons-collections:commons-collections:3.2.1'
|
||||||
// Base64
|
// Base64
|
||||||
implementation 'biz.source_code:base64coder:2010-12-19'
|
implementation 'biz.source_code:base64coder:2010-12-19'
|
||||||
implementation 'com.google.code.gson:gson:2.8.1'
|
implementation 'com.google.code.gson:gson:2.8.4'
|
||||||
implementation 'com.google.guava:guava:23.0-android'
|
implementation 'com.google.guava:guava:23.0-android'
|
||||||
// Icon pack, classic for all, material for libre and pro
|
// Icon pack, classic for all, material for libre and pro
|
||||||
implementation project(path: ':icon-pack-classic')
|
implementation project(path: ':icon-pack-classic')
|
||||||
implementation project(path: ':icon-pack-material')
|
implementation project(path: ':icon-pack-material')
|
||||||
|
implementation project(path: ':magikeyboard')
|
||||||
|
implementation project(path: ':keepass-model')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.tests.database;
|
package com.kunzisoft.keepass.tests.database;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
@@ -30,9 +28,11 @@ import com.kunzisoft.keepass.database.PwDatabaseV3;
|
|||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
import com.kunzisoft.keepass.database.PwEntryV3;
|
import com.kunzisoft.keepass.database.PwEntryV3;
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
|
import com.kunzisoft.keepass.database.action.node.DeleteGroupRunnable;
|
||||||
import com.kunzisoft.keepass.search.SearchDbHelper;
|
import com.kunzisoft.keepass.search.SearchDbHelper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DeleteEntry extends AndroidTestCase {
|
public class DeleteEntry extends AndroidTestCase {
|
||||||
private static final String GROUP1_NAME = "Group1";
|
private static final String GROUP1_NAME = "Group1";
|
||||||
private static final String ENTRY1_NAME = "Test1";
|
private static final String ENTRY1_NAME = "Test1";
|
||||||
|
|||||||
50
app/src/free/res/drawable-v24/ic_launcher_foreground.xml
Normal file
50
app/src/free/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp">
|
||||||
|
<group
|
||||||
|
android:translateY="-332">
|
||||||
|
<group
|
||||||
|
android:translateY="332">
|
||||||
|
<path
|
||||||
|
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
|
||||||
|
android:fillColor="@color/long_shadow"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:strokeMiterLimit="4" />
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
|
||||||
|
android:fillColor="#eaeaea"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#58000000" />
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
|
||||||
|
android:fillColor="#81c784" />
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
|
||||||
|
android:fillColor="#eaeaea"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#58000000" />
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/green" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/green" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
50
app/src/libre/res/drawable-v24/ic_launcher_foreground.xml
Normal file
50
app/src/libre/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp">
|
||||||
|
<group
|
||||||
|
android:translateY="-332">
|
||||||
|
<group
|
||||||
|
android:translateY="332">
|
||||||
|
<path
|
||||||
|
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
|
||||||
|
android:fillColor="@color/long_shadow"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:strokeMiterLimit="4" />
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
|
||||||
|
android:fillColor="#eaeaea"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#58000000"/>
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
|
||||||
|
android:fillColor="#64b5f6" />
|
||||||
|
</group>
|
||||||
|
<group
|
||||||
|
android:scaleX="0.3939503"
|
||||||
|
android:scaleY="0.3939503"
|
||||||
|
android:translateX="33.66343"
|
||||||
|
android:translateY="233.998">
|
||||||
|
<path
|
||||||
|
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
|
||||||
|
android:fillColor="#eaeaea"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#58000000" />
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
5
app/src/libre/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
5
app/src/libre/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/green" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/green" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
|
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
|
||||||
android:theme="@style/KeepassDXStyle.SplashScreen"
|
android:theme="@style/KeepassDXStyle.SplashScreen"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTop"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden"
|
||||||
android:windowSoftInputMode="stateHidden" >
|
android:windowSoftInputMode="stateHidden" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -132,13 +132,15 @@
|
|||||||
<activity android:name="com.kunzisoft.keepass.settings.SettingsActivity" />
|
<activity android:name="com.kunzisoft.keepass.settings.SettingsActivity" />
|
||||||
<activity android:name="com.kunzisoft.keepass.autofill.AutoFillAuthActivity"
|
<activity android:name="com.kunzisoft.keepass.autofill.AutoFillAuthActivity"
|
||||||
android:configChanges="orientation|keyboardHidden" />
|
android:configChanges="orientation|keyboardHidden" />
|
||||||
|
<activity android:name="com.kunzisoft.keepass.selection.EntrySelectionAuthActivity"
|
||||||
|
android:configChanges="orientation|keyboardHidden" />
|
||||||
<activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" />
|
<activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" />
|
||||||
|
|
||||||
<service android:name="com.kunzisoft.keepass.timeout.TimeoutService" />
|
|
||||||
<service
|
<service
|
||||||
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
|
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
<!-- Receiver for Autofill -->
|
||||||
<service
|
<service
|
||||||
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
|
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
|
||||||
android:label="@string/autofill_service_name"
|
android:label="@string/autofill_service_name"
|
||||||
@@ -146,11 +148,11 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.autofill"
|
android:name="android.autofill"
|
||||||
android:resource="@xml/dataset_service" />
|
android:resource="@xml/dataset_service" />
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.service.autofill.AutofillService" />
|
<action android:name="android.service.autofill.AutofillService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
|
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import com.kunzisoft.keepass.database.PwDatabase;
|
|||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingHideActivity;
|
||||||
import com.kunzisoft.keepass.notifications.NotificationCopyingService;
|
import com.kunzisoft.keepass.notifications.NotificationCopyingService;
|
||||||
import com.kunzisoft.keepass.notifications.NotificationField;
|
import com.kunzisoft.keepass.notifications.NotificationField;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
@@ -150,12 +152,28 @@ public class EntryActivity extends LockingHideActivity {
|
|||||||
// Start to manage field reference to copy a value from ref
|
// Start to manage field reference to copy a value from ref
|
||||||
mEntry.startToManageFieldReferences(App.getDB().getPwDatabase());
|
mEntry.startToManageFieldReferences(App.getDB().getPwDatabase());
|
||||||
|
|
||||||
|
boolean containsUsernameToCopy =
|
||||||
|
mEntry.getUsername().length() > 0;
|
||||||
|
boolean containsPasswordToCopy =
|
||||||
|
(mEntry.getPassword().length() > 0
|
||||||
|
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this));
|
||||||
|
boolean containsExtraFieldToCopy =
|
||||||
|
(mEntry.allowExtraFields()
|
||||||
|
&& ((mEntry.containsCustomFields()
|
||||||
|
&& mEntry.containsCustomFieldsNotProtected())
|
||||||
|
|| (mEntry.containsCustomFields()
|
||||||
|
&& mEntry.containsCustomFieldsProtected()
|
||||||
|
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// If notifications enabled in settings
|
// If notifications enabled in settings
|
||||||
// Don't if application timeout
|
// Don't if application timeout
|
||||||
if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) {
|
if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) {
|
||||||
if (mEntry.getUsername().length() > 0
|
if (containsUsernameToCopy
|
||||||
|| (mEntry.getPassword().length() > 0 && PreferencesUtil.allowCopyPassword(this))
|
|| containsPasswordToCopy
|
||||||
|| mEntry.containsCustomFields()) {
|
|| containsExtraFieldToCopy
|
||||||
|
) {
|
||||||
// username already copied, waiting for user's action before copy password.
|
// username already copied, waiting for user's action before copy password.
|
||||||
Intent intent = new Intent(this, NotificationCopyingService.class);
|
Intent intent = new Intent(this, NotificationCopyingService.class);
|
||||||
intent.setAction(NotificationCopyingService.ACTION_NEW_NOTIFICATION);
|
intent.setAction(NotificationCopyingService.ACTION_NEW_NOTIFICATION);
|
||||||
@@ -164,35 +182,37 @@ public class EntryActivity extends LockingHideActivity {
|
|||||||
// Construct notification fields
|
// Construct notification fields
|
||||||
ArrayList<NotificationField> notificationFields = new ArrayList<>();
|
ArrayList<NotificationField> notificationFields = new ArrayList<>();
|
||||||
// Add username if exists to notifications
|
// Add username if exists to notifications
|
||||||
if (mEntry.getUsername().length() > 0)
|
if (containsUsernameToCopy)
|
||||||
notificationFields.add(
|
notificationFields.add(
|
||||||
new NotificationField(
|
new NotificationField(
|
||||||
NotificationField.NotificationFieldId.USERNAME,
|
NotificationField.NotificationFieldId.USERNAME,
|
||||||
mEntry.getUsername(),
|
mEntry.getUsername(),
|
||||||
getResources()));
|
getResources()));
|
||||||
// Add password to notifications
|
// Add password to notifications
|
||||||
if (PreferencesUtil.allowCopyPassword(this)) {
|
if (containsPasswordToCopy) {
|
||||||
if (mEntry.getPassword().length() > 0)
|
notificationFields.add(
|
||||||
notificationFields.add(
|
new NotificationField(
|
||||||
new NotificationField(
|
NotificationField.NotificationFieldId.PASSWORD,
|
||||||
NotificationField.NotificationFieldId.PASSWORD,
|
mEntry.getPassword(),
|
||||||
mEntry.getPassword(),
|
getResources()));
|
||||||
getResources()));
|
|
||||||
}
|
}
|
||||||
// Add extra fields
|
// Add extra fields
|
||||||
if (mEntry.allowExtraFields()) {
|
if (containsExtraFieldToCopy) {
|
||||||
try {
|
try {
|
||||||
mEntry.getFields().doActionToAllCustomProtectedField(new ExtraFields.ActionProtected() {
|
mEntry.getFields().doActionToAllCustomProtectedField(new ExtraFields.ActionProtected() {
|
||||||
private int anonymousFieldNumber = 0;
|
private int anonymousFieldNumber = 0;
|
||||||
@Override
|
@Override
|
||||||
public void doAction(String key, ProtectedString value) {
|
public void doAction(String key, ProtectedString value) {
|
||||||
notificationFields.add(
|
//If value is not protected or allowed
|
||||||
new NotificationField(
|
if (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this)) {
|
||||||
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
|
notificationFields.add(
|
||||||
value.toString(),
|
new NotificationField(
|
||||||
key,
|
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
|
||||||
getResources()));
|
value.toString(),
|
||||||
anonymousFieldNumber++;
|
key,
|
||||||
|
getResources()));
|
||||||
|
anonymousFieldNumber++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
@@ -215,68 +235,70 @@ public class EntryActivity extends LockingHideActivity {
|
|||||||
* Displays the explanation for copying a field and editing an entry
|
* Displays the explanation for copying a field and editing an entry
|
||||||
*/
|
*/
|
||||||
private void checkAndPerformedEducation(Menu menu) {
|
private void checkAndPerformedEducation(Menu menu) {
|
||||||
|
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||||
|
|
||||||
if (entryContentsView != null && entryContentsView.isUserNamePresent()
|
if (entryContentsView != null && entryContentsView.isUserNamePresent()
|
||||||
&& !PreferencesUtil.isEducationCopyUsernamePerformed(this)) {
|
&& !PreferencesUtil.isEducationCopyUsernamePerformed(this)) {
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
|
|
||||||
getString(R.string.education_field_copy_title),
|
|
||||||
getString(R.string.education_field_copy_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(false)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
|
|
||||||
getString(R.string.copy_field, getString(R.string.entry_user_name)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
// Launch autofill settings
|
|
||||||
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_copy_username_key);
|
|
||||||
|
|
||||||
} else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
TapTargetView.showFor(this,
|
TapTargetView.showFor(this,
|
||||||
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit,
|
TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
|
||||||
getString(R.string.education_entry_edit_title),
|
getString(R.string.education_field_copy_title),
|
||||||
getString(R.string.education_entry_edit_summary))
|
getString(R.string.education_field_copy_summary))
|
||||||
.textColorInt(Color.WHITE)
|
.textColorInt(Color.WHITE)
|
||||||
.tintTarget(true)
|
.tintTarget(false)
|
||||||
.cancelable(true),
|
.cancelable(true),
|
||||||
new TapTargetView.Listener() {
|
new TapTargetView.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTargetClick(TapTargetView view) {
|
public void onTargetClick(TapTargetView view) {
|
||||||
super.onTargetClick(view);
|
super.onTargetClick(view);
|
||||||
MenuItem editItem = menu.findItem(R.id.menu_edit);
|
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
|
||||||
onOptionsItemSelected(editItem);
|
getString(R.string.copy_field, getString(R.string.entry_user_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
super.onOuterCircleClick(view);
|
super.onOuterCircleClick(view);
|
||||||
view.dismiss(false);
|
view.dismiss(false);
|
||||||
// Open Keepass doc to create field references
|
// Launch autofill settings
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
|
||||||
Uri.parse(getString(R.string.field_references_url)));
|
|
||||||
startActivity(browserIntent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
R.string.education_entry_edit_key);
|
R.string.education_copy_username_key);
|
||||||
} catch (Exception e) {
|
|
||||||
// If icon not visible
|
} else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
|
||||||
Log.w(TAG, "Can't performed education for entry's edition");
|
|
||||||
|
try {
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit,
|
||||||
|
getString(R.string.education_entry_edit_title),
|
||||||
|
getString(R.string.education_entry_edit_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(true)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
MenuItem editItem = menu.findItem(R.id.menu_edit);
|
||||||
|
onOptionsItemSelected(editItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
// Open Keepass doc to create field references
|
||||||
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse(getString(R.string.field_references_url)));
|
||||||
|
startActivity(browserIntent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
|
R.string.education_entry_edit_key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// If icon not visible
|
||||||
|
Log.w(TAG, "Can't performed education for entry's edition");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,7 +331,7 @@ public class EntryActivity extends LockingHideActivity {
|
|||||||
);
|
);
|
||||||
|
|
||||||
entryContentsView.assignPassword(mEntry.getPassword());
|
entryContentsView.assignPassword(mEntry.getPassword());
|
||||||
if (PreferencesUtil.allowCopyPassword(this)) {
|
if (PreferencesUtil.allowCopyPasswordAndProtectedFields(this)) {
|
||||||
entryContentsView.assignPasswordCopyListener(view ->
|
entryContentsView.assignPasswordCopyListener(view ->
|
||||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(),
|
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(),
|
||||||
getString(R.string.copy_field, getString(R.string.entry_password)))
|
getString(R.string.copy_field, getString(R.string.entry_password)))
|
||||||
@@ -325,14 +347,15 @@ public class EntryActivity extends LockingHideActivity {
|
|||||||
if (mEntry.allowExtraFields()) {
|
if (mEntry.allowExtraFields()) {
|
||||||
entryContentsView.clearExtraFields();
|
entryContentsView.clearExtraFields();
|
||||||
|
|
||||||
mEntry.getFields().doActionToAllCustomProtectedField((label, value) ->
|
mEntry.getFields().doActionToAllCustomProtectedField((label, value) -> {
|
||||||
|
boolean showAction = (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this));
|
||||||
entryContentsView.addExtraField(label, value, view ->
|
entryContentsView.addExtraField(label, value, showAction, view ->
|
||||||
clipboardHelper.timeoutCopyToClipboard(
|
clipboardHelper.timeoutCopyToClipboard(
|
||||||
value.toString(),
|
value.toString(),
|
||||||
getString(R.string.copy_field, label)
|
getString(R.string.copy_field, label)
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign dates
|
// Assign dates
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.content.Intent;
|
|||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -49,14 +48,17 @@ import com.kunzisoft.keepass.database.PwEntry;
|
|||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
import com.kunzisoft.keepass.database.PwGroupId;
|
import com.kunzisoft.keepass.database.PwGroupId;
|
||||||
import com.kunzisoft.keepass.database.PwIconStandard;
|
import com.kunzisoft.keepass.database.PwIconStandard;
|
||||||
import com.kunzisoft.keepass.database.action.AddEntryRunnable;
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
|
||||||
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
|
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
|
||||||
import com.kunzisoft.keepass.database.action.UpdateEntryRunnable;
|
import com.kunzisoft.keepass.database.action.node.AddEntryRunnable;
|
||||||
|
import com.kunzisoft.keepass.database.action.node.AfterActionNodeOnFinish;
|
||||||
|
import com.kunzisoft.keepass.database.action.node.UpdateEntryRunnable;
|
||||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||||
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
|
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
||||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingHideActivity;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||||
@@ -67,6 +69,8 @@ import com.kunzisoft.keepass.view.EntryEditCustomField;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID;
|
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID;
|
||||||
|
|
||||||
public class EntryEditActivity extends LockingHideActivity
|
public class EntryEditActivity extends LockingHideActivity
|
||||||
@@ -251,7 +255,7 @@ public class EntryEditActivity extends LockingHideActivity
|
|||||||
mCallbackNewEntry = populateNewEntry();
|
mCallbackNewEntry = populateNewEntry();
|
||||||
|
|
||||||
// Open a progress dialog and save entry
|
// Open a progress dialog and save entry
|
||||||
OnFinishRunnable onFinish = new AfterSave();
|
AfterActionNodeOnFinish onFinish = new AfterSave();
|
||||||
EntryEditActivity act = EntryEditActivity.this;
|
EntryEditActivity act = EntryEditActivity.this;
|
||||||
RunnableOnFinish task;
|
RunnableOnFinish task;
|
||||||
if ( mIsNew ) {
|
if ( mIsNew ) {
|
||||||
@@ -272,59 +276,58 @@ public class EntryEditActivity extends LockingHideActivity
|
|||||||
* Displays the explanation for the icon selection, the password generator and for a new field
|
* Displays the explanation for the icon selection, the password generator and for a new field
|
||||||
*/
|
*/
|
||||||
private void checkAndPerformedEducation() {
|
private void checkAndPerformedEducation() {
|
||||||
|
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||||
|
// TODO Show icon
|
||||||
|
|
||||||
// TODO Show icon
|
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forView(generatePasswordView,
|
||||||
|
getString(R.string.education_generate_password_title),
|
||||||
|
getString(R.string.education_generate_password_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(false)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
openPasswordGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
|
@Override
|
||||||
TapTargetView.showFor(this,
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
TapTarget.forView(generatePasswordView,
|
super.onOuterCircleClick(view);
|
||||||
getString(R.string.education_generate_password_title),
|
view.dismiss(false);
|
||||||
getString(R.string.education_generate_password_summary))
|
}
|
||||||
.textColorInt(Color.WHITE)
|
});
|
||||||
.tintTarget(false)
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
.cancelable(true),
|
R.string.education_password_generator_key);
|
||||||
new TapTargetView.Listener() {
|
} else if (mEntry.allowExtraFields()
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
openPasswordGenerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_password_generator_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (mEntry.allowExtraFields()
|
|
||||||
&& !mEntry.containsCustomFields()
|
&& !mEntry.containsCustomFields()
|
||||||
&& !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) {
|
&& !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) {
|
||||||
TapTargetView.showFor(this,
|
TapTargetView.showFor(this,
|
||||||
TapTarget.forView(addNewFieldView,
|
TapTarget.forView(addNewFieldView,
|
||||||
getString(R.string.education_entry_new_field_title),
|
getString(R.string.education_entry_new_field_title),
|
||||||
getString(R.string.education_entry_new_field_summary))
|
getString(R.string.education_entry_new_field_summary))
|
||||||
.textColorInt(Color.WHITE)
|
.textColorInt(Color.WHITE)
|
||||||
.tintTarget(false)
|
.tintTarget(false)
|
||||||
.cancelable(true),
|
.cancelable(true),
|
||||||
new TapTargetView.Listener() {
|
new TapTargetView.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTargetClick(TapTargetView view) {
|
public void onTargetClick(TapTargetView view) {
|
||||||
super.onTargetClick(view);
|
super.onTargetClick(view);
|
||||||
addNewCustomField();
|
addNewCustomField();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
super.onOuterCircleClick(view);
|
super.onOuterCircleClick(view);
|
||||||
view.dismiss(false);
|
view.dismiss(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
R.string.education_entry_new_field_key);
|
R.string.education_entry_new_field_key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +443,7 @@ public class EntryEditActivity extends LockingHideActivity
|
|||||||
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID);
|
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID);
|
||||||
else {
|
else {
|
||||||
if (mIsNew) {
|
if (mIsNew) {
|
||||||
return App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
|
return App.getDB().getPwDatabase().getIconFactory().getKeyIcon();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Keep previous icon, if no new one was selected
|
// Keep previous icon, if no new one was selected
|
||||||
@@ -560,14 +563,10 @@ public class EntryEditActivity extends LockingHideActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class AfterSave extends OnFinishRunnable {
|
private final class AfterSave extends AfterActionNodeOnFinish {
|
||||||
|
|
||||||
AfterSave() {
|
|
||||||
super(new Handler());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run(@Nullable PwNode oldNode, @Nullable PwNode newNode) {
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
if ( mSuccess ) {
|
if ( mSuccess ) {
|
||||||
finish();
|
finish();
|
||||||
@@ -578,6 +577,6 @@ public class EntryEditActivity extends LockingHideActivity
|
|||||||
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
|
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -50,35 +50,49 @@ import com.kunzisoft.keepass.adapters.NodeAdapter;
|
|||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwDatabase;
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
import com.kunzisoft.keepass.database.PwGroupId;
|
import com.kunzisoft.keepass.database.PwGroupId;
|
||||||
import com.kunzisoft.keepass.database.PwIcon;
|
import com.kunzisoft.keepass.database.PwIcon;
|
||||||
import com.kunzisoft.keepass.database.PwIconStandard;
|
import com.kunzisoft.keepass.database.PwIconStandard;
|
||||||
import com.kunzisoft.keepass.database.PwNode;
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
import com.kunzisoft.keepass.database.SortNodeEnum;
|
import com.kunzisoft.keepass.database.action.node.AddGroupRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.AddGroupRunnable;
|
import com.kunzisoft.keepass.database.action.node.AfterActionNodeOnFinish;
|
||||||
import com.kunzisoft.keepass.database.action.DeleteEntryRunnable;
|
import com.kunzisoft.keepass.database.action.node.CopyEntryRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
|
import com.kunzisoft.keepass.database.action.node.DeleteEntryRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.UpdateGroupRunnable;
|
import com.kunzisoft.keepass.database.action.node.DeleteGroupRunnable;
|
||||||
|
import com.kunzisoft.keepass.database.action.node.MoveEntryRunnable;
|
||||||
|
import com.kunzisoft.keepass.database.action.node.MoveGroupRunnable;
|
||||||
|
import com.kunzisoft.keepass.database.action.node.UpdateGroupRunnable;
|
||||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
|
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
|
import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
|
||||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||||
|
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||||
import com.kunzisoft.keepass.search.SearchResultsActivity;
|
import com.kunzisoft.keepass.search.SearchResultsActivity;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||||
|
import com.kunzisoft.keepass.tasks.UIToastTask;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||||
import com.kunzisoft.keepass.view.AddNodeButtonView;
|
import com.kunzisoft.keepass.view.AddNodeButtonView;
|
||||||
|
|
||||||
public class GroupActivity extends ListNodesActivity
|
import net.cachapa.expandablelayout.ExpandableLayout;
|
||||||
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
|
|
||||||
|
|
||||||
private static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
public class GroupActivity extends ListNodesActivity
|
||||||
|
implements GroupEditDialogFragment.EditGroupListener,
|
||||||
|
IconPickerDialogFragment.IconPickerListener,
|
||||||
|
NodeAdapter.NodeMenuListener,
|
||||||
|
ListNodesFragment.OnScrollListener {
|
||||||
|
|
||||||
|
private static final String TAG = GroupActivity.class.getName();
|
||||||
|
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
|
|
||||||
|
private ExpandableLayout toolbarPasteExpandableLayout;
|
||||||
|
private Toolbar toolbarPaste;
|
||||||
|
|
||||||
private ImageView iconView;
|
private ImageView iconView;
|
||||||
private AddNodeButtonView addNodeButtonView;
|
private AddNodeButtonView addNodeButtonView;
|
||||||
|
|
||||||
@@ -87,14 +101,16 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
protected boolean isRoot = false;
|
protected boolean isRoot = false;
|
||||||
protected boolean readOnly = false;
|
protected boolean readOnly = false;
|
||||||
|
|
||||||
private static final String TAG = "Group Activity:";
|
|
||||||
|
|
||||||
private static final String OLD_GROUP_TO_UPDATE_KEY = "OLD_GROUP_TO_UPDATE_KEY";
|
private static final String OLD_GROUP_TO_UPDATE_KEY = "OLD_GROUP_TO_UPDATE_KEY";
|
||||||
|
private static final String NODE_TO_COPY_KEY = "NODE_TO_COPY_KEY";
|
||||||
|
private static final String NODE_TO_MOVE_KEY = "NODE_TO_MOVE_KEY";
|
||||||
private PwGroup oldGroupToUpdate;
|
private PwGroup oldGroupToUpdate;
|
||||||
|
private PwNode nodeToCopy;
|
||||||
|
private PwNode nodeToMove;
|
||||||
|
|
||||||
public static void launch(Activity act) {
|
public static void launch(Activity act) {
|
||||||
recordFirstTimeBeforeLaunch(act);
|
startRecordTime(act);
|
||||||
launch(act, (PwGroup) null);
|
launch(act, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void launch(Activity act, PwGroup group) {
|
public static void launch(Activity act, PwGroup group) {
|
||||||
@@ -107,18 +123,37 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void launchForKeyboardResult(Activity act) {
|
||||||
|
startRecordTime(act);
|
||||||
|
launchForKeyboardResult(act, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void launchForKeyboardResult(Activity act, PwGroup group) {
|
||||||
|
// TODO remove
|
||||||
|
if (checkTimeIsAllowedOrFinish(act)) {
|
||||||
|
Intent intent = new Intent(act, GroupActivity.class);
|
||||||
|
if (group != null) {
|
||||||
|
intent.putExtra(GROUP_ID_KEY, group.getId());
|
||||||
|
}
|
||||||
|
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
|
||||||
|
act.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public static void launch(Activity act, AssistStructure assistStructure) {
|
public static void launchForAutofillResult(Activity act, AssistStructure assistStructure) {
|
||||||
if ( assistStructure != null ) {
|
if ( assistStructure != null ) {
|
||||||
recordFirstTimeBeforeLaunch(act);
|
startRecordTime(act);
|
||||||
launch(act, null, assistStructure);
|
launchForAutofillResult(act, null, assistStructure);
|
||||||
} else {
|
} else {
|
||||||
launch(act);
|
launch(act);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public static void launch(Activity act, PwGroup group, AssistStructure assistStructure) {
|
public static void launchForAutofillResult(Activity act, PwGroup group, AssistStructure assistStructure) {
|
||||||
|
// TODO remove
|
||||||
if ( assistStructure != null ) {
|
if ( assistStructure != null ) {
|
||||||
if (checkTimeIsAllowedOrFinish(act)) {
|
if (checkTimeIsAllowedOrFinish(act)) {
|
||||||
Intent intent = new Intent(act, GroupActivity.class);
|
Intent intent = new Intent(act, GroupActivity.class);
|
||||||
@@ -136,35 +171,51 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Log.w(TAG, "Retrieved tree");
|
Log.i(TAG, "Started creating tree");
|
||||||
if ( mCurrentGroup == null ) {
|
if ( mCurrentGroup == null ) {
|
||||||
Log.w(TAG, "Group was null");
|
Log.w(TAG, "Group was null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null
|
// Construct main view
|
||||||
&& savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY)) {
|
|
||||||
oldGroupToUpdate = (PwGroup) savedInstanceState.getSerializable(OLD_GROUP_TO_UPDATE_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct main view
|
|
||||||
setContentView(getLayoutInflater().inflate(R.layout.list_nodes_with_add_button, null));
|
setContentView(getLayoutInflater().inflate(R.layout.list_nodes_with_add_button, null));
|
||||||
|
|
||||||
|
attachFragmentToContentView();
|
||||||
|
|
||||||
iconView = findViewById(R.id.icon);
|
iconView = findViewById(R.id.icon);
|
||||||
addNodeButtonView = findViewById(R.id.add_node_button);
|
addNodeButtonView = findViewById(R.id.add_node_button);
|
||||||
addNodeButtonView.enableAddGroup(addGroupEnabled);
|
addNodeButtonView.enableAddGroup(addGroupEnabled);
|
||||||
addNodeButtonView.enableAddEntry(addEntryEnabled);
|
addNodeButtonView.enableAddEntry(addEntryEnabled);
|
||||||
// Hide when scroll
|
|
||||||
RecyclerView recyclerView = findViewById(R.id.nodes_list);
|
|
||||||
recyclerView.addOnScrollListener(addNodeButtonView.hideButtonOnScrollListener());
|
|
||||||
|
|
||||||
toolbar = findViewById(R.id.toolbar);
|
toolbar = findViewById(R.id.toolbar);
|
||||||
toolbar.setTitle("");
|
toolbar.setTitle("");
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
groupNameView = findViewById(R.id.group_name);
|
||||||
|
|
||||||
if ( mCurrentGroup.getParent() != null )
|
toolbarPasteExpandableLayout = findViewById(R.id.expandable_toolbar_paste_layout);
|
||||||
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
|
toolbarPaste = findViewById(R.id.toolbar_paste);
|
||||||
|
toolbarPaste.inflateMenu(R.menu.node_paste_menu);
|
||||||
|
toolbarPaste.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
|
||||||
|
toolbarPaste.setNavigationOnClickListener(view -> {
|
||||||
|
toolbarPasteExpandableLayout.collapse();
|
||||||
|
nodeToCopy = null;
|
||||||
|
nodeToMove = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
if (savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY))
|
||||||
|
oldGroupToUpdate = (PwGroup) savedInstanceState.getSerializable(OLD_GROUP_TO_UPDATE_KEY);
|
||||||
|
|
||||||
|
if (savedInstanceState.containsKey(NODE_TO_COPY_KEY)) {
|
||||||
|
nodeToCopy = (PwNode) savedInstanceState.getSerializable(NODE_TO_COPY_KEY);
|
||||||
|
toolbarPaste.setOnMenuItemClickListener(new OnCopyMenuItemClickListener());
|
||||||
|
}
|
||||||
|
else if (savedInstanceState.containsKey(NODE_TO_MOVE_KEY)) {
|
||||||
|
nodeToMove = (PwNode) savedInstanceState.getSerializable(NODE_TO_MOVE_KEY);
|
||||||
|
toolbarPaste.setOnMenuItemClickListener(new OnMoveMenuItemClickListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addNodeButtonView.setAddGroupClickListener(v -> {
|
addNodeButtonView.setAddGroupClickListener(v -> {
|
||||||
GroupEditDialogFragment.build()
|
GroupEditDialogFragment.build()
|
||||||
@@ -173,24 +224,42 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
});
|
});
|
||||||
addNodeButtonView.setAddEntryClickListener(v ->
|
addNodeButtonView.setAddEntryClickListener(v ->
|
||||||
EntryEditActivity.launch(GroupActivity.this, mCurrentGroup));
|
EntryEditActivity.launch(GroupActivity.this, mCurrentGroup));
|
||||||
|
|
||||||
setGroupTitle();
|
|
||||||
|
|
||||||
Log.w(TAG, "Finished creating tree");
|
Log.i(TAG, "Finished creating tree");
|
||||||
|
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
showWarnings();
|
showWarnings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PwGroup initCurrentGroup() {
|
@Override
|
||||||
PwGroup currentGroup;
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putSerializable(GROUP_ID_KEY, mCurrentGroup.getId());
|
||||||
|
outState.putSerializable(OLD_GROUP_TO_UPDATE_KEY, oldGroupToUpdate);
|
||||||
|
if (nodeToCopy != null)
|
||||||
|
outState.putSerializable(NODE_TO_COPY_KEY, nodeToCopy);
|
||||||
|
if (nodeToMove != null)
|
||||||
|
outState.putSerializable(NODE_TO_MOVE_KEY, nodeToMove);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
PwGroupId pwGroupId = null; // TODO Parcelable
|
||||||
|
if (savedInstanceState != null
|
||||||
|
&& savedInstanceState.containsKey(GROUP_ID_KEY)) {
|
||||||
|
pwGroupId = (PwGroupId) savedInstanceState.getSerializable(GROUP_ID_KEY);
|
||||||
|
} else {
|
||||||
|
if (getIntent() != null)
|
||||||
|
pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
Database db = App.getDB();
|
Database db = App.getDB();
|
||||||
readOnly = db.isReadOnly();
|
readOnly = db.isReadOnly();
|
||||||
PwGroup root = db.getPwDatabase().getRootGroup();
|
PwGroup root = db.getPwDatabase().getRootGroup();
|
||||||
|
|
||||||
Log.w(TAG, "Creating tree view");
|
Log.w(TAG, "Creating tree view");
|
||||||
PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
|
PwGroup currentGroup;
|
||||||
if ( pwGroupId == null ) {
|
if ( pwGroupId == null ) {
|
||||||
currentGroup = root;
|
currentGroup = root;
|
||||||
} else {
|
} else {
|
||||||
@@ -199,7 +268,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
|
|
||||||
if (currentGroup != null) {
|
if (currentGroup != null) {
|
||||||
addGroupEnabled = !readOnly;
|
addGroupEnabled = !readOnly;
|
||||||
addEntryEnabled = !readOnly; // TODO ReadOnly
|
addEntryEnabled = !readOnly; // TODO consultation mode
|
||||||
isRoot = (currentGroup == root);
|
isRoot = (currentGroup == root);
|
||||||
if (!currentGroup.allowAddEntryIfIsRoot())
|
if (!currentGroup.allowAddEntryIfIsRoot())
|
||||||
addEntryEnabled = !isRoot && addEntryEnabled;
|
addEntryEnabled = !isRoot && addEntryEnabled;
|
||||||
@@ -209,219 +278,11 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RecyclerView defineNodeList() {
|
public void assignToolbarElements() {
|
||||||
return (RecyclerView) findViewById(R.id.nodes_list);
|
super.assignToolbarElements();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// Assign the group icon depending of IconPack or custom icon
|
||||||
protected void addOptionsToAdapter(NodeAdapter nodeAdapter) {
|
if ( mCurrentGroup != null ) {
|
||||||
super.addOptionsToAdapter(nodeAdapter);
|
|
||||||
|
|
||||||
nodeAdapter.setActivateContextMenu(true);
|
|
||||||
nodeAdapter.setNodeMenuListener(new NodeAdapter.NodeMenuListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onOpenMenuClick(PwNode node) {
|
|
||||||
switch (node.getType()) {
|
|
||||||
case GROUP:
|
|
||||||
GroupActivity.launch(GroupActivity.this, (PwGroup) node);
|
|
||||||
break;
|
|
||||||
case ENTRY:
|
|
||||||
EntryActivity.launch(GroupActivity.this, (PwEntry) node);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onEditMenuClick(PwNode node) {
|
|
||||||
switch (node.getType()) {
|
|
||||||
case GROUP:
|
|
||||||
oldGroupToUpdate = (PwGroup) node;
|
|
||||||
GroupEditDialogFragment.build(node)
|
|
||||||
.show(getSupportFragmentManager(),
|
|
||||||
GroupEditDialogFragment.TAG_CREATE_GROUP);
|
|
||||||
break;
|
|
||||||
case ENTRY:
|
|
||||||
EntryEditActivity.launch(GroupActivity.this, (PwEntry) node);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onDeleteMenuClick(PwNode node) {
|
|
||||||
switch (node.getType()) {
|
|
||||||
case GROUP:
|
|
||||||
deleteGroup((PwGroup) node);
|
|
||||||
break;
|
|
||||||
case ENTRY:
|
|
||||||
deleteEntry((PwEntry) node);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
// Refresh the group icon
|
|
||||||
assignGroupIcon();
|
|
||||||
// Show button on resume
|
|
||||||
addNodeButtonView.showButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check and display learning views
|
|
||||||
* Displays the explanation for a add, search, sort a new node and lock the database
|
|
||||||
*/
|
|
||||||
private void checkAndPerformedEducation(Menu menu) {
|
|
||||||
|
|
||||||
// If no node, show education to add new one
|
|
||||||
if (mAdapter.getItemCount() <= 0) {
|
|
||||||
if (!PreferencesUtil.isEducationNewNodePerformed(this)) {
|
|
||||||
|
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forView(findViewById(R.id.add_button),
|
|
||||||
getString(R.string.education_new_node_title),
|
|
||||||
getString(R.string.education_new_node_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(false)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
addNodeButtonView.openButtonIfClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_new_node_key);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Else show the search education
|
|
||||||
else if (!PreferencesUtil.isEducationSearchPerformed(this)) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
|
|
||||||
getString(R.string.education_search_title),
|
|
||||||
getString(R.string.education_search_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(true)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
|
||||||
searchItem.expandActionView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_search_key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// If icon not visible
|
|
||||||
Log.w(TAG, "Can't performed education for search");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Else show the sort education
|
|
||||||
else if (!PreferencesUtil.isEducationSortPerformed(this)) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
|
|
||||||
getString(R.string.education_sort_title),
|
|
||||||
getString(R.string.education_sort_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(true)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
MenuItem sortItem = menu.findItem(R.id.menu_sort);
|
|
||||||
onOptionsItemSelected(sortItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_sort_key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(TAG, "Can't performed education for sort");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Else show the lock education
|
|
||||||
else if (!PreferencesUtil.isEducationLockPerformed(this)) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
|
|
||||||
getString(R.string.education_lock_title),
|
|
||||||
getString(R.string.education_lock_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(true)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
MenuItem lockItem = menu.findItem(R.id.menu_lock);
|
|
||||||
onOptionsItemSelected(lockItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(this,
|
|
||||||
R.string.education_lock_key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(TAG, "Can't performed education for lock");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
// Hide button
|
|
||||||
addNodeButtonView.hideButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
|
||||||
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
|
||||||
// Show button if hide after sort
|
|
||||||
addNodeButtonView.showButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign the group icon depending of IconPack or custom icon
|
|
||||||
*/
|
|
||||||
protected void assignGroupIcon() {
|
|
||||||
if (mCurrentGroup != null) {
|
|
||||||
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
|
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
|
||||||
// Retrieve the textColor to tint the icon
|
// Retrieve the textColor to tint the icon
|
||||||
int[] attrs = {R.attr.textColorInverse};
|
int[] attrs = {R.attr.textColorInverse};
|
||||||
@@ -431,13 +292,80 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
} else {
|
} else {
|
||||||
App.getDB().getDrawFactory().assignDatabaseIconTo(this, iconView, mCurrentGroup.getIcon());
|
App.getDB().getDrawFactory().assignDatabaseIconTo(this, iconView, mCurrentGroup.getIcon());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteEntry(PwEntry entry) {
|
if (toolbar != null) {
|
||||||
Handler handler = new Handler();
|
if ( mCurrentGroup.containsParent() )
|
||||||
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
|
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
|
||||||
new AfterDeleteNode(handler, entry));
|
else {
|
||||||
|
toolbar.setNavigationIcon(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrolled(int dy) {
|
||||||
|
if (addNodeButtonView != null)
|
||||||
|
addNodeButtonView.hideButtonOnScrollListener(dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOpenMenuClick(PwNode node) {
|
||||||
|
onNodeClick(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEditMenuClick(PwNode node) {
|
||||||
|
switch (node.getType()) {
|
||||||
|
case GROUP:
|
||||||
|
oldGroupToUpdate = (PwGroup) node;
|
||||||
|
GroupEditDialogFragment.build(node)
|
||||||
|
.show(getSupportFragmentManager(),
|
||||||
|
GroupEditDialogFragment.TAG_CREATE_GROUP);
|
||||||
|
break;
|
||||||
|
case ENTRY:
|
||||||
|
EntryEditActivity.launch(GroupActivity.this, (PwEntry) node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCopyMenuClick(PwNode node) {
|
||||||
|
|
||||||
|
toolbarPasteExpandableLayout.expand();
|
||||||
|
nodeToCopy = node;
|
||||||
|
toolbarPaste.setOnMenuItemClickListener(new OnCopyMenuItemClickListener());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OnCopyMenuItemClickListener implements Toolbar.OnMenuItemClickListener{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
toolbarPasteExpandableLayout.collapse();
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_paste:
|
||||||
|
switch (nodeToCopy.getType()) {
|
||||||
|
case GROUP:
|
||||||
|
Log.e(TAG, "Copy not allowed for group");
|
||||||
|
break;
|
||||||
|
case ENTRY:
|
||||||
|
copyEntry((PwEntry) nodeToCopy, mCurrentGroup);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nodeToCopy = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyEntry(PwEntry entryToCopy, PwGroup newParent) {
|
||||||
|
CopyEntryRunnable task = new CopyEntryRunnable(this, App.getDB(), entryToCopy, newParent,
|
||||||
|
new AfterAddNode());
|
||||||
task.setUpdateProgressTaskStatus(
|
task.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(this,
|
new UpdateProgressTaskStatus(this,
|
||||||
SaveDatabaseProgressTaskDialogFragment.start(
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
@@ -446,11 +374,45 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
new Thread(task).start();
|
new Thread(task).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteGroup(PwGroup group) {
|
@Override
|
||||||
//TODO Verify trash recycle bin
|
public boolean onMoveMenuClick(PwNode node) {
|
||||||
Handler handler = new Handler();
|
|
||||||
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
|
toolbarPasteExpandableLayout.expand();
|
||||||
new AfterDeleteNode(handler, group));
|
nodeToMove = node;
|
||||||
|
toolbarPaste.setOnMenuItemClickListener(new OnMoveMenuItemClickListener());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OnMoveMenuItemClickListener implements Toolbar.OnMenuItemClickListener{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
toolbarPasteExpandableLayout.collapse();
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_paste:
|
||||||
|
switch (nodeToMove.getType()) {
|
||||||
|
case GROUP:
|
||||||
|
moveGroup((PwGroup) nodeToMove, mCurrentGroup);
|
||||||
|
break;
|
||||||
|
case ENTRY:
|
||||||
|
moveEntry((PwEntry) nodeToMove, mCurrentGroup);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nodeToMove = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveGroup(PwGroup groupToMove, PwGroup newParent) {
|
||||||
|
MoveGroupRunnable task = new MoveGroupRunnable(
|
||||||
|
this,
|
||||||
|
App.getDB(),
|
||||||
|
groupToMove,
|
||||||
|
newParent,
|
||||||
|
new AfterAddNode());
|
||||||
task.setUpdateProgressTaskStatus(
|
task.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(this,
|
new UpdateProgressTaskStatus(this,
|
||||||
SaveDatabaseProgressTaskDialogFragment.start(
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
@@ -459,6 +421,213 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
new Thread(task).start();
|
new Thread(task).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moveEntry(PwEntry entryToMove, PwGroup newParent) {
|
||||||
|
MoveEntryRunnable task = new MoveEntryRunnable(
|
||||||
|
this,
|
||||||
|
App.getDB(),
|
||||||
|
entryToMove,
|
||||||
|
newParent,
|
||||||
|
new AfterAddNode());
|
||||||
|
task.setUpdateProgressTaskStatus(
|
||||||
|
new UpdateProgressTaskStatus(this,
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
|
getSupportFragmentManager())
|
||||||
|
));
|
||||||
|
new Thread(task).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDeleteMenuClick(PwNode node) {
|
||||||
|
switch (node.getType()) {
|
||||||
|
case GROUP:
|
||||||
|
deleteGroup((PwGroup) node);
|
||||||
|
break;
|
||||||
|
case ENTRY:
|
||||||
|
deleteEntry((PwEntry) node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteGroup(PwGroup group) {
|
||||||
|
//TODO Verify trash recycle bin
|
||||||
|
DeleteGroupRunnable task = new DeleteGroupRunnable(
|
||||||
|
this,
|
||||||
|
App.getDB(),
|
||||||
|
group,
|
||||||
|
new AfterDeleteNode());
|
||||||
|
task.setUpdateProgressTaskStatus(
|
||||||
|
new UpdateProgressTaskStatus(this,
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
|
getSupportFragmentManager())
|
||||||
|
));
|
||||||
|
new Thread(task).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteEntry(PwEntry entry) {
|
||||||
|
DeleteEntryRunnable task = new DeleteEntryRunnable(
|
||||||
|
this,
|
||||||
|
App.getDB(),
|
||||||
|
entry,
|
||||||
|
new AfterDeleteNode());
|
||||||
|
task.setUpdateProgressTaskStatus(
|
||||||
|
new UpdateProgressTaskStatus(this,
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
|
getSupportFragmentManager())
|
||||||
|
));
|
||||||
|
new Thread(task).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
// Show button on resume
|
||||||
|
if (addNodeButtonView != null)
|
||||||
|
addNodeButtonView.showButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check and display learning views
|
||||||
|
* Displays the explanation for a add, search, sort a new node and lock the database
|
||||||
|
*/
|
||||||
|
private void checkAndPerformedEducation(Menu menu) {
|
||||||
|
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||||
|
|
||||||
|
// If no node, show education to add new one
|
||||||
|
if (listNodesFragment != null
|
||||||
|
&& listNodesFragment.isEmpty()) {
|
||||||
|
if (!PreferencesUtil.isEducationNewNodePerformed(this)) {
|
||||||
|
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forView(findViewById(R.id.add_button),
|
||||||
|
getString(R.string.education_new_node_title),
|
||||||
|
getString(R.string.education_new_node_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(false)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
addNodeButtonView.openButtonIfClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
|
R.string.education_new_node_key);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Else show the search education
|
||||||
|
else if (!PreferencesUtil.isEducationSearchPerformed(this)) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
|
||||||
|
getString(R.string.education_search_title),
|
||||||
|
getString(R.string.education_search_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(true)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
||||||
|
searchItem.expandActionView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
|
R.string.education_search_key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// If icon not visible
|
||||||
|
Log.w(TAG, "Can't performed education for search");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Else show the sort education
|
||||||
|
else if (!PreferencesUtil.isEducationSortPerformed(this)) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
|
||||||
|
getString(R.string.education_sort_title),
|
||||||
|
getString(R.string.education_sort_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(true)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
MenuItem sortItem = menu.findItem(R.id.menu_sort);
|
||||||
|
onOptionsItemSelected(sortItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
|
R.string.education_sort_key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Can't performed education for sort");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Else show the lock education
|
||||||
|
else if (!PreferencesUtil.isEducationLockPerformed(this)) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
TapTargetView.showFor(this,
|
||||||
|
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
|
||||||
|
getString(R.string.education_lock_title),
|
||||||
|
getString(R.string.education_lock_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(true)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
MenuItem lockItem = menu.findItem(R.id.menu_lock);
|
||||||
|
onOptionsItemSelected(lockItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(this,
|
||||||
|
R.string.education_lock_key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Can't performed education for lock");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
// Hide button
|
||||||
|
if (addNodeButtonView != null)
|
||||||
|
addNodeButtonView.hideButton();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
||||||
@@ -500,6 +669,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
// manually launch the real search activity
|
// manually launch the real search activity
|
||||||
final Intent searchIntent = new Intent(getApplicationContext(), SearchResultsActivity.class);
|
final Intent searchIntent = new Intent(getApplicationContext(), SearchResultsActivity.class);
|
||||||
// add query to the Intent Extras
|
// add query to the Intent Extras
|
||||||
|
searchIntent.setAction(Intent.ACTION_SEARCH);
|
||||||
searchIntent.putExtra(SearchManager.QUERY, query);
|
searchIntent.putExtra(SearchManager.QUERY, query);
|
||||||
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
&& autofillHelper.getAssistStructure() != null ) {
|
&& autofillHelper.getAssistStructure() != null ) {
|
||||||
@@ -547,7 +717,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
String name,
|
String name,
|
||||||
PwIcon icon) {
|
PwIcon icon) {
|
||||||
Database database = App.getDB();
|
Database database = App.getDB();
|
||||||
PwIconStandard iconStandard = database.getPwDatabase().getIconFactory().getFirstIcon();
|
PwIconStandard iconStandard = database.getPwDatabase().getIconFactory().getFolderIcon();
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case CREATION:
|
case CREATION:
|
||||||
@@ -564,7 +734,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
|
AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
|
||||||
App.getDB(),
|
App.getDB(),
|
||||||
newGroup,
|
newGroup,
|
||||||
new AfterAddNode(new Handler()));
|
new AfterAddNode());
|
||||||
addGroupRunnable.setUpdateProgressTaskStatus(
|
addGroupRunnable.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(this,
|
new UpdateProgressTaskStatus(this,
|
||||||
SaveDatabaseProgressTaskDialogFragment.start(
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
@@ -583,14 +753,15 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
} catch (Exception ignored) {} // TODO custom icon
|
} catch (Exception ignored) {} // TODO custom icon
|
||||||
updateGroup.setIcon(iconStandard);
|
updateGroup.setIcon(iconStandard);
|
||||||
|
|
||||||
mAdapter.removeNode(oldGroupToUpdate);
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.removeNode(oldGroupToUpdate);
|
||||||
|
|
||||||
// If group updated save it in the database
|
// If group updated save it in the database
|
||||||
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
|
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
|
||||||
App.getDB(),
|
App.getDB(),
|
||||||
oldGroupToUpdate,
|
oldGroupToUpdate,
|
||||||
updateGroup,
|
updateGroup,
|
||||||
new AfterUpdateNode(new Handler()));
|
new AfterUpdateNode());
|
||||||
updateGroupRunnable.setUpdateProgressTaskStatus(
|
updateGroupRunnable.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(this,
|
new UpdateProgressTaskStatus(this,
|
||||||
SaveDatabaseProgressTaskDialogFragment.start(
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
@@ -603,10 +774,79 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
class AfterAddNode extends AfterActionNodeOnFinish {
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
outState.putSerializable(OLD_GROUP_TO_UPDATE_KEY, oldGroupToUpdate);
|
public void run(PwNode oldNode, PwNode newNode) {
|
||||||
super.onSaveInstanceState(outState);
|
super.run();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
if (mSuccess) {
|
||||||
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.addNode(newNode);
|
||||||
|
} else {
|
||||||
|
displayMessage(GroupActivity.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AfterUpdateNode extends AfterActionNodeOnFinish {
|
||||||
|
|
||||||
|
public void run(PwNode oldNode, PwNode newNode) {
|
||||||
|
super.run();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
if (mSuccess) {
|
||||||
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.updateNode(oldNode, newNode);
|
||||||
|
} else {
|
||||||
|
displayMessage(GroupActivity.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AfterDeleteNode extends AfterActionNodeOnFinish {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(PwNode oldNode, PwNode newNode) {
|
||||||
|
super.run();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
if ( mSuccess) {
|
||||||
|
|
||||||
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.removeNode(oldNode);
|
||||||
|
|
||||||
|
PwGroup parent = oldNode.getParent();
|
||||||
|
Database db = App.getDB();
|
||||||
|
PwDatabase database = db.getPwDatabase();
|
||||||
|
if (db.isRecycleBinAvailable() &&
|
||||||
|
db.isRecycleBinEnabled()) {
|
||||||
|
PwGroup recycleBin = database.getRecycleBin();
|
||||||
|
// Add trash if it doesn't exists
|
||||||
|
if (parent.equals(recycleBin)
|
||||||
|
&& mCurrentGroup != null
|
||||||
|
&& mCurrentGroup.getParent() == null
|
||||||
|
&& !mCurrentGroup.equals(recycleBin)) {
|
||||||
|
|
||||||
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.addNode(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mHandler.post(new UIToastTask(GroupActivity.this, "Unrecoverable error: " + mMessage));
|
||||||
|
App.setShutdown();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -637,4 +877,18 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void openGroup(PwGroup group) {
|
||||||
|
super.openGroup(group);
|
||||||
|
if (addNodeButtonView != null)
|
||||||
|
addNodeButtonView.showButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
if (addNodeButtonView != null)
|
||||||
|
addNodeButtonView.showButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,53 +22,44 @@ package com.kunzisoft.keepass.activities;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.assist.AssistStructure;
|
import android.app.assist.AssistStructure;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.Editor;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.support.annotation.Nullable;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||||
import com.kunzisoft.keepass.compat.EditorCompat;
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
|
||||||
import com.kunzisoft.keepass.database.PwDatabase;
|
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
import com.kunzisoft.keepass.database.PwNode;
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
import com.kunzisoft.keepass.database.SortNodeEnum;
|
import com.kunzisoft.keepass.database.SortNodeEnum;
|
||||||
import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish;
|
|
||||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
|
||||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||||
|
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
|
||||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
|
||||||
import com.kunzisoft.keepass.tasks.UIToastTask;
|
|
||||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||||
|
|
||||||
public abstract class ListNodesActivity extends LockingActivity
|
public abstract class ListNodesActivity extends LockingActivity
|
||||||
implements AssignMasterKeyDialogFragment.AssignPasswordDialogListener,
|
implements AssignMasterKeyDialogFragment.AssignPasswordDialogListener,
|
||||||
NodeAdapter.OnNodeClickCallback,
|
NodeAdapter.NodeClickCallback,
|
||||||
SortDialogFragment.SortSelectionListener {
|
SortDialogFragment.SortSelectionListener {
|
||||||
|
|
||||||
protected PwGroup mCurrentGroup;
|
protected static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
||||||
protected NodeAdapter mAdapter;
|
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
|
||||||
|
|
||||||
|
protected static final String LIST_NODES_FRAGMENT_TAG = "LIST_NODES_FRAGMENT_TAG";
|
||||||
|
protected ListNodesFragment listNodesFragment;
|
||||||
|
|
||||||
|
protected PwGroup mCurrentGroup;
|
||||||
|
protected TextView groupNameView;
|
||||||
|
|
||||||
|
protected boolean entrySelectionMode;
|
||||||
protected AutofillHelper autofillHelper;
|
protected AutofillHelper autofillHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,61 +75,85 @@ public abstract class ListNodesActivity extends LockingActivity
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
|
|
||||||
// TODO Move in search
|
mCurrentGroup = retrieveCurrentGroup(savedInstanceState);
|
||||||
setContentView(R.layout.list_nodes);
|
|
||||||
|
|
||||||
mCurrentGroup = initCurrentGroup();
|
initializeListNodesFragment(mCurrentGroup);
|
||||||
|
|
||||||
mAdapter = new NodeAdapter(this);
|
|
||||||
addOptionsToAdapter(mAdapter);
|
|
||||||
|
|
||||||
|
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
autofillHelper = new AutofillHelper();
|
autofillHelper = new AutofillHelper();
|
||||||
autofillHelper.retrieveAssistStructure(getIntent());
|
autofillHelper.retrieveAssistStructure(getIntent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract PwGroup initCurrentGroup();
|
protected abstract PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState);
|
||||||
|
|
||||||
protected abstract RecyclerView defineNodeList();
|
|
||||||
|
|
||||||
protected void addOptionsToAdapter(NodeAdapter nodeAdapter) {
|
|
||||||
mAdapter.setOnNodeClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// Add elements to the list
|
// Refresh the title
|
||||||
mAdapter.rebuildList(mCurrentGroup);
|
assignToolbarElements();
|
||||||
assignListToNodeAdapter(defineNodeList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setGroupTitle() {
|
protected void initializeListNodesFragment(PwGroup currentGroup) {
|
||||||
if ( mCurrentGroup != null ) {
|
listNodesFragment = (ListNodesFragment) getSupportFragmentManager()
|
||||||
String name = mCurrentGroup.getName();
|
.findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||||
TextView tv = findViewById(R.id.group_name);
|
if (listNodesFragment == null)
|
||||||
if ( name != null && name.length() > 0 ) {
|
listNodesFragment = ListNodesFragment.newInstance(currentGroup.getId());
|
||||||
if ( tv != null ) {
|
}
|
||||||
tv.setText(name);
|
|
||||||
}
|
/**
|
||||||
} else {
|
* Attach the fragment's list of node.
|
||||||
if ( tv != null ) {
|
* <br />
|
||||||
tv.setText(getText(R.string.root));
|
* <strong>R.id.nodes_list_fragment_container</strong> must be the id of the container
|
||||||
}
|
*/
|
||||||
}
|
protected void attachFragmentToContentView() {
|
||||||
}
|
getSupportFragmentManager().beginTransaction().replace(
|
||||||
|
R.id.nodes_list_fragment_container,
|
||||||
|
listNodesFragment,
|
||||||
|
LIST_NODES_FRAGMENT_TAG)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assignToolbarElements() {
|
||||||
|
if (mCurrentGroup != null) {
|
||||||
|
String title = mCurrentGroup.getName();
|
||||||
|
if (title != null && title.length() > 0) {
|
||||||
|
if (groupNameView != null) {
|
||||||
|
groupNameView.setText(title);
|
||||||
|
groupNameView.invalidate();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (groupNameView != null) {
|
||||||
|
groupNameView.setText(getText(R.string.root));
|
||||||
|
groupNameView.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
MenuUtil.contributionMenuInflater(inflater, menu);
|
||||||
|
inflater.inflate(R.menu.default_menu, menu);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
|
@Override
|
||||||
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
switch ( item.getItemId() ) {
|
||||||
recyclerView.setAdapter(mAdapter);
|
default:
|
||||||
|
// Check the time lock before launching settings
|
||||||
|
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, true);
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,7 +166,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
|||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
switch (node.getType()) {
|
switch (node.getType()) {
|
||||||
case GROUP:
|
case GROUP:
|
||||||
GroupActivity.launch(this, (PwGroup) node, assistStructure);
|
openGroup((PwGroup) node);
|
||||||
break;
|
break;
|
||||||
case ENTRY:
|
case ENTRY:
|
||||||
// Build response with the entry selected
|
// Build response with the entry selected
|
||||||
@@ -162,80 +177,49 @@ public abstract class ListNodesActivity extends LockingActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( assistStructure == null ){
|
if ( assistStructure == null ){
|
||||||
switch (node.getType()) {
|
if (entrySelectionMode) {
|
||||||
case GROUP:
|
switch (node.getType()) {
|
||||||
GroupActivity.launch(this, (PwGroup) node);
|
case GROUP:
|
||||||
break;
|
openGroup((PwGroup) node);
|
||||||
case ENTRY:
|
break;
|
||||||
EntryActivity.launch(this, (PwEntry) node);
|
case ENTRY:
|
||||||
break;
|
EntrySelectionHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (node.getType()) {
|
||||||
|
case GROUP:
|
||||||
|
openGroup((PwGroup) node);
|
||||||
|
break;
|
||||||
|
case ENTRY:
|
||||||
|
EntryActivity.launch(this, (PwEntry) node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void openGroup(PwGroup group) {
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
// Check Timeout
|
||||||
super.onCreateOptionsMenu(menu);
|
if (checkTimeIsAllowedOrFinish(this)) {
|
||||||
|
startRecordTime(this);
|
||||||
MenuInflater inflater = getMenuInflater();
|
|
||||||
MenuUtil.contributionMenuInflater(inflater, menu);
|
|
||||||
inflater.inflate(R.menu.tree, menu);
|
|
||||||
inflater.inflate(R.menu.default_menu, menu);
|
|
||||||
|
|
||||||
return true;
|
ListNodesFragment newListNodeFragment = ListNodesFragment.newInstance(group.getId());
|
||||||
}
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left,
|
||||||
@Override
|
R.anim.slide_in_left, R.anim.slide_out_right)
|
||||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
.replace(R.id.nodes_list_fragment_container,
|
||||||
// Toggle setting
|
newListNodeFragment,
|
||||||
Editor editor = prefs.edit();
|
LIST_NODES_FRAGMENT_TAG)
|
||||||
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
|
.addToBackStack(LIST_NODES_FRAGMENT_TAG)
|
||||||
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
|
.commit();
|
||||||
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
|
listNodesFragment = newListNodeFragment;
|
||||||
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
|
mCurrentGroup = group;
|
||||||
EditorCompat.apply(editor);
|
assignToolbarElements();
|
||||||
|
}
|
||||||
// Tell the adapter to refresh it's list
|
|
||||||
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
|
|
||||||
mAdapter.rebuildList(mCurrentGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch ( item.getItemId() ) {
|
|
||||||
|
|
||||||
case R.id.menu_sort:
|
|
||||||
SortDialogFragment sortDialogFragment;
|
|
||||||
|
|
||||||
PwDatabase database = App.getDB().getPwDatabase();
|
|
||||||
/*
|
|
||||||
// TODO Recycle bin bottom
|
|
||||||
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
|
|
||||||
sortDialogFragment =
|
|
||||||
SortDialogFragment.getInstance(
|
|
||||||
PrefsUtil.getListSort(this),
|
|
||||||
PrefsUtil.getAscendingSort(this),
|
|
||||||
PrefsUtil.getGroupsBeforeSort(this),
|
|
||||||
PrefsUtil.getRecycleBinBottomSort(this));
|
|
||||||
} else {
|
|
||||||
*/
|
|
||||||
sortDialogFragment =
|
|
||||||
SortDialogFragment.getInstance(
|
|
||||||
PreferencesUtil.getListSort(this),
|
|
||||||
PreferencesUtil.getAscendingSort(this),
|
|
||||||
PreferencesUtil.getGroupsBeforeSort(this));
|
|
||||||
//}
|
|
||||||
|
|
||||||
sortDialogFragment.show(getSupportFragmentManager(), "sortDialog");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Check the time lock before launching settings
|
|
||||||
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, true);
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAssignKeyDialogPositiveClick(
|
public void onAssignKeyDialogPositiveClick(
|
||||||
boolean masterPasswordChecked, String masterPassword,
|
boolean masterPasswordChecked, String masterPassword,
|
||||||
@@ -254,29 +238,17 @@ public abstract class ListNodesActivity extends LockingActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||||
|
if (listNodesFragment != null)
|
||||||
|
listNodesFragment.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
switch (requestCode) {
|
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
|
||||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
|
||||||
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
|
||||||
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
|
|
||||||
if (newNode != null) {
|
|
||||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
|
||||||
mAdapter.addNode(newNode);
|
|
||||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
|
||||||
//mAdapter.updateLastNodeRegister(newNode);
|
|
||||||
mAdapter.rebuildList(mCurrentGroup);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
@@ -301,83 +273,18 @@ public abstract class ListNodesActivity extends LockingActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AfterAddNode extends AfterActionNodeOnFinish {
|
@Override
|
||||||
AfterAddNode(Handler handler) {
|
public void onBackPressed() {
|
||||||
super(handler);
|
if (checkTimeIsAllowedOrFinish(this)) {
|
||||||
}
|
startRecordTime(this);
|
||||||
|
|
||||||
public void run(PwNode oldNode, PwNode newNode) {
|
super.onBackPressed();
|
||||||
super.run();
|
|
||||||
|
|
||||||
runOnUiThread(() -> {
|
listNodesFragment = (ListNodesFragment) getSupportFragmentManager().findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||||
if (mSuccess) {
|
// to refresh fragment
|
||||||
mAdapter.addNode(newNode);
|
listNodesFragment.rebuildList();
|
||||||
} else {
|
mCurrentGroup = listNodesFragment.getMainGroup();
|
||||||
displayMessage(ListNodesActivity.this);
|
assignToolbarElements();
|
||||||
}
|
|
||||||
|
|
||||||
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AfterUpdateNode extends AfterActionNodeOnFinish {
|
|
||||||
AfterUpdateNode(Handler handler) {
|
|
||||||
super(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(PwNode oldNode, PwNode newNode) {
|
|
||||||
super.run();
|
|
||||||
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
if (mSuccess) {
|
|
||||||
mAdapter.updateNode(oldNode, newNode);
|
|
||||||
} else {
|
|
||||||
displayMessage(ListNodesActivity.this);
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AfterDeleteNode extends OnFinishRunnable {
|
|
||||||
private PwNode pwNode;
|
|
||||||
|
|
||||||
AfterDeleteNode(Handler handler, PwNode pwNode) {
|
|
||||||
super(handler);
|
|
||||||
this.pwNode = pwNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
super.run();
|
|
||||||
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
if ( mSuccess) {
|
|
||||||
mAdapter.removeNode(pwNode);
|
|
||||||
PwGroup parent = pwNode.getParent();
|
|
||||||
Database db = App.getDB();
|
|
||||||
PwDatabase database = db.getPwDatabase();
|
|
||||||
if (db.isRecycleBinAvailable() &&
|
|
||||||
db.isRecycleBinEnabled()) {
|
|
||||||
PwGroup recycleBin = database.getRecycleBin();
|
|
||||||
// Add trash if it doesn't exists
|
|
||||||
if (parent.equals(recycleBin)
|
|
||||||
&& mCurrentGroup != null
|
|
||||||
&& mCurrentGroup.getParent() == null
|
|
||||||
&& !mCurrentGroup.equals(recycleBin)) {
|
|
||||||
mAdapter.addNode(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage));
|
|
||||||
App.setShutdown();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,283 @@
|
|||||||
|
package com.kunzisoft.keepass.activities;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
||||||
|
import com.kunzisoft.keepass.app.App;
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwDatabase;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroupId;
|
||||||
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
|
import com.kunzisoft.keepass.database.SortNodeEnum;
|
||||||
|
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||||
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
|
import com.kunzisoft.keepass.stylish.StylishFragment;
|
||||||
|
|
||||||
|
public class ListNodesFragment extends StylishFragment implements
|
||||||
|
SortDialogFragment.SortSelectionListener {
|
||||||
|
|
||||||
|
private static final String TAG = ListNodesFragment.class.getName();
|
||||||
|
|
||||||
|
private static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
||||||
|
|
||||||
|
private NodeAdapter.NodeClickCallback nodeClickCallback;
|
||||||
|
private NodeAdapter.NodeMenuListener nodeMenuListener;
|
||||||
|
private OnScrollListener onScrollListener;
|
||||||
|
|
||||||
|
private RecyclerView listView;
|
||||||
|
protected PwGroup mCurrentGroup;
|
||||||
|
protected NodeAdapter mAdapter;
|
||||||
|
|
||||||
|
// Preferences for sorting
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
|
public static ListNodesFragment newInstance(PwGroupId groupId) {
|
||||||
|
Bundle bundle=new Bundle();
|
||||||
|
if (groupId != null) {
|
||||||
|
bundle.putSerializable(GROUP_ID_KEY, groupId);
|
||||||
|
}
|
||||||
|
ListNodesFragment listNodesFragment = new ListNodesFragment();
|
||||||
|
listNodesFragment.setArguments(bundle);
|
||||||
|
return listNodesFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
try {
|
||||||
|
nodeClickCallback = (NodeAdapter.NodeClickCallback) context;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
// The activity doesn't implement the interface, throw exception
|
||||||
|
throw new ClassCastException(context.toString()
|
||||||
|
+ " must implement " + NodeAdapter.NodeClickCallback.class.getName());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
nodeMenuListener = (NodeAdapter.NodeMenuListener) context;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
nodeMenuListener = null;
|
||||||
|
// Context menu can be omit
|
||||||
|
Log.w(TAG, context.toString()
|
||||||
|
+ " must implement " + NodeAdapter.NodeMenuListener.class.getName());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
onScrollListener = (OnScrollListener) context;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
onScrollListener = null;
|
||||||
|
// Context menu can be omit
|
||||||
|
Log.w(TAG, context.toString()
|
||||||
|
+ " must implement " + RecyclerView.OnScrollListener.class.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
mCurrentGroup = initCurrentGroup();
|
||||||
|
if (getActivity() != null) {
|
||||||
|
mAdapter = new NodeAdapter(getContextThemed(), getActivity().getMenuInflater());
|
||||||
|
mAdapter.setOnNodeClickListener(nodeClickCallback);
|
||||||
|
|
||||||
|
if (nodeMenuListener != null) {
|
||||||
|
mAdapter.setActivateContextMenu(true);
|
||||||
|
mAdapter.setNodeMenuListener(nodeMenuListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PwGroup initCurrentGroup() { // TODO Change by parcelable
|
||||||
|
|
||||||
|
Database db = App.getDB();
|
||||||
|
PwGroup root = db.getPwDatabase().getRootGroup();
|
||||||
|
|
||||||
|
PwGroup currentGroup = null;
|
||||||
|
if (getArguments() != null) {
|
||||||
|
// Contains only the group id, so the group must be retrieve
|
||||||
|
if (getArguments().containsKey(GROUP_ID_KEY)) {
|
||||||
|
PwGroupId pwGroupId = (PwGroupId) getArguments().getSerializable(GROUP_ID_KEY);
|
||||||
|
if ( pwGroupId != null )
|
||||||
|
currentGroup = db.getPwDatabase().getGroupByGroupId(pwGroupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( currentGroup == null ) {
|
||||||
|
currentGroup = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
|
// To apply theme
|
||||||
|
View rootView = inflater.cloneInContext(getContextThemed())
|
||||||
|
.inflate(R.layout.list_nodes_fragment, container, false);
|
||||||
|
listView = rootView.findViewById(R.id.nodes_list);
|
||||||
|
|
||||||
|
if (onScrollListener != null) {
|
||||||
|
listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
onScrollListener.onScrolled(dy);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
rebuildList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rebuildList() {
|
||||||
|
// Add elements to the list
|
||||||
|
mAdapter.rebuildList(mCurrentGroup);
|
||||||
|
assignListToNodeAdapter(listView);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
|
||||||
|
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
recyclerView.setAdapter(mAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||||
|
// Toggle setting
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
|
||||||
|
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
|
||||||
|
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
|
||||||
|
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
// Tell the adapter to refresh it's list
|
||||||
|
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
|
||||||
|
mAdapter.rebuildList(mCurrentGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.tree, menu);
|
||||||
|
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch ( item.getItemId() ) {
|
||||||
|
|
||||||
|
case R.id.menu_sort:
|
||||||
|
SortDialogFragment sortDialogFragment;
|
||||||
|
|
||||||
|
PwDatabase database = App.getDB().getPwDatabase();
|
||||||
|
/*
|
||||||
|
// TODO Recycle bin bottom
|
||||||
|
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
|
||||||
|
sortDialogFragment =
|
||||||
|
SortDialogFragment.getInstance(
|
||||||
|
PrefsUtil.getListSort(this),
|
||||||
|
PrefsUtil.getAscendingSort(this),
|
||||||
|
PrefsUtil.getGroupsBeforeSort(this),
|
||||||
|
PrefsUtil.getRecycleBinBottomSort(this));
|
||||||
|
} else {
|
||||||
|
*/
|
||||||
|
sortDialogFragment =
|
||||||
|
SortDialogFragment.getInstance(
|
||||||
|
PreferencesUtil.getListSort(getContext()),
|
||||||
|
PreferencesUtil.getAscendingSort(getContext()),
|
||||||
|
PreferencesUtil.getGroupsBeforeSort(getContext()));
|
||||||
|
//}
|
||||||
|
|
||||||
|
sortDialogFragment.show(getChildFragmentManager(), "sortDialog");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
switch (requestCode) {
|
||||||
|
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||||
|
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
||||||
|
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||||
|
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
|
||||||
|
if (newNode != null) {
|
||||||
|
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||||
|
mAdapter.addNode(newNode);
|
||||||
|
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||||
|
//mAdapter.updateLastNodeRegister(newNode);
|
||||||
|
mAdapter.rebuildList(mCurrentGroup);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return mAdapter == null || mAdapter.getItemCount() <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNode(PwNode newNode) {
|
||||||
|
mAdapter.addNode(newNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateNode(PwNode oldNode, PwNode newNode) {
|
||||||
|
mAdapter.updateNode(oldNode, newNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeNode(PwNode pwNode) {
|
||||||
|
mAdapter.removeNode(pwNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PwGroup getMainGroup() {
|
||||||
|
return mCurrentGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnScrollListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback method to be invoked when the RecyclerView has been scrolled. This will be
|
||||||
|
* called after the scroll has completed.
|
||||||
|
*
|
||||||
|
* @param dy The amount of vertical scroll.
|
||||||
|
*/
|
||||||
|
void onScrolled(int dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,8 +20,6 @@
|
|||||||
package com.kunzisoft.keepass.adapters;
|
package com.kunzisoft.keepass.adapters;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
@@ -30,7 +28,7 @@ class EntryViewHolder extends BasicViewHolder {
|
|||||||
EntryViewHolder(View itemView) {
|
EntryViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
container = itemView.findViewById(R.id.entry_container);
|
container = itemView.findViewById(R.id.entry_container);
|
||||||
icon = (ImageView) itemView.findViewById(R.id.entry_icon);
|
icon = itemView.findViewById(R.id.entry_icon);
|
||||||
text = (TextView) itemView.findViewById(R.id.entry_text);
|
text = itemView.findViewById(R.id.entry_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@
|
|||||||
package com.kunzisoft.keepass.adapters;
|
package com.kunzisoft.keepass.adapters;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
@@ -30,7 +28,7 @@ class GroupViewHolder extends BasicViewHolder {
|
|||||||
GroupViewHolder(View itemView) {
|
GroupViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
container = itemView.findViewById(R.id.group_container);
|
container = itemView.findViewById(R.id.group_container);
|
||||||
icon = (ImageView) itemView.findViewById(R.id.group_icon);
|
icon = itemView.findViewById(R.id.group_icon);
|
||||||
text = (TextView) itemView.findViewById(R.id.group_text);
|
text = itemView.findViewById(R.id.group_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.v7.util.SortedList;
|
import android.support.v7.util.SortedList;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.util.SortedListAdapterCallback;
|
import android.support.v7.widget.util.SortedListAdapterCallback;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -47,12 +48,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
|
private MenuInflater menuInflater;
|
||||||
private float textSize;
|
private float textSize;
|
||||||
|
private float iconSize;
|
||||||
private SortNodeEnum listSort;
|
private SortNodeEnum listSort;
|
||||||
private boolean groupsBeforeSort;
|
private boolean groupsBeforeSort;
|
||||||
private boolean ascendingSort;
|
private boolean ascendingSort;
|
||||||
|
|
||||||
private OnNodeClickCallback onNodeClickCallback;
|
private NodeClickCallback nodeClickCallback;
|
||||||
private NodeMenuListener nodeMenuListener;
|
private NodeMenuListener nodeMenuListener;
|
||||||
private boolean activateContextMenu;
|
private boolean activateContextMenu;
|
||||||
|
|
||||||
@@ -63,13 +66,11 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
* Create node list adapter with contextMenu or not
|
* Create node list adapter with contextMenu or not
|
||||||
* @param context Context to use
|
* @param context Context to use
|
||||||
*/
|
*/
|
||||||
public NodeAdapter(final Context context) {
|
public NodeAdapter(final Context context, MenuInflater menuInflater) {
|
||||||
this.inflater = LayoutInflater.from(context);
|
this.inflater = LayoutInflater.from(context);
|
||||||
|
this.menuInflater = menuInflater;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.textSize = PreferencesUtil.getListTextSize(context);
|
assignPreferences();
|
||||||
this.listSort = PreferencesUtil.getListSort(context);
|
|
||||||
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
|
|
||||||
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
|
|
||||||
this.activateContextMenu = false;
|
this.activateContextMenu = false;
|
||||||
|
|
||||||
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
|
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
|
||||||
@@ -101,11 +102,26 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
this.activateContextMenu = activate;
|
this.activateContextMenu = activate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assignPreferences() {
|
||||||
|
this.textSize = PreferencesUtil.getListTextSize(context);
|
||||||
|
// Retrieve the icon size
|
||||||
|
int iconDefaultSize = (int) TypedValue.applyDimension(
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP,
|
||||||
|
context.getResources().getInteger(R.integer.list_icon_size_default),
|
||||||
|
context.getResources().getDisplayMetrics()
|
||||||
|
);
|
||||||
|
this.iconSize = iconDefaultSize * textSize / Float.parseFloat(context.getString(R.string.list_size_default));
|
||||||
|
this.listSort = PreferencesUtil.getListSort(context);
|
||||||
|
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
|
||||||
|
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rebuild the list by clear and build children from the group
|
* Rebuild the list by clear and build children from the group
|
||||||
*/
|
*/
|
||||||
public void rebuildList(PwGroup group) {
|
public void rebuildList(PwGroup group) {
|
||||||
this.nodeSortedList.clear();
|
this.nodeSortedList.clear();
|
||||||
|
assignPreferences();
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
this.nodeSortedList.addAll(group.getDirectChildren());
|
this.nodeSortedList.addAll(group.getDirectChildren());
|
||||||
}
|
}
|
||||||
@@ -196,7 +212,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
holder.container.setOnCreateContextMenuListener(
|
holder.container.setOnCreateContextMenuListener(
|
||||||
new ContextMenuBuilder(subNode, nodeMenuListener));
|
new ContextMenuBuilder(subNode, nodeMenuListener));
|
||||||
}
|
}
|
||||||
// Assign text size
|
// Assign image and text size
|
||||||
|
// Relative size of the icon
|
||||||
|
holder.icon.getLayoutParams().height = ((int) iconSize);
|
||||||
|
holder.icon.getLayoutParams().width = ((int) iconSize);
|
||||||
holder.text.setTextSize(textSize);
|
holder.text.setTextSize(textSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +227,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
/**
|
/**
|
||||||
* Assign a listener when a node is clicked
|
* Assign a listener when a node is clicked
|
||||||
*/
|
*/
|
||||||
public void setOnNodeClickListener(OnNodeClickCallback onNodeClickCallback) {
|
public void setOnNodeClickListener(NodeClickCallback nodeClickCallback) {
|
||||||
this.onNodeClickCallback = onNodeClickCallback;
|
this.nodeClickCallback = nodeClickCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,7 +241,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
/**
|
/**
|
||||||
* Callback listener to redefine to do an action when a node is click
|
* Callback listener to redefine to do an action when a node is click
|
||||||
*/
|
*/
|
||||||
public interface OnNodeClickCallback {
|
public interface NodeClickCallback {
|
||||||
void onNodeClick(PwNode node);
|
void onNodeClick(PwNode node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +251,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
public interface NodeMenuListener {
|
public interface NodeMenuListener {
|
||||||
boolean onOpenMenuClick(PwNode node);
|
boolean onOpenMenuClick(PwNode node);
|
||||||
boolean onEditMenuClick(PwNode node);
|
boolean onEditMenuClick(PwNode node);
|
||||||
|
boolean onCopyMenuClick(PwNode node);
|
||||||
|
boolean onMoveMenuClick(PwNode node);
|
||||||
boolean onDeleteMenuClick(PwNode node);
|
boolean onDeleteMenuClick(PwNode node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,8 +268,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (onNodeClickCallback != null)
|
if (nodeClickCallback != null)
|
||||||
onNodeClickCallback.onNodeClick(node);
|
nodeClickCallback.onNodeClick(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,10 +278,6 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
*/
|
*/
|
||||||
private class ContextMenuBuilder implements View.OnCreateContextMenuListener {
|
private class ContextMenuBuilder implements View.OnCreateContextMenuListener {
|
||||||
|
|
||||||
private static final int MENU_OPEN = Menu.FIRST;
|
|
||||||
private static final int MENU_EDIT = MENU_OPEN + 1;
|
|
||||||
private static final int MENU_DELETE = MENU_EDIT + 1;
|
|
||||||
|
|
||||||
private PwNode node;
|
private PwNode node;
|
||||||
private NodeMenuListener menuListener;
|
private NodeMenuListener menuListener;
|
||||||
|
|
||||||
@@ -271,15 +288,30 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
||||||
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open);
|
menuInflater.inflate(R.menu.node_menu, contextMenu);
|
||||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
|
||||||
|
// TODO COPY For Group
|
||||||
|
if (node.getType().equals(PwNode.Type.GROUP)) {
|
||||||
|
contextMenu.removeItem(R.id.menu_copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem menuItem = contextMenu.findItem(R.id.menu_open);
|
||||||
|
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
if (!App.getDB().isReadOnly() && !node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
if (!App.getDB().isReadOnly() && !node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||||
// Edition
|
// Edition
|
||||||
clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit);
|
menuItem = contextMenu.findItem(R.id.menu_edit);
|
||||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
|
// Copy (not for group)
|
||||||
|
if (node.getType().equals(PwNode.Type.ENTRY)) {
|
||||||
|
menuItem = contextMenu.findItem(R.id.menu_copy);
|
||||||
|
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
|
}
|
||||||
|
// Move
|
||||||
|
menuItem = contextMenu.findItem(R.id.menu_move);
|
||||||
|
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
// Deletion
|
// Deletion
|
||||||
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete);
|
menuItem = contextMenu.findItem(R.id.menu_delete);
|
||||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,11 +321,15 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
if (menuListener == null)
|
if (menuListener == null)
|
||||||
return false;
|
return false;
|
||||||
switch ( item.getItemId() ) {
|
switch ( item.getItemId() ) {
|
||||||
case MENU_OPEN:
|
case R.id.menu_open:
|
||||||
return menuListener.onOpenMenuClick(node);
|
return menuListener.onOpenMenuClick(node);
|
||||||
case MENU_EDIT:
|
case R.id.menu_edit:
|
||||||
return menuListener.onEditMenuClick(node);
|
return menuListener.onEditMenuClick(node);
|
||||||
case MENU_DELETE:
|
case R.id.menu_copy:
|
||||||
|
return menuListener.onCopyMenuClick(node);
|
||||||
|
case R.id.menu_move:
|
||||||
|
return menuListener.onMoveMenuClick(node);
|
||||||
|
case R.id.menu_delete:
|
||||||
return menuListener.onDeleteMenuClick(node);
|
return menuListener.onDeleteMenuClick(node);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class AutoFillAuthActivity extends AppCompatActivity {
|
|||||||
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
|
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
|
||||||
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
|
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
|
||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
FileSelectActivity.launch(this, assistStructure);
|
FileSelectActivity.launchForAutofillResult(this, assistStructure);
|
||||||
} else {
|
} else {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import android.widget.RemoteViews;
|
|||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,6 +65,7 @@ public class AutofillHelper {
|
|||||||
|
|
||||||
public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) {
|
public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) {
|
||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
|
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
|
||||||
intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure);
|
intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ public class AutofillHelper {
|
|||||||
/**
|
/**
|
||||||
* Utility method to loop and close each activity with return data
|
* Utility method to loop and close each activity with return data
|
||||||
*/
|
*/
|
||||||
public static void onActivityResultSetResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
|
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
activity.setResult(resultCode, data);
|
activity.setResult(resultCode, data);
|
||||||
@@ -152,15 +154,6 @@ public class AutofillHelper {
|
|||||||
if (resultCode == Activity.RESULT_CANCELED) {
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
activity.setResult(Activity.RESULT_CANCELED);
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility method to loop and close each activity with return data
|
|
||||||
*/
|
|
||||||
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
||||||
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
|
|
||||||
onActivityResultSetResult(activity, requestCode, resultCode, data);
|
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.compat;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class BackupManagerCompat {
|
|
||||||
private static Class classBackupManager;
|
|
||||||
private static Constructor constructorBackupManager;
|
|
||||||
private static Method dataChanged;
|
|
||||||
|
|
||||||
private Object backupManager;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
classBackupManager = Class.forName("android.app.backup.BackupManager");
|
|
||||||
constructorBackupManager = classBackupManager.getConstructor(Context.class);
|
|
||||||
dataChanged = classBackupManager.getMethod("dataChanged", (Class[]) null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Do nothing, class does not exist
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BackupManagerCompat(Context ctx) {
|
|
||||||
if (constructorBackupManager != null) {
|
|
||||||
try {
|
|
||||||
backupManager = constructorBackupManager.newInstance(ctx);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dataChanged() {
|
|
||||||
if (backupManager != null && dataChanged != null) {
|
|
||||||
try {
|
|
||||||
dataChanged.invoke(backupManager, (Object[]) null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.compat;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
// This compatiblity hack can go away when support for Android 1.5 api level 3 is dropped
|
|
||||||
public class BitmapDrawableCompat {
|
|
||||||
private static Constructor<BitmapDrawable> constResBitmap;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
constResBitmap = BitmapDrawable.class.getConstructor(Resources.class, Bitmap.class);
|
|
||||||
// This constructor is support in this api version
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This constructor is not supported
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BitmapDrawable getBitmapDrawable(Resources res, Bitmap bitmap) {
|
|
||||||
if (constResBitmap != null) {
|
|
||||||
try {
|
|
||||||
return constResBitmap.newInstance(res, bitmap);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Do nothing, fall through to the safe constructor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BitmapDrawable(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.compat;
|
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class BuildCompat {
|
|
||||||
private static Field manufacturer;
|
|
||||||
private static String manuText;
|
|
||||||
|
|
||||||
public static final int VERSION_CODE_GINGERBREAD = 9;
|
|
||||||
public static final int VERSION_CODE_ICE_CREAM_SANDWICH = 14;
|
|
||||||
public static final int VERSION_CODE_JELLY_BEAN = 16;
|
|
||||||
public static final int VERSION_CODE_JELLY_BEAN_MR2 = 18;
|
|
||||||
public static final int VERSION_KITKAT = 19;
|
|
||||||
public static final int VERSION_CODE_M = 23;
|
|
||||||
|
|
||||||
private static Field versionSDK;
|
|
||||||
private static int versionInt;
|
|
||||||
|
|
||||||
static {
|
|
||||||
// MANUFACTURER is only available in API version 4 and later
|
|
||||||
try {
|
|
||||||
manufacturer = Build.class.getField("MANUFACTURER");
|
|
||||||
manuText = (String) manufacturer.get(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
manuText = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDK is only available in API version 4 and later
|
|
||||||
try {
|
|
||||||
versionSDK = Build.VERSION.class.getField("SDK_INT");
|
|
||||||
versionInt = versionSDK.getInt(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
try {
|
|
||||||
versionInt = Integer.parseInt(Build.VERSION.SDK);
|
|
||||||
} catch (Exception nfe) {
|
|
||||||
versionInt = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getManufacturer() {
|
|
||||||
return manuText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getSdkVersion() {
|
|
||||||
return versionInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,9 +25,6 @@ import android.net.Uri;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ClipDataCompat {
|
public class ClipDataCompat {
|
||||||
private static Class clipData;
|
|
||||||
private static Class clipDataItem;
|
|
||||||
private static Class clipDescription;
|
|
||||||
private static Method getClipDataFromIntent;
|
private static Method getClipDataFromIntent;
|
||||||
private static Method getDescription;
|
private static Method getDescription;
|
||||||
private static Method getItemCount;
|
private static Method getItemCount;
|
||||||
@@ -39,14 +36,14 @@ public class ClipDataCompat {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
clipData = Class.forName("android.content.ClipData");
|
Class clipData = Class.forName("android.content.ClipData");
|
||||||
getDescription = clipData.getMethod("getDescription", (Class[])null);
|
getDescription = clipData.getMethod("getDescription", (Class[])null);
|
||||||
getItemCount = clipData.getMethod("getItemCount", (Class[])null);
|
getItemCount = clipData.getMethod("getItemCount", (Class[])null);
|
||||||
getItemAt = clipData.getMethod("getItemAt", new Class[]{int.class});
|
getItemAt = clipData.getMethod("getItemAt", new Class[]{int.class});
|
||||||
clipDescription = Class.forName("android.content.ClipDescription");
|
Class clipDescription = Class.forName("android.content.ClipDescription");
|
||||||
getLabel = clipDescription.getMethod("getLabel", (Class[])null);
|
getLabel = clipDescription.getMethod("getLabel", (Class[])null);
|
||||||
|
|
||||||
clipDataItem = Class.forName("android.content.ClipData$Item");
|
Class clipDataItem = Class.forName("android.content.ClipData$Item");
|
||||||
getUri = clipDataItem.getMethod("getUri", (Class[])null);
|
getUri = clipDataItem.getMethod("getUri", (Class[])null);
|
||||||
|
|
||||||
getClipDataFromIntent = Intent.class.getMethod("getClipData", (Class[])null);
|
getClipDataFromIntent = Intent.class.getMethod("getClipData", (Class[])null);
|
||||||
@@ -58,7 +55,6 @@ public class ClipDataCompat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Uri getUriFromIntent(Intent i, String key) {
|
public static Uri getUriFromIntent(Intent i, String key) {
|
||||||
boolean clipDataSucceeded = false;
|
|
||||||
if (initSucceded) {
|
if (initSucceded) {
|
||||||
try {
|
try {
|
||||||
Object clip = getClipDataFromIntent.invoke(i);
|
Object clip = getClipDataFromIntent.invoke(i);
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.compat;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class ContentResolverCompat {
|
|
||||||
public static boolean available;
|
|
||||||
private static Class contentResolver;
|
|
||||||
private static Method takePersistableUriPermission;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
contentResolver = ContentResolver.class;
|
|
||||||
takePersistableUriPermission = contentResolver.getMethod("takePersistableUriPermission", new Class[]{Uri.class, int.class});
|
|
||||||
|
|
||||||
available = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
available = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void takePersistableUriPermission(ContentResolver resolver, Uri uri, int modeFlags) {
|
|
||||||
if (available) {
|
|
||||||
try {
|
|
||||||
takePersistableUriPermission.invoke(resolver, new Object[]{uri, modeFlags});
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Fail silently
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.compat;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class EditorCompat {
|
|
||||||
private static Method apply;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
apply = Activity.class.getMethod("apply", (Class<SharedPreferences.Editor>[]) null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Substitute commit for apply when not available (API level < 9)
|
|
||||||
try {
|
|
||||||
apply = Activity.class.getMethod("commit", (Class<SharedPreferences.Editor>[]) null);
|
|
||||||
} catch (Exception f) {
|
|
||||||
// Should be impossible, but leave apply null in this case
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void apply(SharedPreferences.Editor edit) {
|
|
||||||
try {
|
|
||||||
apply.invoke(edit, (Object[]) null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Shouldn't be possible, but call commit directly if this happens
|
|
||||||
edit.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -44,7 +44,6 @@ public final class PRNGFixes {
|
|||||||
|
|
||||||
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
||||||
getBuildFingerprintAndDeviceSerial();
|
getBuildFingerprintAndDeviceSerial();
|
||||||
private static int sdkVersion = BuildCompat.getSdkVersion();
|
|
||||||
|
|
||||||
/** Hidden constructor to prevent instantiation. */
|
/** Hidden constructor to prevent instantiation. */
|
||||||
private PRNGFixes() {}
|
private PRNGFixes() {}
|
||||||
@@ -67,11 +66,11 @@ public final class PRNGFixes {
|
|||||||
|
|
||||||
private static boolean supportedOnThisDevice() {
|
private static boolean supportedOnThisDevice() {
|
||||||
// Blacklist on samsung devices
|
// Blacklist on samsung devices
|
||||||
if (StrUtil.indexOfIgnoreCase(BuildCompat.getManufacturer(), "samsung", Locale.ENGLISH) >= 0) {
|
if (StrUtil.indexOfIgnoreCase(Build.MANUFACTURER, "samsung", Locale.ENGLISH) >= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,8 +125,8 @@ public final class PRNGFixes {
|
|||||||
* @throws SecurityException if the fix is needed but could not be applied.
|
* @throws SecurityException if the fix is needed but could not be applied.
|
||||||
*/
|
*/
|
||||||
private static void applyOpenSSLFix() throws SecurityException {
|
private static void applyOpenSSLFix() throws SecurityException {
|
||||||
if ((sdkVersion < BuildCompat.VERSION_CODE_JELLY_BEAN)
|
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|
||||||
|| (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2)) {
|
|| (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)) {
|
||||||
// No need to apply the fix
|
// No need to apply the fix
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -162,7 +161,7 @@ public final class PRNGFixes {
|
|||||||
*/
|
*/
|
||||||
private static void installLinuxPRNGSecureRandom()
|
private static void installLinuxPRNGSecureRandom()
|
||||||
throws SecurityException {
|
throws SecurityException {
|
||||||
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
// No need to apply the fix
|
// No need to apply the fix
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.compat;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
@@ -45,7 +46,7 @@ public class StorageAF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean supportsStorageFramework() { return BuildCompat.getSdkVersion() >= BuildCompat.VERSION_KITKAT; }
|
public static boolean supportsStorageFramework() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; }
|
||||||
|
|
||||||
public static boolean useStorageFramework(Context ctx) {
|
public static boolean useStorageFramework(Context ctx) {
|
||||||
if (!supportsStorageFramework()) { return false; }
|
if (!supportsStorageFramework()) { return false; }
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class AesKdf extends KdfEngine {
|
public class AesKdf extends KdfEngine {
|
||||||
|
|
||||||
public static final int DEFAULT_ROUNDS = 6000;
|
private static final int DEFAULT_ROUNDS = 6000;
|
||||||
public static final String DEFAULT_NAME = "AES-KDF";
|
private static final String DEFAULT_NAME = "AES-KDF";
|
||||||
|
|
||||||
public static final UUID CIPHER_UUID = Types.bytestoUUID(
|
public static final UUID CIPHER_UUID = Types.bytestoUUID(
|
||||||
new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60,
|
new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60,
|
||||||
@@ -44,8 +44,8 @@ public class AesKdf extends KdfEngine {
|
|||||||
public static final String ParamRounds = "R";
|
public static final String ParamRounds = "R";
|
||||||
public static final String ParamSeed = "S";
|
public static final String ParamSeed = "S";
|
||||||
|
|
||||||
public AesKdf() {
|
AesKdf() {
|
||||||
uuid = CIPHER_UUID;
|
setUUID(CIPHER_UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -35,16 +35,16 @@ public class Argon2Kdf extends KdfEngine {
|
|||||||
(byte) 0x91, (byte) 0xF7, (byte) 0xA9, (byte) 0xA4, (byte)0x03, (byte) 0xE3, (byte) 0x0A, (byte) 0x0C
|
(byte) 0x91, (byte) 0xF7, (byte) 0xA9, (byte) 0xA4, (byte)0x03, (byte) 0xE3, (byte) 0x0A, (byte) 0x0C
|
||||||
});
|
});
|
||||||
|
|
||||||
public static final String ParamSalt = "S"; // byte[]
|
private static final String ParamSalt = "S"; // byte[]
|
||||||
public static final String ParamParallelism = "P"; // UInt32
|
private static final String ParamParallelism = "P"; // UInt32
|
||||||
public static final String ParamMemory = "M"; // UInt64
|
private static final String ParamMemory = "M"; // UInt64
|
||||||
public static final String ParamIterations = "I"; // UInt64
|
private static final String ParamIterations = "I"; // UInt64
|
||||||
public static final String ParamVersion = "V"; // UInt32
|
private static final String ParamVersion = "V"; // UInt32
|
||||||
public static final String ParamSecretKey = "K"; // byte[]
|
private static final String ParamSecretKey = "K"; // byte[]
|
||||||
public static final String ParamAssocData = "A"; // byte[]
|
private static final String ParamAssocData = "A"; // byte[]
|
||||||
|
|
||||||
public static final long MinVersion = 0x10;
|
private static final long MinVersion = 0x10;
|
||||||
public static final long MaxVersion = 0x13;
|
private static final long MaxVersion = 0x13;
|
||||||
|
|
||||||
private static final int MinSalt = 8;
|
private static final int MinSalt = 8;
|
||||||
private static final int MaxSalt = Integer.MAX_VALUE;
|
private static final int MaxSalt = Integer.MAX_VALUE;
|
||||||
@@ -64,8 +64,8 @@ public class Argon2Kdf extends KdfEngine {
|
|||||||
|
|
||||||
private static final String DEFAULT_NAME = "Argon2";
|
private static final String DEFAULT_NAME = "Argon2";
|
||||||
|
|
||||||
public Argon2Kdf() {
|
Argon2Kdf() {
|
||||||
uuid = CIPHER_UUID;
|
setUUID(CIPHER_UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,7 +29,15 @@ public abstract class KdfEngine implements ObjectNameResource{
|
|||||||
public static final int UNKNOW_VALUE = -1;
|
public static final int UNKNOW_VALUE = -1;
|
||||||
public static final String UNKNOW_VALUE_STRING = String.valueOf(-1);
|
public static final String UNKNOW_VALUE_STRING = String.valueOf(-1);
|
||||||
|
|
||||||
public UUID uuid;
|
protected UUID uuid;
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUUID(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract KdfParameters getDefaultParameters();
|
public abstract KdfParameters getDefaultParameters();
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.crypto.keyDerivation;
|
package com.kunzisoft.keepass.crypto.keyDerivation;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -28,22 +30,26 @@ public class KdfFactory {
|
|||||||
public static Argon2Kdf argon2Kdf = new Argon2Kdf();
|
public static Argon2Kdf argon2Kdf = new Argon2Kdf();
|
||||||
|
|
||||||
public static List<KdfEngine> kdfListV3 = new ArrayList<>();
|
public static List<KdfEngine> kdfListV3 = new ArrayList<>();
|
||||||
public static List<KdfEngine> kdfList = new ArrayList<>();
|
public static List<KdfEngine> kdfListV4 = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
kdfListV3.add(aesKdf);
|
kdfListV3.add(aesKdf);
|
||||||
|
|
||||||
kdfList.add(aesKdf);
|
kdfListV4.add(aesKdf);
|
||||||
kdfList.add(argon2Kdf);
|
kdfListV4.add(argon2Kdf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KdfEngine get(KdfParameters kdfParameters) {
|
public static KdfEngine getEngineV4(KdfParameters kdfParameters) throws UnknownKDF {
|
||||||
for (KdfEngine engine: kdfList) {
|
UnknownKDF unknownKDFException = new UnknownKDF();
|
||||||
if (engine.uuid.equals(kdfParameters.kdfUUID)) {
|
if (kdfParameters == null) {
|
||||||
|
throw unknownKDFException;
|
||||||
|
}
|
||||||
|
for (KdfEngine engine: kdfListV4) {
|
||||||
|
if (engine.getUUID().equals(kdfParameters.getUUID())) {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw unknownKDFException;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class KdfParameters extends VariantDictionary {
|
public class KdfParameters extends VariantDictionary {
|
||||||
|
|
||||||
public UUID kdfUUID;
|
private UUID kdfUUID;
|
||||||
|
|
||||||
private static final String ParamUUID = "$UUID";
|
private static final String ParamUUID = "$UUID";
|
||||||
|
|
||||||
@@ -39,6 +39,10 @@ public class KdfParameters extends VariantDictionary {
|
|||||||
kdfUUID = uuid;
|
kdfUUID = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return kdfUUID;
|
||||||
|
}
|
||||||
|
|
||||||
protected void setParamUUID() {
|
protected void setParamUUID() {
|
||||||
setByteArray(ParamUUID, Types.UUIDtoBytes(kdfUUID));
|
setByteArray(ParamUUID, Types.UUIDtoBytes(kdfUUID));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,14 @@
|
|||||||
package com.kunzisoft.keepass.database;
|
package com.kunzisoft.keepass.database;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
||||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
|
|
||||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||||
import com.kunzisoft.keepass.database.load.Importer;
|
import com.kunzisoft.keepass.database.load.Importer;
|
||||||
import com.kunzisoft.keepass.database.load.ImporterFactory;
|
import com.kunzisoft.keepass.database.load.ImporterFactory;
|
||||||
@@ -51,6 +47,9 @@ import java.io.OutputStream;
|
|||||||
import java.io.SyncFailedException;
|
import java.io.SyncFailedException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
@@ -107,7 +106,7 @@ public class Database {
|
|||||||
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
|
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
private void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
readOnly = false;
|
readOnly = false;
|
||||||
if (uri.getScheme().equals("file")) {
|
if (uri.getScheme().equals("file")) {
|
||||||
@@ -115,26 +114,10 @@ public class Database {
|
|||||||
readOnly = !file.canWrite();
|
readOnly = !file.canWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug);
|
||||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, 0);
|
|
||||||
} catch (InvalidPasswordException e) {
|
|
||||||
// Retry with rounds fix
|
|
||||||
try {
|
|
||||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, getFixRounds(ctx));
|
|
||||||
} catch (Exception e2) {
|
|
||||||
// Rethrow original exception
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getFixRounds(Context ctx) {
|
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
|
||||||
return prefs.getLong(ctx.getString(R.string.roundsFix_key), ctx.getResources().getInteger(R.integer.roundsFix_default));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
|
|
||||||
InputStream is, kfIs;
|
InputStream is, kfIs;
|
||||||
try {
|
try {
|
||||||
is = UriUtil.getUriInputStream(ctx, uri);
|
is = UriUtil.getUriInputStream(ctx, uri);
|
||||||
@@ -149,14 +132,14 @@ public class Database {
|
|||||||
Log.e("KPD", "Database::loadData", e);
|
Log.e("KPD", "Database::loadData", e);
|
||||||
throw ContentFileNotFoundException.getInstance(keyfile);
|
throw ContentFileNotFoundException.getInstance(keyfile);
|
||||||
}
|
}
|
||||||
loadData(ctx, is, password, kfIs, status, debug, roundsFix);
|
loadData(ctx, is, password, kfIs, status, debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
|
public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
|
||||||
loadData(ctx, is, password, keyFileInputStream, null, debug, 0);
|
loadData(ctx, is, password, keyFileInputStream, null, debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
|
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug) throws IOException, InvalidDBException {
|
||||||
BufferedInputStream bis = new BufferedInputStream(is);
|
BufferedInputStream bis = new BufferedInputStream(is);
|
||||||
|
|
||||||
if ( ! bis.markSupported() ) {
|
if ( ! bis.markSupported() ) {
|
||||||
@@ -170,7 +153,7 @@ public class Database {
|
|||||||
|
|
||||||
bis.reset(); // Return to the start
|
bis.reset(); // Return to the start
|
||||||
|
|
||||||
pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater, roundsFix);
|
pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater);
|
||||||
if ( pm != null ) {
|
if ( pm != null ) {
|
||||||
try {
|
try {
|
||||||
switch (pm.getVersion()) {
|
switch (pm.getVersion()) {
|
||||||
@@ -266,6 +249,7 @@ public class Database {
|
|||||||
mUri = uri;
|
mUri = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Clear database when lock broadcast is receive in backstage
|
||||||
public void clear() {
|
public void clear() {
|
||||||
drawFactory.clearCache();
|
drawFactory.clearCache();
|
||||||
|
|
||||||
@@ -384,7 +368,7 @@ public class Database {
|
|||||||
public List<KdfEngine> getAvailableKdfEngines() {
|
public List<KdfEngine> getAvailableKdfEngines() {
|
||||||
switch (getPwDatabase().getVersion()) {
|
switch (getPwDatabase().getVersion()) {
|
||||||
case V4:
|
case V4:
|
||||||
return KdfFactory.kdfList;
|
return KdfFactory.kdfListV4;
|
||||||
case V3:
|
case V3:
|
||||||
return KdfFactory.kdfListV3;
|
return KdfFactory.kdfListV3;
|
||||||
}
|
}
|
||||||
@@ -396,10 +380,16 @@ public class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public KdfEngine getKdfEngine() {
|
public KdfEngine getKdfEngine() {
|
||||||
KdfEngine kdfEngine = getPwDatabase().getKdfEngine();
|
switch (getPwDatabase().getVersion()) {
|
||||||
if (kdfEngine == null)
|
case V4:
|
||||||
return KdfFactory.aesKdf;
|
KdfEngine kdfEngine = ((PwDatabaseV4) getPwDatabase()).getKdfEngine();
|
||||||
return kdfEngine;
|
if (kdfEngine == null)
|
||||||
|
return KdfFactory.aesKdf;
|
||||||
|
return kdfEngine;
|
||||||
|
default:
|
||||||
|
case V3:
|
||||||
|
return KdfFactory.aesKdf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assignKdfEngine(KdfEngine kdfEngine) {
|
public void assignKdfEngine(KdfEngine kdfEngine) {
|
||||||
@@ -407,7 +397,7 @@ public class Database {
|
|||||||
case V4:
|
case V4:
|
||||||
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
|
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
|
||||||
if (db.getKdfParameters() == null
|
if (db.getKdfParameters() == null
|
||||||
|| !db.getKdfParameters().kdfUUID.equals(kdfEngine.getDefaultParameters().kdfUUID))
|
|| !db.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID()))
|
||||||
db.setKdfParameters(kdfEngine.getDefaultParameters());
|
db.setKdfParameters(kdfEngine.getDefaultParameters());
|
||||||
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
|
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
|
||||||
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
|
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
|
||||||
@@ -417,7 +407,7 @@ public class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyDerivationName(Resources resources) {
|
public String getKeyDerivationName(Resources resources) {
|
||||||
KdfEngine kdfEngine = getPwDatabase().getKdfEngine();
|
KdfEngine kdfEngine = getKdfEngine();
|
||||||
if (kdfEngine != null) {
|
if (kdfEngine != null) {
|
||||||
return kdfEngine.getName(resources);
|
return kdfEngine.getName(resources);
|
||||||
}
|
}
|
||||||
@@ -653,6 +643,44 @@ public class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A duplicate entry with the same values, a new UUID,
|
||||||
|
* @param entryToCopy
|
||||||
|
* @param newParent
|
||||||
|
*/
|
||||||
|
public @Nullable PwEntry copyEntry(PwEntry entryToCopy, PwGroup newParent) {
|
||||||
|
try {
|
||||||
|
// TODO encapsulate
|
||||||
|
switch (getPwDatabase().getVersion()) {
|
||||||
|
case V3:
|
||||||
|
PwEntryV3 entryV3Copied = ((PwEntryV3) entryToCopy).clone();
|
||||||
|
entryV3Copied.setUUID(UUID.randomUUID());
|
||||||
|
entryV3Copied.setParent((PwGroupV3) newParent);
|
||||||
|
addEntryTo(entryV3Copied, newParent);
|
||||||
|
return entryV3Copied;
|
||||||
|
case V4:
|
||||||
|
PwEntryV4 entryV4Copied = ((PwEntryV4) entryToCopy).clone();
|
||||||
|
entryV4Copied.setUUID(UUID.randomUUID());
|
||||||
|
entryV4Copied.setParent((PwGroupV4) newParent);
|
||||||
|
addEntryTo(entryV4Copied, newParent);
|
||||||
|
return entryV4Copied;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "This version of PwEntry can't be updated", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveEntry(PwEntry entryToMove, PwGroup newParent) {
|
||||||
|
removeEntryFrom(entryToMove, entryToMove.parent);
|
||||||
|
addEntryTo(entryToMove, newParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveGroup(PwGroup groupToMove, PwGroup newParent) {
|
||||||
|
removeGroupFrom(groupToMove, groupToMove.parent);
|
||||||
|
addGroupTo(groupToMove, newParent);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteEntry(PwEntry entry) {
|
public void deleteEntry(PwEntry entry) {
|
||||||
try {
|
try {
|
||||||
switch (getPwDatabase().getVersion()) {
|
switch (getPwDatabase().getVersion()) {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class EntrySearchV4 {
|
|||||||
|
|
||||||
boolean negate = false;
|
boolean negate = false;
|
||||||
if (sp.searchString.startsWith("-")) {
|
if (sp.searchString.startsWith("-")) {
|
||||||
sp.searchString.substring(1); // TODO Verify bug or no need ?
|
sp.searchString = sp.searchString.substring(1);
|
||||||
negate = sp.searchString.length() > 0;
|
negate = sp.searchString.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,22 @@ public class ExtraFields implements Serializable, Cloneable {
|
|||||||
return !getCustomProtectedFields().keySet().isEmpty();
|
return !getCustomProtectedFields().keySet().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsCustomFieldsProtected() {
|
||||||
|
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
|
||||||
|
if (field.getValue().isProtected())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsCustomFieldsNotProtected() {
|
||||||
|
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
|
||||||
|
if (!field.getValue().isProtected())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getProtectedStringValue(String key) {
|
public String getProtectedStringValue(String key) {
|
||||||
ProtectedString value = fields.get(key);
|
ProtectedString value = fields.get(key);
|
||||||
if ( value == null ) return "";
|
if ( value == null ) return "";
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database;
|
package com.kunzisoft.keepass.database;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||||
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
|
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
|
||||||
import com.kunzisoft.keepass.utils.Util;
|
import com.kunzisoft.keepass.utils.Util;
|
||||||
@@ -249,8 +248,6 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
|
|||||||
|
|
||||||
public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
|
public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
|
||||||
|
|
||||||
public abstract KdfEngine getKdfEngine();
|
|
||||||
|
|
||||||
public abstract List<PwGroupDB> getGrpRoots();
|
public abstract List<PwGroupDB> getGrpRoots();
|
||||||
|
|
||||||
public abstract List<PwGroupDB> getGroups();
|
public abstract List<PwGroupDB> getGroups();
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ package com.kunzisoft.keepass.database;
|
|||||||
|
|
||||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
|
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
|
||||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
|
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||||
import com.kunzisoft.keepass.stream.NullOutputStream;
|
import com.kunzisoft.keepass.stream.NullOutputStream;
|
||||||
|
|
||||||
@@ -102,11 +100,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
|||||||
return PwVersion.V3;
|
return PwVersion.V3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public KdfEngine getKdfEngine() {
|
|
||||||
return KdfFactory.aesKdf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
||||||
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
||||||
|
|||||||
@@ -19,17 +19,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database;
|
package com.kunzisoft.keepass.database;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.collections.VariantDictionary;
|
import com.kunzisoft.keepass.collections.VariantDictionary;
|
||||||
import com.kunzisoft.keepass.crypto.CryptoUtil;
|
import com.kunzisoft.keepass.crypto.CryptoUtil;
|
||||||
import com.kunzisoft.keepass.crypto.engine.AesEngine;
|
import com.kunzisoft.keepass.crypto.engine.AesEngine;
|
||||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
|
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
||||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
|
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||||
|
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||||
import com.kunzisoft.keepass.utils.EmptyUtils;
|
import com.kunzisoft.keepass.utils.EmptyUtils;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -50,6 +51,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
@@ -57,6 +59,7 @@ import biz.source_code.base64Coder.Base64Coder;
|
|||||||
|
|
||||||
|
|
||||||
public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||||
|
private static final String TAG = PwDatabaseV4.class.getName();
|
||||||
|
|
||||||
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
|
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
|
||||||
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
||||||
@@ -149,10 +152,14 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
this.compressionAlgorithm = compressionAlgorithm;
|
this.compressionAlgorithm = compressionAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public @Nullable KdfEngine getKdfEngine() {
|
||||||
public KdfEngine getKdfEngine() {
|
try {
|
||||||
return KdfFactory.get(getKdfParameters());
|
return KdfFactory.getEngineV4(kdfParameters);
|
||||||
}
|
} catch (UnknownKDF unknownKDF) {
|
||||||
|
Log.i(TAG, "Unable to retrieve KDF engine", unknownKDF);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public KdfParameters getKdfParameters() {
|
public KdfParameters getKdfParameters() {
|
||||||
return kdfParameters;
|
return kdfParameters;
|
||||||
@@ -395,22 +402,8 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void makeFinalKey(byte[] masterSeed) throws IOException {
|
public void makeFinalKey(byte[] masterSeed) throws IOException {
|
||||||
makeFinalKey(masterSeed, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void makeFinalKey(byte[] masterSeed, long roundsFix)
|
KdfEngine kdfEngine = KdfFactory.getEngineV4(kdfParameters);
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
KdfEngine kdfEngine = KdfFactory.get(kdfParameters);
|
|
||||||
if (kdfEngine == null) {
|
|
||||||
throw new IOException("Unknown key derivation function");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set to 6000 rounds to open corrupted database
|
|
||||||
if (roundsFix > 0 && kdfParameters.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
|
|
||||||
kdfParameters.setUInt32(AesKdf.ParamRounds, roundsFix);
|
|
||||||
numKeyEncRounds = roundsFix;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
|
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
|
||||||
if (transformedMasterKey.length != 32) {
|
if (transformedMasterKey.length != 32) {
|
||||||
@@ -562,15 +555,15 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
super.populateGlobals(currentGroup);
|
super.populateGlobals(currentGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ensure that the recycle bin tree exists, if enabled and create it
|
/**
|
||||||
* if it doesn't exist
|
* Ensure that the recycle bin tree exists, if enabled and create it
|
||||||
*
|
* if it doesn't exist
|
||||||
*/
|
*/
|
||||||
private void ensureRecycleBin() {
|
private void ensureRecycleBin() {
|
||||||
if (getRecycleBin() == null) {
|
if (getRecycleBin() == null) {
|
||||||
// Create recycle bin
|
// Create recycle bin
|
||||||
|
|
||||||
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getIcon(PwIconStandard.TRASH_BIN));
|
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getTrashIcon());
|
||||||
recycleBin.setEnableAutoType(false);
|
recycleBin.setEnableAutoType(false);
|
||||||
recycleBin.setEnableSearching(false);
|
recycleBin.setEnableSearching(false);
|
||||||
recycleBin.setExpanded(false);
|
recycleBin.setExpanded(false);
|
||||||
@@ -694,8 +687,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
@Override
|
@Override
|
||||||
public void undoDeleteEntry(PwEntryV4 entry, PwGroupV4 origParent) {
|
public void undoDeleteEntry(PwEntryV4 entry, PwGroupV4 origParent) {
|
||||||
super.undoDeleteEntry(entry, origParent);
|
super.undoDeleteEntry(entry, origParent);
|
||||||
// TODO undo delete entry
|
deletedObjects.remove(new PwDeletedObject(entry.getUUID()));
|
||||||
deletedObjects.remove(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -744,7 +736,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initNew(String dbPath) {
|
public void initNew(String dbPath) {
|
||||||
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
|
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getFolderIcon());
|
||||||
groups.put(rootGroup.getId(), rootGroup);
|
groups.put(rootGroup.getId(), rootGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
private static final int FILE_VERSION_CRITICAL_MASK = 0xFFFF0000;
|
private static final int FILE_VERSION_CRITICAL_MASK = 0xFFFF0000;
|
||||||
public static final int FILE_VERSION_32_3 = 0x00030001;
|
public static final int FILE_VERSION_32_3 = 0x00030001;
|
||||||
public static final int FILE_VERSION_32_4 = 0x00040000;
|
public static final int FILE_VERSION_32_4 = 0x00040000;
|
||||||
public static final int FILE_VERSION_32 = FILE_VERSION_32_4;
|
|
||||||
|
|
||||||
public class PwDbHeaderV4Fields {
|
public class PwDbHeaderV4Fields {
|
||||||
public static final byte EndOfHeader = 0;
|
public static final byte EndOfHeader = 0;
|
||||||
@@ -146,13 +145,13 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
private int getMinKdbxVersion(PwDatabaseV4 databaseV4) {
|
private int getMinKdbxVersion(PwDatabaseV4 databaseV4) {
|
||||||
// Return v4 if AES is not use
|
// Return v4 if AES is not use
|
||||||
if (databaseV4.getKdfParameters() != null
|
if (databaseV4.getKdfParameters() != null
|
||||||
&& !databaseV4.getKdfParameters().kdfUUID.equals(AesKdf.CIPHER_UUID)) {
|
&& !databaseV4.getKdfParameters().getUUID().equals(AesKdf.CIPHER_UUID)) {
|
||||||
return PwDbHeaderV4.FILE_VERSION_32;
|
return PwDbHeaderV4.FILE_VERSION_32_4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return V4 if custom data are present
|
// Return V4 if custom data are present
|
||||||
if (databaseV4.containsPublicCustomData()) {
|
if (databaseV4.containsPublicCustomData()) {
|
||||||
return PwDbHeaderV4.FILE_VERSION_32;
|
return PwDbHeaderV4.FILE_VERSION_32_4;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntryHasCustomData entryHandler = new EntryHasCustomData();
|
EntryHasCustomData entryHandler = new EntryHasCustomData();
|
||||||
@@ -163,7 +162,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
}
|
}
|
||||||
databaseV4.getRootGroup().preOrderTraverseTree(groupHandler, entryHandler);
|
databaseV4.getRootGroup().preOrderTraverseTree(groupHandler, entryHandler);
|
||||||
if (groupHandler.hasCustomData || entryHandler.hasCustomData) {
|
if (groupHandler.hasCustomData || entryHandler.hasCustomData) {
|
||||||
return PwDbHeaderV4.FILE_VERSION_32;
|
return PwDbHeaderV4.FILE_VERSION_32_4;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PwDbHeaderV4.FILE_VERSION_32_3;
|
return PwDbHeaderV4.FILE_VERSION_32_3;
|
||||||
@@ -210,7 +209,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
|
|
||||||
private boolean readHeaderField(LEDataInputStream dis) throws IOException {
|
private boolean readHeaderField(LEDataInputStream dis) throws IOException {
|
||||||
byte fieldID = (byte) dis.read();
|
byte fieldID = (byte) dis.read();
|
||||||
|
|
||||||
int fieldSize;
|
int fieldSize;
|
||||||
if (version < FILE_VERSION_32_4) {
|
if (version < FILE_VERSION_32_4) {
|
||||||
fieldSize = dis.readUShort();
|
fieldSize = dis.readUShort();
|
||||||
@@ -221,7 +220,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
byte[] fieldData = null;
|
byte[] fieldData = null;
|
||||||
if ( fieldSize > 0 ) {
|
if ( fieldSize > 0 ) {
|
||||||
fieldData = new byte[fieldSize];
|
fieldData = new byte[fieldSize];
|
||||||
|
|
||||||
int readSize = dis.read(fieldData);
|
int readSize = dis.read(fieldData);
|
||||||
if ( readSize != fieldSize ) {
|
if ( readSize != fieldSize ) {
|
||||||
throw new IOException("Header ended early.");
|
throw new IOException("Header ended early.");
|
||||||
@@ -287,7 +286,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assignAesKdfEngineIfNotExists() {
|
private void assignAesKdfEngineIfNotExists() {
|
||||||
if (db.getKdfParameters() == null || !db.getKdfParameters().kdfUUID.equals(KdfFactory.aesKdf.uuid)) {
|
if (db.getKdfParameters() == null || !db.getKdfParameters().getUUID().equals(KdfFactory.aesKdf.getUUID())) {
|
||||||
db.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
db.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -346,11 +345,11 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
|||||||
* @return true if it's a supported version
|
* @return true if it's a supported version
|
||||||
*/
|
*/
|
||||||
private boolean validVersion(long version) {
|
private boolean validVersion(long version) {
|
||||||
return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32 & FILE_VERSION_CRITICAL_MASK));
|
return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32_4 & FILE_VERSION_CRITICAL_MASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean matchesHeader(int sig1, int sig2) {
|
public static boolean matchesHeader(int sig1, int sig2) {
|
||||||
return (sig1 == PWM_DBSIG_1) && ( (sig2 == DBSIG_PRE2) || (sig2 == DBSIG_2) ); // TODO verify add DBSIG_PRE2
|
return (sig1 == PWM_DBSIG_1) && ( (sig2 == DBSIG_PRE2) || (sig2 == DBSIG_2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] computeHeaderHmac(byte[] header, byte[] key) throws IOException{
|
public static byte[] computeHeaderHmac(byte[] header, byte[] key) throws IOException{
|
||||||
|
|||||||
@@ -117,6 +117,22 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
|
|||||||
return getFields().containsCustomFields();
|
return getFields().containsCustomFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If entry contains extra fields that are protected
|
||||||
|
* @return true if there is extra fields protected
|
||||||
|
*/
|
||||||
|
public boolean containsCustomFieldsProtected() {
|
||||||
|
return getFields().containsCustomFieldsProtected();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If entry contains extra fields that are not protected
|
||||||
|
* @return true if there is extra fields not protected
|
||||||
|
*/
|
||||||
|
public boolean containsCustomFieldsNotProtected() {
|
||||||
|
return getFields().containsCustomFieldsNotProtected();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an extra field to the list (standard or custom)
|
* Add an extra field to the list (standard or custom)
|
||||||
* @param label Label of field, must be unique
|
* @param label Label of field, must be unique
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
|
|||||||
public void populateBlankFields(PwDatabaseV3 db) {
|
public void populateBlankFields(PwDatabaseV3 db) {
|
||||||
// TODO verify and remove
|
// TODO verify and remove
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
icon = db.getIconFactory().getFirstIcon();
|
icon = db.getIconFactory().getKeyIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
|
|||||||
public void populateBlankFields(PwDatabaseV3 db) {
|
public void populateBlankFields(PwDatabaseV3 db) {
|
||||||
// TODO populate blanck field
|
// TODO populate blanck field
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
icon = db.getIconFactory().getFirstIcon();
|
icon = db.getIconFactory().getFolderIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
|
|||||||
@@ -37,20 +37,23 @@ public class PwIconFactory {
|
|||||||
*/
|
*/
|
||||||
private ReferenceMap customCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
|
private ReferenceMap customCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
|
||||||
|
|
||||||
public PwIconStandard getFirstIcon() {
|
public PwIconStandard getKeyIcon() {
|
||||||
return getIcon(0);
|
return getIcon(PwIconStandard.KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PwIconStandard getTrashIcon() {
|
||||||
|
return getIcon(PwIconStandard.TRASH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PwIconStandard getFolderIcon() {
|
||||||
|
return getIcon(PwIconStandard.FOLDER);
|
||||||
|
}
|
||||||
|
|
||||||
public PwIconStandard getIcon(int iconId) {
|
public PwIconStandard getIcon(int iconId) {
|
||||||
PwIconStandard icon = (PwIconStandard) cache.get(iconId);
|
PwIconStandard icon = (PwIconStandard) cache.get(iconId);
|
||||||
|
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
if (iconId == 1) {
|
icon = new PwIconStandard(iconId);
|
||||||
icon = PwIconStandard.FIRST;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
icon = new PwIconStandard(iconId);
|
|
||||||
}
|
|
||||||
cache.put(iconId, icon);
|
cache.put(iconId, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ package com.kunzisoft.keepass.database;
|
|||||||
public class PwIconStandard extends PwIcon {
|
public class PwIconStandard extends PwIcon {
|
||||||
public final int iconId;
|
public final int iconId;
|
||||||
|
|
||||||
// The first is number 0
|
public static final int KEY = 0;
|
||||||
public static PwIconStandard FIRST = new PwIconStandard(0);
|
public static final int TRASH = 43;
|
||||||
|
|
||||||
public static final int TRASH_BIN = 43;
|
|
||||||
public static final int FOLDER = 48;
|
public static final int FOLDER = 48;
|
||||||
|
|
||||||
public PwIconStandard(int iconId) {
|
public PwIconStandard(int iconId) {
|
||||||
this.iconId = iconId;
|
this.iconId = iconId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
|
|||||||
|
|
||||||
protected Parent parent = null;
|
protected Parent parent = null;
|
||||||
|
|
||||||
protected PwIconStandard icon = PwIconStandard.FIRST;
|
protected PwIconStandard icon = new PwIconStandard(0);
|
||||||
|
|
||||||
protected PwDate creation = new PwDate();
|
protected PwDate creation = new PwDate();
|
||||||
protected PwDate lastMod = new PwDate();
|
protected PwDate lastMod = new PwDate();
|
||||||
@@ -119,6 +119,13 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
|
|||||||
parent = prt;
|
parent = prt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if parent is present (can be a root or a detach element)
|
||||||
|
*/
|
||||||
|
public boolean containsParent() {
|
||||||
|
return getParent() != null;
|
||||||
|
}
|
||||||
|
|
||||||
public PwDate getCreationTime() {
|
public PwDate getCreationTime() {
|
||||||
return creation;
|
return creation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.kunzisoft.keepass.database.action;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
|
||||||
|
public abstract class ActionWithSaveDatabaseRunnable extends RunnableOnFinish {
|
||||||
|
|
||||||
|
protected Context mContext;
|
||||||
|
protected boolean mDontSave;
|
||||||
|
protected Database mDatabase;
|
||||||
|
|
||||||
|
public ActionWithSaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||||
|
super(finish);
|
||||||
|
|
||||||
|
this.mDatabase = database;
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDontSave = dontSave;
|
||||||
|
this.mFinish = new AfterActionRunnable(finish);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Commit to disk
|
||||||
|
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, mDatabase, mFinish, mDontSave);
|
||||||
|
save.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runWithoutSaveDatabase() {
|
||||||
|
mFinish.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected void onFinish(boolean success, String message);
|
||||||
|
|
||||||
|
private class AfterActionRunnable extends OnFinishRunnable {
|
||||||
|
|
||||||
|
AfterActionRunnable(OnFinishRunnable finish) {
|
||||||
|
super(finish);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
onFinish(mSuccess, mMessage);
|
||||||
|
super.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.action;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
|
||||||
import com.kunzisoft.keepass.database.PwDatabase;
|
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class AssignPasswordInDBRunnable extends RunnableOnFinish {
|
|
||||||
|
|
||||||
private String mPassword;
|
|
||||||
private Uri mKeyfile;
|
|
||||||
private Database mDb;
|
|
||||||
private boolean mDontSave;
|
|
||||||
private Context ctx;
|
|
||||||
|
|
||||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
|
||||||
this(ctx, db, password, keyfile, finish, false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
|
||||||
super(finish);
|
|
||||||
|
|
||||||
mDb = db;
|
|
||||||
mPassword = password;
|
|
||||||
mKeyfile = keyfile;
|
|
||||||
mDontSave = dontSave;
|
|
||||||
this.ctx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PwDatabase pm = mDb.getPwDatabase();
|
|
||||||
|
|
||||||
byte[] backupKey = new byte[pm.getMasterKey().length];
|
|
||||||
System.arraycopy(pm.getMasterKey(), 0, backupKey, 0, backupKey.length);
|
|
||||||
|
|
||||||
// Set key
|
|
||||||
try {
|
|
||||||
InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile);
|
|
||||||
pm.retrieveMasterKey(mPassword, is);
|
|
||||||
} catch (InvalidKeyFileException e) {
|
|
||||||
erase(backupKey);
|
|
||||||
finish(false, e.getMessage());
|
|
||||||
return;
|
|
||||||
} catch (IOException e) {
|
|
||||||
erase(backupKey);
|
|
||||||
finish(false, e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save Database
|
|
||||||
mFinish = new AfterSave(backupKey, mFinish);
|
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
|
|
||||||
save.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AfterSave extends OnFinishRunnable {
|
|
||||||
private byte[] mBackup;
|
|
||||||
|
|
||||||
public AfterSave(byte[] backup, OnFinishRunnable finish) {
|
|
||||||
super(finish);
|
|
||||||
|
|
||||||
mBackup = backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if ( ! mSuccess ) {
|
|
||||||
// Erase the current master key
|
|
||||||
erase(mDb.getPwDatabase().getMasterKey());
|
|
||||||
mDb.getPwDatabase().setMasterKey(mBackup);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
private void erase(byte[] array) {
|
|
||||||
if ( array == null ) return;
|
|
||||||
|
|
||||||
for ( int i = 0; i < array.length; i++ ) {
|
|
||||||
array[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwDatabase;
|
||||||
|
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||||
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class AssignPasswordInDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||||
|
|
||||||
|
private String mPassword;
|
||||||
|
private Uri mKeyfile;
|
||||||
|
private byte[] mBackupKey;
|
||||||
|
|
||||||
|
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||||
|
this(ctx, db, password, keyfile, finish, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||||
|
super(ctx, db, finish, dontSave);
|
||||||
|
|
||||||
|
this.mPassword = password;
|
||||||
|
this.mKeyfile = keyfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PwDatabase pm = mDatabase.getPwDatabase();
|
||||||
|
|
||||||
|
mBackupKey = new byte[pm.getMasterKey().length];
|
||||||
|
System.arraycopy(pm.getMasterKey(), 0, mBackupKey, 0, mBackupKey.length);
|
||||||
|
|
||||||
|
// Set key
|
||||||
|
try {
|
||||||
|
InputStream is = UriUtil.getUriInputStream(mContext, mKeyfile);
|
||||||
|
pm.retrieveMasterKey(mPassword, is);
|
||||||
|
// Save Database
|
||||||
|
super.run();
|
||||||
|
} catch (InvalidKeyFileException|IOException e) {
|
||||||
|
erase(mBackupKey);
|
||||||
|
finish(false, e.getMessage());
|
||||||
|
super.runWithoutSaveDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if (!success) {
|
||||||
|
// Erase the current master key
|
||||||
|
erase(mDatabase.getPwDatabase().getMasterKey());
|
||||||
|
mDatabase.getPwDatabase().setMasterKey(mBackupKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
||||||
|
*/
|
||||||
|
private void erase(byte[] array) {
|
||||||
|
if ( array == null ) return;
|
||||||
|
|
||||||
|
for ( int i = 0; i < array.length; i++ ) {
|
||||||
|
array[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,18 +26,18 @@ import com.kunzisoft.keepass.database.Database;
|
|||||||
import com.kunzisoft.keepass.database.PwDatabase;
|
import com.kunzisoft.keepass.database.PwDatabase;
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
|
|
||||||
public class CreateDBRunnable extends RunnableOnFinish {
|
public class CreateDatabaseRunnable extends RunnableOnFinish {
|
||||||
|
|
||||||
private String mFilename;
|
|
||||||
private boolean mDontSave;
|
|
||||||
private Context ctx;
|
|
||||||
|
|
||||||
public CreateDBRunnable(Context ctx, String filename, OnFinishRunnable finish, boolean dontSave) {
|
private Context mContext;
|
||||||
|
private boolean mDontSave;
|
||||||
|
private String mFilename;
|
||||||
|
|
||||||
|
public CreateDatabaseRunnable(Context mContext, String filename, OnFinishRunnable finish, boolean dontSave) {
|
||||||
super(finish);
|
super(finish);
|
||||||
|
|
||||||
mFilename = filename;
|
this.mContext = mContext;
|
||||||
mDontSave = dontSave;
|
this.mDontSave = dontSave;
|
||||||
this.ctx = ctx;
|
this.mFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,8 +56,9 @@ public class CreateDBRunnable extends RunnableOnFinish {
|
|||||||
App.clearShutdown();
|
App.clearShutdown();
|
||||||
|
|
||||||
// Commit changes
|
// Commit changes
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, db, mFinish, mDontSave);
|
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, db, mFinish, mDontSave);
|
||||||
mFinish = null;
|
mFinish = null;
|
||||||
|
|
||||||
save.run();
|
save.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.action;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
|
||||||
|
|
||||||
/** Task to delete entries
|
|
||||||
* @author bpellin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class DeleteEntryRunnable extends RunnableOnFinish {
|
|
||||||
|
|
||||||
private Database mDb;
|
|
||||||
private PwEntry mEntry;
|
|
||||||
private boolean mDontSave;
|
|
||||||
private Context ctx;
|
|
||||||
|
|
||||||
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) {
|
|
||||||
this(ctx, db, entry, finish, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) {
|
|
||||||
super(finish);
|
|
||||||
|
|
||||||
this.mDb = db;
|
|
||||||
this.mEntry = entry;
|
|
||||||
this.mDontSave = dontSave;
|
|
||||||
this.ctx = ctx;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PwGroup parent = mEntry.getParent();
|
|
||||||
|
|
||||||
// Remove Entry from parent
|
|
||||||
boolean recycle = mDb.canRecycle(mEntry);
|
|
||||||
if (recycle) {
|
|
||||||
mDb.recycle(mEntry);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mDb.deleteEntry(mEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save
|
|
||||||
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
|
|
||||||
|
|
||||||
// Commit database
|
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
|
|
||||||
save.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AfterDelete extends OnFinishRunnable {
|
|
||||||
|
|
||||||
private PwGroup mParent;
|
|
||||||
private PwEntry mEntry;
|
|
||||||
private boolean recycled;
|
|
||||||
|
|
||||||
AfterDelete(OnFinishRunnable finish, PwGroup parent, PwEntry entry, boolean r) {
|
|
||||||
super(finish);
|
|
||||||
|
|
||||||
mParent = parent;
|
|
||||||
mEntry = entry;
|
|
||||||
recycled = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if ( !mSuccess ) {
|
|
||||||
if (recycled) {
|
|
||||||
mDb.undoRecycle(mEntry, mParent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mDb.undoDeleteEntry(mEntry, mParent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO Callback after delete entry
|
|
||||||
|
|
||||||
super.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.action;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.app.App;
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DeleteGroupRunnable extends RunnableOnFinish {
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private Database mDb;
|
|
||||||
private PwGroup<PwGroup, PwGroup, PwEntry> mGroup;
|
|
||||||
private boolean mDontSave;
|
|
||||||
|
|
||||||
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinishRunnable finish) {
|
|
||||||
super(finish);
|
|
||||||
setMembers(ctx, db, group, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinishRunnable finish, boolean dontSave) {
|
|
||||||
super(finish);
|
|
||||||
setMembers(ctx, db, group, dontSave);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMembers(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, boolean dontSave) {
|
|
||||||
mDb = db;
|
|
||||||
mGroup = group;
|
|
||||||
mContext = ctx;
|
|
||||||
mDontSave = dontSave;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PwGroup parent = mGroup.getParent();
|
|
||||||
|
|
||||||
// Remove Group from parent
|
|
||||||
boolean recycle = mDb.canRecycle(mGroup);
|
|
||||||
if (recycle) {
|
|
||||||
mDb.recycle(mGroup);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// TODO tests
|
|
||||||
// Remove child entries
|
|
||||||
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods
|
|
||||||
for ( int i = 0; i < childEnt.size(); i++ ) {
|
|
||||||
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDb, childEnt.get(i), null, true);
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove child groups
|
|
||||||
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
|
|
||||||
for ( int i = 0; i < childGrp.size(); i++ ) {
|
|
||||||
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDb, childGrp.get(i), null, true);
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
mDb.deleteGroup(mGroup);
|
|
||||||
|
|
||||||
// Remove from PwDatabaseV3
|
|
||||||
// TODO ENcapsulate
|
|
||||||
mDb.getPwDatabase().getGroups().remove(mGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save
|
|
||||||
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
|
|
||||||
|
|
||||||
// Commit Database
|
|
||||||
SaveDBRunnable save = new SaveDBRunnable(mContext, mDb, mFinish, mDontSave);
|
|
||||||
save.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AfterDelete extends OnFinishRunnable {
|
|
||||||
|
|
||||||
private PwGroup mParent;
|
|
||||||
private PwGroup mGroup;
|
|
||||||
private boolean recycled;
|
|
||||||
|
|
||||||
AfterDelete(OnFinishRunnable finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
|
|
||||||
super(finish);
|
|
||||||
|
|
||||||
this.mParent = parent;
|
|
||||||
this.mGroup = mGroup;
|
|
||||||
this.recycled = recycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
if ( !mSuccess ) {
|
|
||||||
if (recycled) {
|
|
||||||
mDb.undoRecycle(mGroup, mParent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
|
|
||||||
App.setShutdown();
|
|
||||||
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO Callback after delete group
|
|
||||||
|
|
||||||
super.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,6 +24,7 @@ import android.net.Uri;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable {
|
public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable {
|
||||||
|
|
||||||
private Uri mFilename = null;
|
private Uri mFilename = null;
|
||||||
protected FileOnFinishRunnable mOnFinish;
|
protected FileOnFinishRunnable mOnFinish;
|
||||||
|
|
||||||
|
|||||||
@@ -42,33 +42,33 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class LoadDBRunnable extends RunnableOnFinish {
|
public class LoadDatabaseRunnable extends RunnableOnFinish {
|
||||||
private static final String TAG = LoadDBRunnable.class.getName();
|
private static final String TAG = LoadDatabaseRunnable.class.getName();
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private Database mDatabase;
|
||||||
private Uri mUri;
|
private Uri mUri;
|
||||||
private String mPass;
|
private String mPass;
|
||||||
private Uri mKey;
|
private Uri mKey;
|
||||||
private Database mDb;
|
|
||||||
private Context mCtx;
|
|
||||||
private boolean mRememberKeyfile;
|
private boolean mRememberKeyfile;
|
||||||
|
|
||||||
public LoadDBRunnable(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
|
public LoadDatabaseRunnable(Context context, Database database, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
|
||||||
super(finish);
|
super(finish);
|
||||||
|
|
||||||
mDb = db;
|
this.mContext = context;
|
||||||
mCtx = ctx;
|
this.mDatabase = database;
|
||||||
mUri = uri;
|
this.mUri = uri;
|
||||||
mPass = pass;
|
this.mPass = pass;
|
||||||
mKey = key;
|
this.mKey = key;
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default));
|
this.mRememberKeyfile = prefs.getBoolean(context.getString(R.string.keyfile_key), context.getResources().getBoolean(R.bool.keyfile_default));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
mDb.loadData(mCtx, mUri, mPass, mKey, mStatus);
|
mDatabase.loadData(mContext, mUri, mPass, mKey, mStatus);
|
||||||
|
|
||||||
saveFileData(mUri, mKey);
|
saveFileData(mUri, mKey);
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
|||||||
catchError(e, R.string.error_invalid_db);
|
catchError(e, R.string.error_invalid_db);
|
||||||
return;
|
return;
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
String errorMessage = mCtx.getString(R.string.error_out_of_memory);
|
String errorMessage = mContext.getString(R.string.error_out_of_memory);
|
||||||
Log.e(TAG, errorMessage, e);
|
Log.e(TAG, errorMessage, e);
|
||||||
finish(false, errorMessage);
|
finish(false, errorMessage);
|
||||||
return;
|
return;
|
||||||
@@ -121,7 +121,7 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void catchError(Exception e, @StringRes int messageId) {
|
private void catchError(Exception e, @StringRes int messageId) {
|
||||||
String errorMessage = mCtx.getString(messageId);
|
String errorMessage = mContext.getString(messageId);
|
||||||
Log.e(TAG, errorMessage, e);
|
Log.e(TAG, errorMessage, e);
|
||||||
finish(false, errorMessage);
|
finish(false, errorMessage);
|
||||||
}
|
}
|
||||||
@@ -134,6 +134,4 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
|||||||
App.getFileHistory().createFile(uri, key);
|
App.getFileHistory().createFile(uri, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -76,11 +76,29 @@ public class OnFinishRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Move
|
/**
|
||||||
|
* ONLY to use in UIThread, typically in an Activity, Fragment or a Service
|
||||||
|
* @param ctx Context to show the message
|
||||||
|
*/
|
||||||
protected void displayMessage(Context ctx) {
|
protected void displayMessage(Context ctx) {
|
||||||
if ( mMessage != null && mMessage.length() > 0 ) {
|
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||||
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return mSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccess(boolean mSuccess) {
|
||||||
|
this.mSuccess = mSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return mMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String mMessage) {
|
||||||
|
this.mMessage = mMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,21 @@ import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SaveDBRunnable extends RunnableOnFinish {
|
public class SaveDatabaseRunnable extends RunnableOnFinish {
|
||||||
|
|
||||||
private Context mCtx;
|
private Context mContext;
|
||||||
private Database mDb;
|
private Database mDatabase;
|
||||||
private boolean mDontSave;
|
private boolean mDontSave;
|
||||||
|
|
||||||
public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish, boolean dontSave) {
|
public SaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||||
super(finish);
|
super(finish);
|
||||||
|
|
||||||
this.mDb = db;
|
this.mContext = context;
|
||||||
|
this.mDatabase = database;
|
||||||
this.mDontSave = dontSave;
|
this.mDontSave = dontSave;
|
||||||
this.mCtx = ctx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish) {
|
public SaveDatabaseRunnable(Context ctx, Database db, OnFinishRunnable finish) {
|
||||||
this(ctx, db, finish, false);
|
this(ctx, db, finish, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class SaveDBRunnable extends RunnableOnFinish {
|
|||||||
|
|
||||||
if ( ! mDontSave ) {
|
if ( ! mDontSave ) {
|
||||||
try {
|
try {
|
||||||
mDb.saveData(mCtx);
|
mDatabase.saveData(mContext);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
finish(false, e.getMessage());
|
finish(false, e.getMessage());
|
||||||
return;
|
return;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
|
import com.kunzisoft.keepass.database.action.ActionWithSaveDatabaseRunnable;
|
||||||
|
|
||||||
|
abstract class ActionNodeDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||||
|
|
||||||
|
private AfterActionNodeOnFinish callbackRunnable;
|
||||||
|
|
||||||
|
public ActionNodeDatabaseRunnable(Context context, Database db, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
|
super(context, db, finish, dontSave);
|
||||||
|
this.callbackRunnable = finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback method who return the node(s) modified after an action
|
||||||
|
* - Add : @param oldNode NULL, @param newNode CreatedNode
|
||||||
|
* - Copy : @param oldNode NodeToCopy, @param newNode NodeCopied
|
||||||
|
* - Delete : @param oldNode NodeToDelete, @param NULL
|
||||||
|
* - Move : @param oldNode NULL, @param NodeToMove
|
||||||
|
* - Update : @param oldNode NodeToUpdate, @param NodeUpdated
|
||||||
|
*/
|
||||||
|
protected void callbackNodeAction(boolean success, String message, PwNode oldNode, PwNode newNode) {
|
||||||
|
if (callbackRunnable != null) {
|
||||||
|
callbackRunnable.setSuccess(success);
|
||||||
|
callbackRunnable.setMessage(message);
|
||||||
|
callbackRunnable.run(oldNode, newNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,57 +17,40 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
|
||||||
public class AddEntryRunnable extends RunnableOnFinish {
|
public class AddEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
protected Database mDb;
|
private PwEntry mNewEntry;
|
||||||
private PwEntry mEntry;
|
|
||||||
private Context ctx;
|
|
||||||
private boolean mDontSave;
|
|
||||||
|
|
||||||
public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) {
|
public AddEntryRunnable(Context ctx, Database db, PwEntry entryToAdd, AfterActionNodeOnFinish finish) {
|
||||||
this(ctx, db, entry, finish, false);
|
this(ctx, db, entryToAdd, finish, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) {
|
public AddEntryRunnable(Context ctx, Database db, PwEntry entryToAdd, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
super(finish);
|
super(ctx, db, finish, dontSave);
|
||||||
|
|
||||||
this.mDb = db;
|
this.mNewEntry = entryToAdd;
|
||||||
this.mEntry = entry;
|
|
||||||
this.ctx = ctx;
|
|
||||||
this.mDontSave = dontSave;
|
|
||||||
|
|
||||||
this.mFinish = new AfterAdd(mFinish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDb.addEntryTo(mEntry, mEntry.getParent());
|
mDatabase.addEntryTo(mNewEntry, mNewEntry.getParent());
|
||||||
|
|
||||||
// Commit to disk
|
// Commit to disk
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
|
super.run();
|
||||||
save.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AfterAdd extends OnFinishRunnable {
|
|
||||||
|
|
||||||
AfterAdd(OnFinishRunnable finish) {
|
@Override
|
||||||
super(finish);
|
protected void onFinish(boolean success, String message) {
|
||||||
}
|
if ( !success ) {
|
||||||
|
mDatabase.removeEntryFrom(mNewEntry, mNewEntry.getParent());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if ( !mSuccess ) {
|
|
||||||
mDb.removeEntryFrom(mEntry, mEntry.getParent());
|
|
||||||
}
|
|
||||||
// TODO if add entry callback
|
|
||||||
super.run();
|
|
||||||
}
|
}
|
||||||
|
callbackNodeAction(success, message, null, mNewEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,63 +17,40 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
public class AddGroupRunnable extends RunnableOnFinish {
|
public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
protected Database mDb;
|
|
||||||
private PwGroup mNewGroup;
|
private PwGroup mNewGroup;
|
||||||
private Context ctx;
|
|
||||||
private boolean mDontSave;
|
|
||||||
|
|
||||||
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
|
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
|
||||||
this(ctx, db, newGroup, afterAddNode, false);
|
this(ctx, db, newGroup, afterAddNode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
|
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||||
boolean dontSave) {
|
super(ctx, db, afterAddNode, dontSave);
|
||||||
super(afterAddNode);
|
|
||||||
|
|
||||||
this.mDb = db;
|
|
||||||
this.mNewGroup = newGroup;
|
this.mNewGroup = newGroup;
|
||||||
this.mDontSave = dontSave;
|
|
||||||
this.ctx = ctx;
|
|
||||||
|
|
||||||
this.mFinish = new AfterAdd(mFinish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
|
mDatabase.addGroupTo(mNewGroup, mNewGroup.getParent());
|
||||||
|
|
||||||
// Commit to disk
|
// Commit to disk
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
|
super.run();
|
||||||
save.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AfterAdd extends OnFinishRunnable {
|
|
||||||
|
|
||||||
AfterAdd(OnFinishRunnable finish) {
|
@Override
|
||||||
super(finish);
|
protected void onFinish(boolean success, String message) {
|
||||||
}
|
if ( !success ) {
|
||||||
|
mDatabase.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||||
@Override
|
}
|
||||||
public void run() {
|
callbackNodeAction(success, message, null, mNewGroup);
|
||||||
if ( !mSuccess ) {
|
|
||||||
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Better callback
|
|
||||||
AfterActionNodeOnFinish afterAddNode =
|
|
||||||
(AfterActionNodeOnFinish) super.mOnFinish;
|
|
||||||
afterAddNode.mSuccess = mSuccess;
|
|
||||||
afterAddNode.mMessage = mMessage;
|
|
||||||
afterAddNode.run(null, mNewGroup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,16 +17,20 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.PwNode;
|
import com.kunzisoft.keepass.database.PwNode;
|
||||||
|
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
|
public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
|
||||||
public AfterActionNodeOnFinish(Handler handler) {
|
|
||||||
super(handler);
|
public AfterActionNodeOnFinish() {
|
||||||
|
super(new Handler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void run(PwNode oldNode, PwNode newNode);
|
public abstract void run(@Nullable PwNode oldNode, @Nullable PwNode newNode);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
|
public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
|
private static final String TAG = CopyEntryRunnable.class.getName();
|
||||||
|
|
||||||
|
private PwEntry mEntryToCopy;
|
||||||
|
private PwEntry mEntryCopied;
|
||||||
|
private PwGroup mNewParent;
|
||||||
|
|
||||||
|
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||||
|
this(context, db, oldE, newParent, afterAddNode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||||
|
super(context, db, afterAddNode, dontSave);
|
||||||
|
|
||||||
|
this.mEntryToCopy = oldE;
|
||||||
|
this.mNewParent = newParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Update entry with new values
|
||||||
|
mEntryCopied = mDatabase.copyEntry(mEntryToCopy, mNewParent);
|
||||||
|
|
||||||
|
if (mEntryCopied != null) {
|
||||||
|
mEntryCopied.touch(true, true);
|
||||||
|
|
||||||
|
// Commit to disk
|
||||||
|
super.run();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unable to create a copy of the entry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
// If we fail to save, try to delete the copy
|
||||||
|
try {
|
||||||
|
mDatabase.deleteEntry(mEntryCopied);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.i(TAG, "Unable to delete the copied entry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, mEntryToCopy, mEntryCopied);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
|
public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
|
private PwEntry mEntryToDelete;
|
||||||
|
private PwGroup mParent;
|
||||||
|
private boolean mRecycle;
|
||||||
|
|
||||||
|
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish) {
|
||||||
|
this(ctx, db, entry, finish, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
|
super(ctx, db, finish, dontSave);
|
||||||
|
|
||||||
|
this.mEntryToDelete = entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mParent = mEntryToDelete.getParent();
|
||||||
|
|
||||||
|
// Remove Entry from parent
|
||||||
|
mRecycle = mDatabase.canRecycle(mEntryToDelete);
|
||||||
|
if (mRecycle) {
|
||||||
|
mDatabase.recycle(mEntryToDelete);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mDatabase.deleteEntry(mEntryToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit database
|
||||||
|
super.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
if (mRecycle) {
|
||||||
|
mDatabase.undoRecycle(mEntryToDelete, mParent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mDatabase.undoDeleteEntry(mEntryToDelete, mParent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, mEntryToDelete, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.app.App;
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
|
private PwGroup<PwGroup, PwGroup, PwEntry> mGroupToDelete;
|
||||||
|
private PwGroup mParent;
|
||||||
|
private boolean mRecycle;
|
||||||
|
|
||||||
|
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, AfterActionNodeOnFinish finish) {
|
||||||
|
this(ctx, db, group, finish, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
|
super(ctx, db, finish, dontSave);
|
||||||
|
mGroupToDelete = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mParent = mGroupToDelete.getParent();
|
||||||
|
|
||||||
|
// Remove Group from parent
|
||||||
|
mRecycle = mDatabase.canRecycle(mGroupToDelete);
|
||||||
|
if (mRecycle) {
|
||||||
|
mDatabase.recycle(mGroupToDelete);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO tests
|
||||||
|
// Remove child entries
|
||||||
|
List<PwEntry> childEnt = new ArrayList<>(mGroupToDelete.getChildEntries()); // TODO new Methods
|
||||||
|
for ( int i = 0; i < childEnt.size(); i++ ) {
|
||||||
|
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDatabase, childEnt.get(i), null, true);
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove child groups
|
||||||
|
List<PwGroup> childGrp = new ArrayList<>(mGroupToDelete.getChildGroups());
|
||||||
|
for ( int i = 0; i < childGrp.size(); i++ ) {
|
||||||
|
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDatabase, childGrp.get(i), null, true);
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
mDatabase.deleteGroup(mGroupToDelete);
|
||||||
|
|
||||||
|
// Remove from PwDatabaseV3
|
||||||
|
// TODO ENcapsulate
|
||||||
|
mDatabase.getPwDatabase().getGroups().remove(mGroupToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit Database
|
||||||
|
super.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
if (mRecycle) {
|
||||||
|
mDatabase.undoRecycle(mGroupToDelete, mParent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
|
||||||
|
App.setShutdown();
|
||||||
|
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, mGroupToDelete, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
|
public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
|
private static final String TAG = MoveEntryRunnable.class.getName();
|
||||||
|
|
||||||
|
private PwEntry mEntryToMove;
|
||||||
|
private PwGroup mOldParent;
|
||||||
|
private PwGroup mNewParent;
|
||||||
|
|
||||||
|
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||||
|
this(context, db, oldE, newParent, afterAddNode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||||
|
super(context, db, afterAddNode, dontSave);
|
||||||
|
|
||||||
|
this.mEntryToMove = oldE;
|
||||||
|
this.mNewParent = newParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Move entry in new parent
|
||||||
|
|
||||||
|
mOldParent = mEntryToMove.getParent();
|
||||||
|
mDatabase.moveEntry(mEntryToMove, mNewParent);
|
||||||
|
|
||||||
|
if (mEntryToMove != null) {
|
||||||
|
mEntryToMove.touch(true, true);
|
||||||
|
|
||||||
|
// Commit to disk
|
||||||
|
super.run();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unable to create a copy of the entry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
// If we fail to save, try to remove in the first place
|
||||||
|
try {
|
||||||
|
mDatabase.moveEntry(mEntryToMove, mOldParent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.i(TAG, "Unable to replace the entry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, null, mEntryToMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
import com.kunzisoft.keepass.database.Database;
|
||||||
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
|
public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
|
private static final String TAG = MoveGroupRunnable.class.getName();
|
||||||
|
|
||||||
|
private PwGroup mGroupToMove;
|
||||||
|
private PwGroup mOldParent;
|
||||||
|
private PwGroup mNewParent;
|
||||||
|
|
||||||
|
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||||
|
this(context, db, groupToMove, newParent, afterAddNode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||||
|
super(context, db, afterAddNode, dontSave);
|
||||||
|
|
||||||
|
this.mGroupToMove = groupToMove;
|
||||||
|
this.mNewParent = newParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mOldParent = mGroupToMove.getParent();
|
||||||
|
// Move group in new parent if not in the current group
|
||||||
|
if (!mGroupToMove.equals(mNewParent)
|
||||||
|
&& !mNewParent.isContainedIn(mGroupToMove)) {
|
||||||
|
mDatabase.moveGroup(mGroupToMove, mNewParent);
|
||||||
|
|
||||||
|
if (mGroupToMove != null) {
|
||||||
|
mGroupToMove.touch(true, true);
|
||||||
|
|
||||||
|
// Commit to disk
|
||||||
|
super.run();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unable to create a copy of the group");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Only finish thread
|
||||||
|
mFinish.setResult(false);
|
||||||
|
String message = mContext.getString(R.string.error_move_folder_in_itself);
|
||||||
|
Log.e(TAG, message);
|
||||||
|
mFinish.setMessage(message);
|
||||||
|
mFinish.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
// If we fail to save, try to move in the first place
|
||||||
|
try {
|
||||||
|
mDatabase.moveGroup(mGroupToMove, mOldParent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.i(TAG, "Unable to replace the group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, null, mGroupToMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,68 +17,47 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.database.PwEntry;
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
|
||||||
public class UpdateEntryRunnable extends RunnableOnFinish {
|
public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
private Database mDb;
|
private PwEntry mOldEntry;
|
||||||
private PwEntry mOldE;
|
private PwEntry mNewEntry;
|
||||||
private PwEntry mNewE;
|
private PwEntry mBackupEntry;
|
||||||
private Context ctx;
|
|
||||||
private boolean mDontSave;
|
|
||||||
|
|
||||||
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish) {
|
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish) {
|
||||||
this(ctx, db, oldE, newE, finish, false);
|
this(ctx, db, oldE, newE, finish, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish, boolean dontSave) {
|
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
super(finish);
|
super(ctx, db, finish, dontSave);
|
||||||
|
|
||||||
this.mDb = db;
|
this.mOldEntry = oldE;
|
||||||
this.mOldE = oldE;
|
this.mNewEntry = newE;
|
||||||
this.mNewE = newE;
|
|
||||||
this.ctx = ctx;
|
|
||||||
this.mDontSave = dontSave;
|
|
||||||
|
|
||||||
// Keep backup of original values in case save fails
|
// Keep backup of original values in case save fails
|
||||||
PwEntry backup;
|
this.mBackupEntry = mOldEntry.clone();
|
||||||
backup = mOldE.clone();
|
|
||||||
|
|
||||||
mFinish = new AfterUpdate(backup, finish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Update entry with new values
|
// Update entry with new values
|
||||||
mDb.updateEntry(mOldE, mNewE);
|
mDatabase.updateEntry(mOldEntry, mNewEntry);
|
||||||
mOldE.touch(true, true);
|
mOldEntry.touch(true, true);
|
||||||
|
|
||||||
// Commit to disk
|
super.run();
|
||||||
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
|
|
||||||
save.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AfterUpdate extends OnFinishRunnable {
|
|
||||||
private PwEntry mBackup;
|
|
||||||
|
|
||||||
AfterUpdate(PwEntry backup, OnFinishRunnable finish) {
|
|
||||||
super(finish);
|
|
||||||
mBackup = backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if ( !mSuccess ) {
|
|
||||||
// If we fail to save, back out changes to global structure
|
|
||||||
mDb.updateEntry(mOldE, mBackup);
|
|
||||||
}
|
|
||||||
// TODO Callback for update entry
|
|
||||||
super.run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinish(boolean success, String message) {
|
||||||
|
if ( !success ) {
|
||||||
|
// If we fail to save, back out changes to global structure
|
||||||
|
mDatabase.updateEntry(mOldEntry, mBackupEntry);
|
||||||
|
}
|
||||||
|
callbackNodeAction(success, message, mOldEntry, mNewEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,72 +17,48 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action.node;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
|
|
||||||
public class UpdateGroupRunnable extends RunnableOnFinish {
|
public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||||
|
|
||||||
private Database mDb;
|
|
||||||
private PwGroup mOldGroup;
|
private PwGroup mOldGroup;
|
||||||
private PwGroup mNewGroup;
|
private PwGroup mNewGroup;
|
||||||
private Context ctx;
|
private PwGroup mBackupGroup;
|
||||||
private boolean mDontSave;
|
|
||||||
|
|
||||||
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) {
|
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) {
|
||||||
this(ctx, db, oldGroup, newGroup, finish, false);
|
this(ctx, db, oldGroup, newGroup, finish, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) {
|
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||||
super(finish);
|
super(ctx, db, finish, dontSave);
|
||||||
|
|
||||||
this.mDb = db;
|
|
||||||
this.mOldGroup = oldGroup;
|
this.mOldGroup = oldGroup;
|
||||||
this.mNewGroup = newGroup;
|
this.mNewGroup = newGroup;
|
||||||
this.ctx = ctx;
|
|
||||||
this.mDontSave = dontSave;
|
|
||||||
|
|
||||||
// Keep backup of original values in case save fails
|
// Keep backup of original values in case save fails
|
||||||
PwGroup backup;
|
this.mBackupGroup = mOldGroup.clone();
|
||||||
backup = mOldGroup.clone();
|
|
||||||
|
|
||||||
this.mFinish = new AfterUpdate(backup, finish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Update group with new values
|
// Update group with new values
|
||||||
mDb.updateGroup(mOldGroup, mNewGroup);
|
mDatabase.updateGroup(mOldGroup, mNewGroup);
|
||||||
mOldGroup.touch(true, true);
|
mOldGroup.touch(true, true);
|
||||||
|
|
||||||
// Commit to disk
|
// Commit to disk
|
||||||
new SaveDBRunnable(ctx, mDb, mFinish, mDontSave).run();
|
super.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AfterUpdate extends OnFinishRunnable {
|
|
||||||
private PwGroup mBackup;
|
|
||||||
|
|
||||||
AfterUpdate(PwGroup backup, OnFinishRunnable finish) {
|
|
||||||
super(finish);
|
|
||||||
mBackup = backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if ( !mSuccess ) {
|
|
||||||
// If we fail to save, back out changes to global structure
|
|
||||||
mDb.updateGroup(mOldGroup, mBackup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Better callback
|
@Override
|
||||||
AfterActionNodeOnFinish afterActionNodeOnFinish =
|
protected void onFinish(boolean success, String message) {
|
||||||
(AfterActionNodeOnFinish) super.mOnFinish;
|
if ( !success ) {
|
||||||
afterActionNodeOnFinish.mSuccess = mSuccess;
|
// If we fail to save, back out changes to global structure
|
||||||
afterActionNodeOnFinish.mMessage = mMessage;
|
mDatabase.updateGroup(mOldGroup, mBackupGroup);
|
||||||
afterActionNodeOnFinish.run(mOldGroup, mNewGroup);
|
|
||||||
}
|
}
|
||||||
|
callbackNodeAction(success, message, mOldGroup, mNewGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.kunzisoft.keepass.database.exception;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class UnknownKDF extends IOException {
|
||||||
|
|
||||||
|
private static String message = "Unknown key derivation function";
|
||||||
|
|
||||||
|
public UnknownKDF() {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnknownKDF(Exception e) {
|
||||||
|
super(message, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,15 +76,19 @@ public class EntrySearchStringIteratorV3 extends EntrySearchStringIterator {
|
|||||||
switch (current) {
|
switch (current) {
|
||||||
case title:
|
case title:
|
||||||
found = sp.searchInTitles;
|
found = sp.searchInTitles;
|
||||||
|
break;
|
||||||
|
|
||||||
case url:
|
case url:
|
||||||
found = sp.searchInUrls;
|
found = sp.searchInUrls;
|
||||||
|
break;
|
||||||
|
|
||||||
case username:
|
case username:
|
||||||
found = sp.searchInUserNames;
|
found = sp.searchInUserNames;
|
||||||
|
break;
|
||||||
|
|
||||||
case comment:
|
case comment:
|
||||||
found = sp.searchInNotes;
|
found = sp.searchInNotes;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
found = true;
|
found = true;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public abstract class Importer {
|
|||||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
|
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
|
||||||
throws IOException, InvalidDBException;
|
throws IOException, InvalidDBException;
|
||||||
|
|
||||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater, long roundsFix)
|
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater)
|
||||||
throws IOException, InvalidDBException;
|
throws IOException, InvalidDBException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,11 +126,11 @@ public class ImporterV3 extends Importer {
|
|||||||
@Override
|
@Override
|
||||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
||||||
throws IOException, InvalidDBException {
|
throws IOException, InvalidDBException {
|
||||||
return openDatabase(inStream, password, kfIs, null, 0);
|
return openDatabase(inStream, password, kfIs, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix)
|
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater)
|
||||||
throws IOException, InvalidDBException {
|
throws IOException, InvalidDBException {
|
||||||
|
|
||||||
PwDatabaseV3 databaseToOpen;
|
PwDatabaseV3 databaseToOpen;
|
||||||
|
|||||||
@@ -35,10 +35,9 @@ public class ImporterV3Debug extends ImporterV3 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException,
|
InputStream keyInputStream, ProgressTaskUpdater status) throws IOException,
|
||||||
InvalidDBException {
|
InvalidDBException {
|
||||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status);
|
||||||
roundsFix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,12 +92,12 @@ public class ImporterV4 extends Importer {
|
|||||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream) throws IOException, InvalidDBException {
|
InputStream keyInputStream) throws IOException, InvalidDBException {
|
||||||
|
|
||||||
return openDatabase(inStream, password, keyInputStream, null, 0);
|
return openDatabase(inStream, password, keyInputStream, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater, long roundsFix) throws IOException,
|
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater) throws IOException,
|
||||||
InvalidDBException {
|
InvalidDBException {
|
||||||
|
|
||||||
if (progressTaskUpdater != null)
|
if (progressTaskUpdater != null)
|
||||||
@@ -114,7 +114,7 @@ public class ImporterV4 extends Importer {
|
|||||||
pbHeader = hh.header;
|
pbHeader = hh.header;
|
||||||
|
|
||||||
db.retrieveMasterKey(password, keyInputStream);
|
db.retrieveMasterKey(password, keyInputStream);
|
||||||
db.makeFinalKey(header.masterSeed, roundsFix);
|
db.makeFinalKey(header.masterSeed);
|
||||||
|
|
||||||
if (progressTaskUpdater != null)
|
if (progressTaskUpdater != null)
|
||||||
progressTaskUpdater.updateMessage(R.string.decrypting_db);
|
progressTaskUpdater.updateMessage(R.string.decrypting_db);
|
||||||
@@ -125,14 +125,8 @@ public class ImporterV4 extends Importer {
|
|||||||
db.setDataEngine(engine);
|
db.setDataEngine(engine);
|
||||||
db.setEncryptionAlgorithm(engine.getPwEncryptionAlgorithm());
|
db.setEncryptionAlgorithm(engine.getPwEncryptionAlgorithm());
|
||||||
cipher = engine.getCipher(Cipher.DECRYPT_MODE, db.getFinalKey(), header.encryptionIV);
|
cipher = engine.getCipher(Cipher.DECRYPT_MODE, db.getFinalKey(), header.encryptionIV);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException|NoSuchPaddingException|InvalidKeyException|InvalidAlgorithmParameterException e) {
|
||||||
throw new IOException("Invalid algorithm.");
|
throw new IOException("Invalid algorithm.", e);
|
||||||
} catch (NoSuchPaddingException e) {
|
|
||||||
throw new IOException("Invalid algorithm.");
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
throw new IOException("Invalid algorithm.");
|
|
||||||
} catch (InvalidAlgorithmParameterException e) {
|
|
||||||
throw new IOException("Invalid algorithm.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream isPlain;
|
InputStream isPlain;
|
||||||
@@ -963,7 +957,7 @@ public class ImporterV4 extends Importer {
|
|||||||
ReadUnknown(xpp);
|
ReadUnknown(xpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(xpp.getName() == unknownName);
|
assert(xpp.getName().equals(unknownName));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
mPM.makeFinalKey(h3.masterSeed, h3.transformSeed, mPM.getNumberKeyEncryptionRounds());
|
mPM.makeFinalKey(h3.masterSeed, h3.transformSeed, mPM.getNumberKeyEncryptionRounds());
|
||||||
return mPM.getFinalKey();
|
return mPM.getFinalKey();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Key creation failed: " + e.getMessage());
|
throw new PwDbOutputException("Key creation failed.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PwDbOutputException("Algorithm not supported.");
|
throw new PwDbOutputException("Algorithm not supported.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -97,11 +97,11 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
bos.close();
|
bos.close();
|
||||||
|
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
throw new PwDbOutputException("Invalid key");
|
throw new PwDbOutputException("Invalid key", e);
|
||||||
} catch (InvalidAlgorithmParameterException e) {
|
} catch (InvalidAlgorithmParameterException e) {
|
||||||
throw new PwDbOutputException("Invalid algorithm parameter.");
|
throw new PwDbOutputException("Invalid algorithm parameter.", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Failed to output final encrypted part.");
|
throw new PwDbOutputException("Failed to output final encrypted part.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
try {
|
try {
|
||||||
md = MessageDigest.getInstance("SHA-256");
|
md = MessageDigest.getInstance("SHA-256");
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new PwDbOutputException("SHA-256 not implemented here.");
|
throw new PwDbOutputException("SHA-256 not implemented here.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header checksum
|
// Header checksum
|
||||||
@@ -153,7 +153,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
try {
|
try {
|
||||||
headerDigest = MessageDigest.getInstance("SHA-256");
|
headerDigest = MessageDigest.getInstance("SHA-256");
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new PwDbOutputException("SHA-256 not implemented here.");
|
throw new PwDbOutputException("SHA-256 not implemented here.", e);
|
||||||
}
|
}
|
||||||
NullOutputStream nos;
|
NullOutputStream nos;
|
||||||
nos = new NullOutputStream();
|
nos = new NullOutputStream();
|
||||||
@@ -180,7 +180,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
bos.flush();
|
bos.flush();
|
||||||
bos.close();
|
bos.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Failed to generate checksum.");
|
throw new PwDbOutputException("Failed to generate checksum.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
header.contentsHash = md.digest();
|
header.contentsHash = md.digest();
|
||||||
@@ -210,7 +210,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
los.writeInt(headerHashBlock.length);
|
los.writeInt(headerHashBlock.length);
|
||||||
los.write(headerHashBlock);
|
los.write(headerHashBlock);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
|
throw new PwDbOutputException("Failed to output header hash.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
try {
|
try {
|
||||||
pgo.output();
|
pgo.output();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
|
throw new PwDbOutputException("Failed to output a tree", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
try {
|
try {
|
||||||
peo.output();
|
peo.output();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PwDbOutputException("Failed to output an entry.");
|
throw new PwDbOutputException("Failed to output an entry.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.save;
|
package com.kunzisoft.keepass.database.save;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.crypto.CipherFactory;
|
import com.kunzisoft.keepass.crypto.CipherFactory;
|
||||||
@@ -42,6 +43,7 @@ import com.kunzisoft.keepass.database.PwEntryV4;
|
|||||||
import com.kunzisoft.keepass.database.PwGroupV4;
|
import com.kunzisoft.keepass.database.PwGroupV4;
|
||||||
import com.kunzisoft.keepass.database.PwIconCustom;
|
import com.kunzisoft.keepass.database.PwIconCustom;
|
||||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||||
|
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||||
import com.kunzisoft.keepass.database.security.ProtectedBinary;
|
import com.kunzisoft.keepass.database.security.ProtectedBinary;
|
||||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||||
import com.kunzisoft.keepass.stream.HashedBlockOutputStream;
|
import com.kunzisoft.keepass.stream.HashedBlockOutputStream;
|
||||||
@@ -74,6 +76,7 @@ import javax.crypto.CipherOutputStream;
|
|||||||
import biz.source_code.base64Coder.Base64Coder;
|
import biz.source_code.base64Coder.Base64Coder;
|
||||||
|
|
||||||
public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
|
public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
|
||||||
|
private static final String TAG = PwDbV4Output.class.getName();
|
||||||
|
|
||||||
private PwDatabaseV4 mPM;
|
private PwDatabaseV4 mPM;
|
||||||
private StreamCipher randomStream;
|
private StreamCipher randomStream;
|
||||||
@@ -276,10 +279,8 @@ public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PwDbOutputException("Invalid algorithm.", e);
|
throw new PwDbOutputException("Invalid algorithm.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
CipherOutputStream cos = new CipherOutputStream(os, cipher);
|
return new CipherOutputStream(os, cipher);
|
||||||
|
|
||||||
return cos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -296,8 +297,13 @@ public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
|
|||||||
if (mPM.getKdfParameters() == null) {
|
if (mPM.getKdfParameters() == null) {
|
||||||
mPM.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
mPM.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
||||||
}
|
}
|
||||||
KdfEngine kdf = KdfFactory.get(mPM.getKdfParameters());
|
|
||||||
kdf.randomize(mPM.getKdfParameters());
|
try {
|
||||||
|
KdfEngine kdf = KdfFactory.getEngineV4(mPM.getKdfParameters());
|
||||||
|
kdf.randomize(mPM.getKdfParameters());
|
||||||
|
} catch (UnknownKDF unknownKDF) {
|
||||||
|
Log.e(TAG, "Unable to retrieve header", unknownKDF);
|
||||||
|
}
|
||||||
|
|
||||||
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
|
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
|
||||||
header.innerRandomStream = CrsAlgorithm.Salsa20;
|
header.innerRandomStream = CrsAlgorithm.Salsa20;
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public class GroupEditDialogFragment extends DialogFragment
|
|||||||
// Init elements
|
// Init elements
|
||||||
editGroupDialogAction = EditGroupDialogAction.NONE;
|
editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||||
nameGroup = "";
|
nameGroup = "";
|
||||||
iconGroup = App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
|
iconGroup = App.getDB().getPwDatabase().getIconFactory().getFolderIcon();
|
||||||
|
|
||||||
if (savedInstanceState != null
|
if (savedInstanceState != null
|
||||||
&& savedInstanceState.containsKey(KEY_ACTION_ID)
|
&& savedInstanceState.containsKey(KEY_ACTION_ID)
|
||||||
|
|||||||
@@ -20,9 +20,9 @@
|
|||||||
package com.kunzisoft.keepass.dialogs;
|
package com.kunzisoft.keepass.dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.compat.BuildCompat;
|
|
||||||
|
|
||||||
public class ReadOnlyDialog extends WarningDialog {
|
public class ReadOnlyDialog extends WarningDialog {
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class ReadOnlyDialog extends WarningDialog {
|
|||||||
|
|
||||||
warning = context.getString(R.string.read_only_warning);
|
warning = context.getString(R.string.read_only_warning);
|
||||||
|
|
||||||
if (BuildCompat.getSdkVersion() >= BuildCompat.VERSION_KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
warning = warning.concat("\n\n").concat(context.getString(R.string.read_only_kitkat_warning));
|
warning = warning.concat("\n\n").concat(context.getString(R.string.read_only_kitkat_warning));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.dialogs;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
|
||||||
|
|
||||||
public class StorageAccessFrameworkDialog extends AlertDialog {
|
|
||||||
|
|
||||||
public StorageAccessFrameworkDialog(@NonNull Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageAccessFrameworkDialog(@NonNull Context context, int themeResId) {
|
|
||||||
super(context, themeResId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageAccessFrameworkDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
|
|
||||||
super(context, cancelable, cancelListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
Context ctx = getContext();
|
|
||||||
setMessage(ctx.getString(R.string.warning_disabling_storage_access_framework));
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,13 +26,14 @@ import android.database.Cursor;
|
|||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.util.Log;
|
||||||
import com.kunzisoft.keepass.compat.EditorCompat;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
|
||||||
public class FileDbHelper {
|
public class FileDbHelper {
|
||||||
|
|
||||||
|
private static final String TAG = FileDbHelper.class.getName();
|
||||||
|
|
||||||
public static final String LAST_FILENAME = "lastFile";
|
public static final String LAST_FILENAME = "lastFile";
|
||||||
public static final String LAST_KEYFILE = "lastKey";
|
public static final String LAST_KEYFILE = "lastKey";
|
||||||
@@ -102,9 +103,9 @@ public class FileDbHelper {
|
|||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.remove(LAST_FILENAME);
|
editor.remove(LAST_FILENAME);
|
||||||
editor.remove(LAST_KEYFILE);
|
editor.remove(LAST_KEYFILE);
|
||||||
EditorCompat.apply(editor);
|
editor.apply();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assert(true);
|
Log.e(TAG, "Unable to delete database preference", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +253,7 @@ public class FileDbHelper {
|
|||||||
* Deletes a database including its journal file and other auxiliary files
|
* Deletes a database including its journal file and other auxiliary files
|
||||||
* that may have been created by the database engine.
|
* that may have been created by the database engine.
|
||||||
*
|
*
|
||||||
* @param file The database file path.
|
* @param ctx Context to get database path
|
||||||
* @return True if the database was successfully deleted.
|
* @return True if the database was successfully deleted.
|
||||||
*/
|
*/
|
||||||
public static boolean deleteDatabase(Context ctx) {
|
public static boolean deleteDatabase(Context ctx) {
|
||||||
|
|||||||
@@ -51,13 +51,14 @@ import com.kunzisoft.keepass.R;
|
|||||||
import com.kunzisoft.keepass.activities.GroupActivity;
|
import com.kunzisoft.keepass.activities.GroupActivity;
|
||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||||
import com.kunzisoft.keepass.database.action.CreateDBRunnable;
|
import com.kunzisoft.keepass.database.action.CreateDatabaseRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
||||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
|
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
|
||||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||||
import com.kunzisoft.keepass.password.PasswordActivity;
|
import com.kunzisoft.keepass.password.PasswordActivity;
|
||||||
|
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
import com.kunzisoft.keepass.stylish.StylishActivity;
|
import com.kunzisoft.keepass.stylish.StylishActivity;
|
||||||
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
||||||
@@ -102,6 +103,8 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
|
|
||||||
// TODO Consultation Mode
|
// TODO Consultation Mode
|
||||||
private boolean consultationMode = false;
|
private boolean consultationMode = false;
|
||||||
|
|
||||||
|
private boolean entrySelectionMode;
|
||||||
private AutofillHelper autofillHelper;
|
private AutofillHelper autofillHelper;
|
||||||
|
|
||||||
private View fileSelectExpandableButton;
|
private View fileSelectExpandableButton;
|
||||||
@@ -118,11 +121,17 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
public static void launch(Activity activity) {
|
public static void launch(Activity activity) {
|
||||||
Intent intent = new Intent(activity, FileSelectActivity.class);
|
Intent intent = new Intent(activity, FileSelectActivity.class);
|
||||||
// only to avoid visible flickering when redirecting
|
// only to avoid visible flickering when redirecting
|
||||||
activity.startActivityForResult(intent, 0);
|
activity.startActivityForResult(intent, RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void launchForKeyboardResult(Activity activity) {
|
||||||
|
Intent intent = new Intent(activity, FileSelectActivity.class);
|
||||||
|
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
|
||||||
|
activity.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public static void launch(Activity activity, AssistStructure assistStructure) {
|
public static void launchForAutofillResult(Activity activity, AssistStructure assistStructure) {
|
||||||
if ( assistStructure != null ) {
|
if ( assistStructure != null ) {
|
||||||
Intent intent = new Intent(activity, FileSelectActivity.class);
|
Intent intent = new Intent(activity, FileSelectActivity.class);
|
||||||
AutofillHelper.addAssistStructureExtraInIntent(intent, assistStructure);
|
AutofillHelper.addAssistStructureExtraInIntent(intent, assistStructure);
|
||||||
@@ -136,11 +145,6 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
if (AutofillHelper.isIntentContainsExtraAssistStructureKey(getIntent()))
|
|
||||||
consultationMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileHistory = App.getFileHistory();
|
fileHistory = App.getFileHistory();
|
||||||
|
|
||||||
setContentView(R.layout.file_selection);
|
setContentView(R.layout.file_selection);
|
||||||
@@ -173,6 +177,7 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
RecyclerView mListFiles = findViewById(R.id.file_list);
|
RecyclerView mListFiles = findViewById(R.id.file_list);
|
||||||
mListFiles.setLayoutManager(new LinearLayoutManager(this));
|
mListFiles.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
|
||||||
|
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
|
||||||
// To retrieve info for AutoFill
|
// To retrieve info for AutoFill
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
autofillHelper = new AutofillHelper();
|
autofillHelper = new AutofillHelper();
|
||||||
@@ -244,13 +249,17 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
assistStructure = autofillHelper.getAssistStructure();
|
assistStructure = autofillHelper.getAssistStructure();
|
||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
PasswordActivity.launch(FileSelectActivity.this,
|
PasswordActivity.launchForAutofillResult(FileSelectActivity.this,
|
||||||
path,
|
path,
|
||||||
assistStructure);
|
assistStructure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (assistStructure == null) {
|
if (assistStructure == null) {
|
||||||
PasswordActivity.launch(FileSelectActivity.this, path);
|
if (entrySelectionMode) {
|
||||||
|
PasswordActivity.launchForKeyboardResult(FileSelectActivity.this, path);
|
||||||
|
} else {
|
||||||
|
PasswordActivity.launch(FileSelectActivity.this, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Delete flickering for kitkat <=
|
// Delete flickering for kitkat <=
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||||
@@ -346,60 +355,62 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
* Displays the explanation for a database selection
|
* Displays the explanation for a database selection
|
||||||
*/
|
*/
|
||||||
private void checkAndPerformedEducationForSelection() {
|
private void checkAndPerformedEducationForSelection() {
|
||||||
|
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||||
|
|
||||||
if (!PreferencesUtil.isEducationSelectDatabasePerformed(this)
|
if (!PreferencesUtil.isEducationSelectDatabasePerformed(this)
|
||||||
&& browseButtonView != null) {
|
&& browseButtonView != null) {
|
||||||
|
|
||||||
TapTargetView.showFor(FileSelectActivity.this,
|
TapTargetView.showFor(FileSelectActivity.this,
|
||||||
TapTarget.forView(browseButtonView,
|
TapTarget.forView(browseButtonView,
|
||||||
getString(R.string.education_select_database_title),
|
getString(R.string.education_select_database_title),
|
||||||
getString(R.string.education_select_database_summary))
|
getString(R.string.education_select_database_summary))
|
||||||
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
|
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
|
||||||
.textColorInt(Color.WHITE)
|
.textColorInt(Color.WHITE)
|
||||||
.tintTarget(true)
|
.tintTarget(true)
|
||||||
.cancelable(true),
|
.cancelable(true),
|
||||||
new TapTargetView.Listener() {
|
new TapTargetView.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTargetClick(TapTargetView view) {
|
public void onTargetClick(TapTargetView view) {
|
||||||
super.onTargetClick(view);
|
super.onTargetClick(view);
|
||||||
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
|
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
|
|
||||||
if (!PreferencesUtil.isEducationOpenLinkDatabasePerformed(FileSelectActivity.this)) {
|
|
||||||
|
|
||||||
TapTargetView.showFor(FileSelectActivity.this,
|
|
||||||
TapTarget.forView(fileSelectExpandableButton,
|
|
||||||
getString(R.string.education_open_link_database_title),
|
|
||||||
getString(R.string.education_open_link_database_summary))
|
|
||||||
.icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(true)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
// Do nothing here
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
|
||||||
super.onOuterCircleClick(view);
|
|
||||||
view.dismiss(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
|
|
||||||
R.string.education_open_link_db_key);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
@Override
|
||||||
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
R.string.education_select_db_key);
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
|
||||||
|
if (!PreferencesUtil.isEducationOpenLinkDatabasePerformed(FileSelectActivity.this)) {
|
||||||
|
|
||||||
|
TapTargetView.showFor(FileSelectActivity.this,
|
||||||
|
TapTarget.forView(fileSelectExpandableButton,
|
||||||
|
getString(R.string.education_open_link_database_title),
|
||||||
|
getString(R.string.education_open_link_database_summary))
|
||||||
|
.icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(true)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
// Do nothing here
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
|
super.onOuterCircleClick(view);
|
||||||
|
view.dismiss(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
|
||||||
|
R.string.education_open_link_db_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
|
||||||
|
R.string.education_select_db_key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +538,7 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
assignPasswordHelper.setCreateProgressDialog(false);
|
assignPasswordHelper.setCreateProgressDialog(false);
|
||||||
|
|
||||||
// Create the new database
|
// Create the new database
|
||||||
CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this,
|
CreateDatabaseRunnable createDBTask = new CreateDatabaseRunnable(FileSelectActivity.this,
|
||||||
databaseFilename, assignPasswordOnFinish, true);
|
databaseFilename, assignPasswordOnFinish, true);
|
||||||
createDBTask.setUpdateProgressTaskStatus(
|
createDBTask.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(this,
|
new UpdateProgressTaskStatus(this,
|
||||||
@@ -578,11 +589,13 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mSuccess) {
|
if (mSuccess) {
|
||||||
// Add to recent files
|
runOnUiThread(() -> {
|
||||||
fileHistory.createFile(mUri, getFilename());
|
// Add to recent files
|
||||||
mAdapter.notifyDataSetChanged();
|
fileHistory.createFile(mUri, getFilename());
|
||||||
updateTitleFileListView();
|
mAdapter.notifyDataSetChanged();
|
||||||
GroupActivity.launch(FileSelectActivity.this);
|
updateTitleFileListView();
|
||||||
|
GroupActivity.launch(FileSelectActivity.this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,12 +609,16 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
assistStructure = autofillHelper.getAssistStructure();
|
assistStructure = autofillHelper.getAssistStructure();
|
||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
PasswordActivity.launch(FileSelectActivity.this,
|
PasswordActivity.launchForAutofillResult(FileSelectActivity.this,
|
||||||
fileName, keyFile, assistStructure);
|
fileName, keyFile, assistStructure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (assistStructure == null) {
|
if (assistStructure == null) {
|
||||||
PasswordActivity.launch(FileSelectActivity.this, fileName, keyFile);
|
if (entrySelectionMode) {
|
||||||
|
PasswordActivity.launchForKeyboardResult(FileSelectActivity.this, fileName, keyFile);
|
||||||
|
} else {
|
||||||
|
PasswordActivity.launch(FileSelectActivity.this, fileName, keyFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (ContentFileNotFoundException e) {
|
} catch (ContentFileNotFoundException e) {
|
||||||
Toast.makeText(FileSelectActivity.this,
|
Toast.makeText(FileSelectActivity.this,
|
||||||
@@ -639,6 +656,8 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
// Get the entry result in entry selection mode
|
||||||
|
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.compat.ContentResolverCompat;
|
|
||||||
import com.kunzisoft.keepass.compat.StorageAF;
|
import com.kunzisoft.keepass.compat.StorageAF;
|
||||||
import com.kunzisoft.keepass.utils.Interaction;
|
import com.kunzisoft.keepass.utils.Interaction;
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
@@ -200,9 +199,11 @@ public class KeyFileHelper {
|
|||||||
if (StorageAF.useStorageFramework(activity)) {
|
if (StorageAF.useStorageFramework(activity)) {
|
||||||
try {
|
try {
|
||||||
// try to persist read and write permissions
|
// try to persist read and write permissions
|
||||||
ContentResolver resolver = activity.getContentResolver();
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
ContentResolverCompat.takePersistableUriPermission(resolver, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
ContentResolver resolver = activity.getContentResolver();
|
||||||
ContentResolverCompat.takePersistableUriPermission(resolver, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
resolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
resolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import android.net.Uri;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.compat.EditorCompat;
|
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -190,7 +189,7 @@ public class RecentFileHistory {
|
|||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
edit.putString(keyprefix + "_" + i, list.get(i));
|
edit.putString(keyprefix + "_" + i, list.get(i));
|
||||||
}
|
}
|
||||||
EditorCompat.apply(edit);
|
edit.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFile(Uri uri) {
|
public void deleteFile(Uri uri) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.kunzisoft.keepass.fingerprint;
|
package com.kunzisoft.keepass.fingerprint;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -30,41 +29,34 @@ import android.support.v4.app.DialogFragment;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
public class FingerPrintDialog extends DialogFragment {
|
public class FingerPrintExplanationDialog extends DialogFragment {
|
||||||
|
|
||||||
private FingerPrintAnimatedVector fingerPrintAnimatedVector;
|
private FingerPrintAnimatedVector fingerPrintAnimatedVector;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
assert getActivity() != null;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
|
|
||||||
View rootView = inflater.inflate(R.layout.fingerprint_dialog, null);
|
View rootView = inflater.inflate(R.layout.fingerprint_explanation, null);
|
||||||
|
|
||||||
View fingerprintSettingWayTextView = rootView.findViewById(R.id.fingerprint_setting_way_text);
|
View fingerprintSettingWayTextView = rootView.findViewById(R.id.fingerprint_setting_way_text);
|
||||||
fingerprintSettingWayTextView.setOnClickListener(new View.OnClickListener() {
|
fingerprintSettingWayTextView.setOnClickListener(
|
||||||
@Override
|
view -> startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS)));
|
||||||
public void onClick(View view) {
|
|
||||||
startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fingerPrintAnimatedVector =
|
fingerPrintAnimatedVector =
|
||||||
new FingerPrintAnimatedVector(getContext(),
|
new FingerPrintAnimatedVector(getActivity(),
|
||||||
(ImageView) rootView.findViewById(R.id.fingerprint_image));
|
rootView.findViewById(R.id.fingerprint_image));
|
||||||
|
|
||||||
builder.setView(rootView)
|
builder.setView(rootView)
|
||||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
@@ -22,13 +22,13 @@ package com.kunzisoft.keepass.fingerprint;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.CancellationSignal;
|
||||||
import android.security.keystore.KeyGenParameterSpec;
|
import android.security.keystore.KeyGenParameterSpec;
|
||||||
import android.security.keystore.KeyPermanentlyInvalidatedException;
|
import android.security.keystore.KeyPermanentlyInvalidatedException;
|
||||||
import android.security.keystore.KeyProperties;
|
import android.security.keystore.KeyProperties;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
|
|
||||||
import android.support.v4.os.CancellationSignal;
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -52,19 +52,19 @@ public class FingerPrintHelper {
|
|||||||
|
|
||||||
private static final String FINGERPRINT_KEYSTORE_KEY = "com.kunzisoft.keepass.fingerprint.key";
|
private static final String FINGERPRINT_KEYSTORE_KEY = "com.kunzisoft.keepass.fingerprint.key";
|
||||||
|
|
||||||
private FingerprintManagerCompat fingerprintManager;
|
private FingerprintManager fingerprintManager;
|
||||||
private KeyStore keyStore = null;
|
private KeyStore keyStore = null;
|
||||||
private KeyGenerator keyGenerator = null;
|
private KeyGenerator keyGenerator = null;
|
||||||
private Cipher cipher = null;
|
private Cipher cipher = null;
|
||||||
private KeyguardManager keyguardManager = null;
|
private KeyguardManager keyguardManager = null;
|
||||||
private FingerprintManagerCompat.CryptoObject cryptoObject = null;
|
private FingerprintManager.CryptoObject cryptoObject = null;
|
||||||
|
|
||||||
private boolean initOk = false;
|
private boolean initOk = false;
|
||||||
private FingerPrintCallback fingerPrintCallback;
|
private FingerPrintCallback fingerPrintCallback;
|
||||||
private CancellationSignal cancellationSignal;
|
private CancellationSignal cancellationSignal;
|
||||||
private FingerprintManagerCompat.AuthenticationCallback authenticationCallback;
|
private FingerprintManager.AuthenticationCallback authenticationCallback;
|
||||||
|
|
||||||
public void setAuthenticationCallback(final FingerprintManagerCompat.AuthenticationCallback authenticationCallback) {
|
public void setAuthenticationCallback(final FingerprintManager.AuthenticationCallback authenticationCallback) {
|
||||||
this.authenticationCallback = authenticationCallback;
|
this.authenticationCallback = authenticationCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,8 +73,8 @@ public class FingerPrintHelper {
|
|||||||
cancellationSignal = new CancellationSignal();
|
cancellationSignal = new CancellationSignal();
|
||||||
fingerprintManager.authenticate(
|
fingerprintManager.authenticate(
|
||||||
cryptoObject,
|
cryptoObject,
|
||||||
0 /* flags */,
|
|
||||||
cancellationSignal,
|
cancellationSignal,
|
||||||
|
0 /* flags */,
|
||||||
authenticationCallback,
|
authenticationCallback,
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ public class FingerPrintHelper {
|
|||||||
final Context context,
|
final Context context,
|
||||||
final FingerPrintCallback fingerPrintCallback) {
|
final FingerPrintCallback fingerPrintCallback) {
|
||||||
|
|
||||||
this.fingerprintManager = FingerprintManagerCompat.from(context);
|
this.fingerprintManager = context.getSystemService(FingerprintManager.class);
|
||||||
if (!isFingerprintSupported(fingerprintManager)) {
|
if (!isFingerprintSupported(fingerprintManager)) {
|
||||||
// really not much to do when no fingerprint support found
|
// really not much to do when no fingerprint support found
|
||||||
setInitOk(false);
|
setInitOk(false);
|
||||||
@@ -112,7 +112,7 @@ public class FingerPrintHelper {
|
|||||||
KeyProperties.KEY_ALGORITHM_AES + "/"
|
KeyProperties.KEY_ALGORITHM_AES + "/"
|
||||||
+ KeyProperties.BLOCK_MODE_CBC + "/"
|
+ KeyProperties.BLOCK_MODE_CBC + "/"
|
||||||
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
|
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
|
||||||
this.cryptoObject = new FingerprintManagerCompat.CryptoObject(cipher);
|
this.cryptoObject = new FingerprintManager.CryptoObject(cipher);
|
||||||
setInitOk(true);
|
setInitOk(true);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Log.e(TAG, "Unable to initialize the keystore", e);
|
Log.e(TAG, "Unable to initialize the keystore", e);
|
||||||
@@ -122,7 +122,7 @@ public class FingerPrintHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFingerprintSupported(FingerprintManagerCompat fingerprintManager) {
|
public static boolean isFingerprintSupported(FingerprintManager fingerprintManager) {
|
||||||
return fingerprintManager != null
|
return fingerprintManager != null
|
||||||
&& fingerprintManager.isHardwareDetected();
|
&& fingerprintManager.isHardwareDetected();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
@@ -33,7 +34,6 @@ import android.util.Log;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.compat.BitmapDrawableCompat;
|
|
||||||
import com.kunzisoft.keepass.database.PwIcon;
|
import com.kunzisoft.keepass.database.PwIcon;
|
||||||
import com.kunzisoft.keepass.database.PwIconCustom;
|
import com.kunzisoft.keepass.database.PwIconCustom;
|
||||||
import com.kunzisoft.keepass.database.PwIconStandard;
|
import com.kunzisoft.keepass.database.PwIconStandard;
|
||||||
@@ -305,7 +305,7 @@ public class IconDrawableFactory {
|
|||||||
|
|
||||||
bitmap = resize(bitmap);
|
bitmap = resize(bitmap);
|
||||||
|
|
||||||
draw = BitmapDrawableCompat.getBitmapDrawable(context.getResources(), bitmap);
|
draw = new BitmapDrawable(context.getResources(), bitmap);
|
||||||
customIconMap.put(icon.uuid, draw);
|
customIconMap.put(icon.uuid, draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.keyboard;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.BuildConfig;
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
import com.kunzisoft.keepass.utils.Util;
|
||||||
|
|
||||||
|
import static android.content.Context.INPUT_METHOD_SERVICE;
|
||||||
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
|
|
||||||
|
public class KeyboardExplanationDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
assert getActivity() != null;
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
|
|
||||||
|
View rootView = inflater.inflate(R.layout.keyboard_explanation, null);
|
||||||
|
|
||||||
|
View fingerprintSettingPath1TextView = rootView.findViewById(R.id.keyboards_activate_setting_path1_text);
|
||||||
|
fingerprintSettingPath1TextView.setOnClickListener(
|
||||||
|
view -> launchActivateKeyboardSetting());
|
||||||
|
View fingerprintSettingPath2TextView = rootView.findViewById(R.id.keyboards_activate_setting_path2_text);
|
||||||
|
fingerprintSettingPath2TextView.setOnClickListener(
|
||||||
|
view -> launchActivateKeyboardSetting());
|
||||||
|
|
||||||
|
View containerKeyboardSwitcher = rootView.findViewById(R.id.container_keyboard_switcher);
|
||||||
|
if(BuildConfig.CLOSED_STORE) {
|
||||||
|
containerKeyboardSwitcher.setOnClickListener(
|
||||||
|
view -> Util.gotoUrl(getContext(), R.string.keyboard_switcher_play_store));
|
||||||
|
} else {
|
||||||
|
containerKeyboardSwitcher.setOnClickListener(
|
||||||
|
view -> Util.gotoUrl(getContext(), R.string.keyboard_switcher_f_droid));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setView(rootView)
|
||||||
|
.setPositiveButton(android.R.string.ok, (dialog, id) -> {});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchActivateKeyboardSetting() {
|
||||||
|
Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
|
||||||
|
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,9 +17,10 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.activities;
|
package com.kunzisoft.keepass.lock;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -37,14 +38,19 @@ public abstract class LockingActivity extends StylishActivity {
|
|||||||
|
|
||||||
private static final String TAG = LockingActivity.class.getName();
|
private static final String TAG = LockingActivity.class.getName();
|
||||||
|
|
||||||
|
public static final String LOCK_ACTION = "com.kunzisoft.keepass.LOCK";
|
||||||
|
|
||||||
public static final int RESULT_EXIT_LOCK = 1450;
|
public static final int RESULT_EXIT_LOCK = 1450;
|
||||||
|
|
||||||
private static final String AT_LEAST_SECOND_SHOWN_KEY = "AT_LEAST_SECOND_SHOWN_KEY";
|
private LockReceiver lockReceiver;
|
||||||
|
|
||||||
private ScreenReceiver screenReceiver;
|
|
||||||
private boolean exitLock;
|
private boolean exitLock;
|
||||||
|
|
||||||
protected static void recordFirstTimeBeforeLaunch(Activity activity) {
|
|
||||||
|
/**
|
||||||
|
* Called to start a record time,
|
||||||
|
* Generally used for a first launch or for a fragment change
|
||||||
|
*/
|
||||||
|
protected static void startRecordTime(Activity activity) {
|
||||||
TimeoutHelper.recordTime(activity);
|
TimeoutHelper.recordTime(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,29 +63,36 @@ public abstract class LockingActivity extends StylishActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (PreferencesUtil.isLockDatabaseWhenScreenShutOffEnable(this)) {
|
if (PreferencesUtil.isLockDatabaseWhenScreenShutOffEnable(this)) {
|
||||||
screenReceiver = new ScreenReceiver();
|
lockReceiver = new LockReceiver();
|
||||||
registerReceiver(screenReceiver, new IntentFilter((Intent.ACTION_SCREEN_OFF)));
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
intentFilter.addAction(LOCK_ACTION);
|
||||||
|
registerReceiver(lockReceiver, new IntentFilter(intentFilter));
|
||||||
} else
|
} else
|
||||||
screenReceiver = null;
|
lockReceiver = null;
|
||||||
|
|
||||||
exitLock = false;
|
exitLock = false;
|
||||||
|
|
||||||
// WARNING TODO recordTime is not called after a back if was in backstack
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkShutdown(Activity act) {
|
public static void checkShutdown(Activity activity) {
|
||||||
if (App.isShutdown() && App.getDB().getLoaded()) {
|
if (App.isShutdown() && App.getDB().getLoaded()) {
|
||||||
Log.i(TAG, "Shutdown " + act.getLocalClassName() +
|
lockAndExit(activity);
|
||||||
" after inactivity or manual lock");
|
|
||||||
act.setResult(RESULT_EXIT_LOCK);
|
|
||||||
act.finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void lockAndExit() {
|
private static void lockAndExit(Activity activity) {
|
||||||
App.setShutdown();
|
App.setShutdown();
|
||||||
setResult(LockingActivity.RESULT_EXIT_LOCK);
|
Log.i(TAG, "Shutdown " + activity.getLocalClassName() +
|
||||||
finish();
|
" after inactivity or manual lock");
|
||||||
|
NotificationManager nm = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
if (nm != null)
|
||||||
|
nm.cancelAll();
|
||||||
|
activity.setResult(LockingActivity.RESULT_EXIT_LOCK);
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void lockAndExit() {
|
||||||
|
lockAndExit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,27 +126,25 @@ public abstract class LockingActivity extends StylishActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if(screenReceiver != null)
|
if(lockReceiver != null)
|
||||||
unregisterReceiver(screenReceiver);
|
unregisterReceiver(lockReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public class LockReceiver extends BroadcastReceiver {
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(AT_LEAST_SECOND_SHOWN_KEY, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ScreenReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
if(intent.getAction() != null) {
|
if(action != null) {
|
||||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
switch (action) {
|
||||||
if (PreferencesUtil.isLockDatabaseWhenScreenShutOffEnable(LockingActivity.this)) {
|
case Intent.ACTION_SCREEN_OFF:
|
||||||
App.setShutdown();
|
if (PreferencesUtil.isLockDatabaseWhenScreenShutOffEnable(LockingActivity.this)) {
|
||||||
checkShutdown(LockingActivity.this);
|
lockAndExit();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case LOCK_ACTION:
|
||||||
|
lockAndExit();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,15 +17,13 @@
|
|||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.activities;
|
package com.kunzisoft.keepass.lock;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.compat.BuildCompat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locking Hide Activity that sets FLAG_SECURE to prevent screenshots, and from
|
* Locking Hide Activity that sets FLAG_SECURE to prevent screenshots, and from
|
||||||
* appearing in the recent app preview
|
* appearing in the recent app preview
|
||||||
@@ -37,10 +35,7 @@ public abstract class LockingHideActivity extends LockingActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Several gingerbread devices have problems with FLAG_SECURE
|
// Several gingerbread devices have problems with FLAG_SECURE
|
||||||
int ver = BuildCompat.getSdkVersion();
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
if (ver >= BuildCompat.VERSION_CODE_ICE_CREAM_SANDWICH || ver < BuildCompat.VERSION_CODE_GINGERBREAD) {
|
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) Workaround for HTC Linkify issues
|
/* (non-Javadoc) Workaround for HTC Linkify issues
|
||||||
@@ -239,13 +239,11 @@ public class NotificationCopyingService extends Service {
|
|||||||
}
|
}
|
||||||
countingDownTask = null;
|
countingDownTask = null;
|
||||||
notificationManager.cancel(myNotificationId);
|
notificationManager.cancel(myNotificationId);
|
||||||
// Clean password only if no next field
|
try {
|
||||||
if (nextFields.size() <= 0)
|
clipboardHelper.cleanClipboard();
|
||||||
try {
|
} catch (SamsungClipboardException e) {
|
||||||
clipboardHelper.cleanClipboard();
|
Log.e(TAG, "Clipboard can't be cleaned", e);
|
||||||
} catch (SamsungClipboardException e) {
|
}
|
||||||
Log.e(TAG, "Clipboard can't be cleaned", e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
countingDownTask.start();
|
countingDownTask.start();
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,11 @@
|
|||||||
package com.kunzisoft.keepass.password;
|
package com.kunzisoft.keepass.password;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable;
|
import com.kunzisoft.keepass.database.action.AssignPasswordInDatabaseRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||||
@@ -61,21 +60,21 @@ public class AssignPasswordHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
|
public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
|
||||||
AssignPasswordInDBRunnable assignPasswordInDBRunnable = new AssignPasswordInDBRunnable(
|
AssignPasswordInDatabaseRunnable assignPasswordInDatabaseRunnable = new AssignPasswordInDatabaseRunnable(
|
||||||
context,
|
context,
|
||||||
App.getDB(),
|
App.getDB(),
|
||||||
masterPassword,
|
masterPassword,
|
||||||
keyfile,
|
keyfile,
|
||||||
new AfterSave(fileOnFinish, new Handler())
|
new AfterSave(fileOnFinish)
|
||||||
);
|
);
|
||||||
if (createProgressDialog) {
|
if (createProgressDialog) {
|
||||||
assignPasswordInDBRunnable.setUpdateProgressTaskStatus(
|
assignPasswordInDatabaseRunnable.setUpdateProgressTaskStatus(
|
||||||
new UpdateProgressTaskStatus(context,
|
new UpdateProgressTaskStatus(context,
|
||||||
SaveDatabaseProgressTaskDialogFragment.start(
|
SaveDatabaseProgressTaskDialogFragment.start(
|
||||||
context.getSupportFragmentManager())
|
context.getSupportFragmentManager())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Thread taskThread = new Thread(assignPasswordInDBRunnable);
|
Thread taskThread = new Thread(assignPasswordInDatabaseRunnable);
|
||||||
|
|
||||||
// Show the progress dialog now or after dialog confirmation
|
// Show the progress dialog now or after dialog confirmation
|
||||||
if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) {
|
if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) {
|
||||||
@@ -89,8 +88,8 @@ public class AssignPasswordHelper {
|
|||||||
private class AfterSave extends OnFinishRunnable {
|
private class AfterSave extends OnFinishRunnable {
|
||||||
private FileOnFinishRunnable mFinish;
|
private FileOnFinishRunnable mFinish;
|
||||||
|
|
||||||
AfterSave(FileOnFinishRunnable finish, Handler handler) {
|
AfterSave(FileOnFinishRunnable finish) {
|
||||||
super(finish, handler);
|
super(finish);
|
||||||
mFinish = finish;
|
mFinish = finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ package com.kunzisoft.keepass.password;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.assist.AssistStructure;
|
import android.app.assist.AssistStructure;
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -34,7 +36,6 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@@ -55,19 +56,18 @@ import com.getkeepsafe.taptargetview.TapTarget;
|
|||||||
import com.getkeepsafe.taptargetview.TapTargetView;
|
import com.getkeepsafe.taptargetview.TapTargetView;
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.activities.GroupActivity;
|
import com.kunzisoft.keepass.activities.GroupActivity;
|
||||||
import com.kunzisoft.keepass.activities.LockingActivity;
|
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||||
|
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||||
import com.kunzisoft.keepass.compat.BackupManagerCompat;
|
|
||||||
import com.kunzisoft.keepass.compat.ClipDataCompat;
|
import com.kunzisoft.keepass.compat.ClipDataCompat;
|
||||||
import com.kunzisoft.keepass.compat.EditorCompat;
|
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.database.action.LoadDBRunnable;
|
import com.kunzisoft.keepass.database.action.LoadDatabaseRunnable;
|
||||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||||
import com.kunzisoft.keepass.fileselect.KeyFileHelper;
|
import com.kunzisoft.keepass.fileselect.KeyFileHelper;
|
||||||
import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector;
|
import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector;
|
||||||
import com.kunzisoft.keepass.fingerprint.FingerPrintDialog;
|
import com.kunzisoft.keepass.fingerprint.FingerPrintExplanationDialog;
|
||||||
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
import com.kunzisoft.keepass.stylish.StylishActivity;
|
import com.kunzisoft.keepass.stylish.StylishActivity;
|
||||||
@@ -122,12 +122,14 @@ public class PasswordActivity extends StylishActivity
|
|||||||
private CompoundButton checkboxPasswordView;
|
private CompoundButton checkboxPasswordView;
|
||||||
private CompoundButton checkboxKeyfileView;
|
private CompoundButton checkboxKeyfileView;
|
||||||
private CompoundButton checkboxDefaultDatabaseView;
|
private CompoundButton checkboxDefaultDatabaseView;
|
||||||
|
private CompoundButton.OnCheckedChangeListener enableButtonOncheckedChangeListener;
|
||||||
|
|
||||||
private DefaultCheckChange defaultCheckChange;
|
private DefaultCheckChange defaultCheckChange;
|
||||||
private ValidateButtonViewClickListener validateButtonViewClickListener;
|
private ValidateButtonViewClickListener validateButtonViewClickListener;
|
||||||
|
|
||||||
private KeyFileHelper keyFileHelper;
|
private KeyFileHelper keyFileHelper;
|
||||||
|
|
||||||
|
protected boolean entrySelectionMode;
|
||||||
private AutofillHelper autofillHelper;
|
private AutofillHelper autofillHelper;
|
||||||
|
|
||||||
public static void launch(
|
public static void launch(
|
||||||
@@ -146,19 +148,39 @@ public class PasswordActivity extends StylishActivity
|
|||||||
intent.putExtra(UriIntentInitTask.KEY_FILENAME, fileName);
|
intent.putExtra(UriIntentInitTask.KEY_FILENAME, fileName);
|
||||||
intent.putExtra(UriIntentInitTask.KEY_KEYFILE, keyFile);
|
intent.putExtra(UriIntentInitTask.KEY_KEYFILE, keyFile);
|
||||||
// only to avoid visible flickering when redirecting
|
// only to avoid visible flickering when redirecting
|
||||||
act.startActivityForResult(intent, 0);
|
act.startActivityForResult(intent, RESULT_CANCELED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void launchForKeyboardResult(
|
||||||
|
Activity act,
|
||||||
|
String fileName) throws FileNotFoundException {
|
||||||
|
launchForKeyboardResult(act, fileName, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void launchForKeyboardResult(
|
||||||
|
Activity act,
|
||||||
|
String fileName,
|
||||||
|
String keyFile) throws FileNotFoundException {
|
||||||
|
verifyFileNameUriFromLaunch(fileName);
|
||||||
|
|
||||||
|
Intent intent = new Intent(act, PasswordActivity.class);
|
||||||
|
intent.putExtra(UriIntentInitTask.KEY_FILENAME, fileName);
|
||||||
|
intent.putExtra(UriIntentInitTask.KEY_KEYFILE, keyFile);
|
||||||
|
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
|
||||||
|
// only to avoid visible flickering when redirecting
|
||||||
|
act.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public static void launch(
|
public static void launchForAutofillResult(
|
||||||
Activity act,
|
Activity act,
|
||||||
String fileName,
|
String fileName,
|
||||||
AssistStructure assistStructure) throws FileNotFoundException {
|
AssistStructure assistStructure) throws FileNotFoundException {
|
||||||
launch(act, fileName, "", assistStructure);
|
launchForAutofillResult(act, fileName, "", assistStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public static void launch(
|
public static void launchForAutofillResult(
|
||||||
Activity act,
|
Activity act,
|
||||||
String fileName,
|
String fileName,
|
||||||
String keyFile,
|
String keyFile,
|
||||||
@@ -200,6 +222,8 @@ public class PasswordActivity extends StylishActivity
|
|||||||
Intent data) {
|
Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
// To get entry in result
|
||||||
|
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
@@ -296,6 +320,8 @@ public class PasswordActivity extends StylishActivity
|
|||||||
fingerprintImageView);
|
fingerprintImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
autofillHelper = new AutofillHelper();
|
autofillHelper = new AutofillHelper();
|
||||||
autofillHelper.retrieveAssistStructure(getIntent());
|
autofillHelper.retrieveAssistStructure(getIntent());
|
||||||
@@ -323,6 +349,18 @@ public class PasswordActivity extends StylishActivity
|
|||||||
// For check shutdown
|
// For check shutdown
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
// Enable or not the open button
|
||||||
|
if (!PreferencesUtil.emptyPasswordAllowed(PasswordActivity.this)) {
|
||||||
|
confirmButtonView.setEnabled(checkboxPasswordView.isChecked());
|
||||||
|
} else {
|
||||||
|
confirmButtonView.setEnabled(true);
|
||||||
|
}
|
||||||
|
enableButtonOncheckedChangeListener = (buttonView, isChecked) -> {
|
||||||
|
if (!PreferencesUtil.emptyPasswordAllowed(PasswordActivity.this)) {
|
||||||
|
confirmButtonView.setEnabled(isChecked);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
||||||
// and the activity still active)
|
// and the activity still active)
|
||||||
@@ -334,6 +372,8 @@ public class PasswordActivity extends StylishActivity
|
|||||||
if (fingerPrintAnimatedVector != null) {
|
if (fingerPrintAnimatedVector != null) {
|
||||||
fingerPrintAnimatedVector.startScan();
|
fingerPrintAnimatedVector.startScan();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
checkboxPasswordView.setOnCheckedChangeListener(enableButtonOncheckedChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
new UriIntentInitTask(this, mRememberKeyfile)
|
new UriIntentInitTask(this, mRememberKeyfile)
|
||||||
@@ -345,34 +385,37 @@ public class PasswordActivity extends StylishActivity
|
|||||||
* Displays the explanation for a database opening with fingerprints if available
|
* Displays the explanation for a database opening with fingerprints if available
|
||||||
*/
|
*/
|
||||||
private void checkAndPerformedEducation() {
|
private void checkAndPerformedEducation() {
|
||||||
if (!PreferencesUtil.isEducationUnlockPerformed(this)) {
|
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||||
|
|
||||||
TapTargetView.showFor(this,
|
if (!PreferencesUtil.isEducationUnlockPerformed(this)) {
|
||||||
TapTarget.forView(findViewById(R.id.password_input_container),
|
|
||||||
getString(R.string.education_unlock_title),
|
|
||||||
getString(R.string.education_unlock_summary))
|
|
||||||
.dimColor(R.color.green)
|
|
||||||
.icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round))
|
|
||||||
.textColorInt(Color.WHITE)
|
|
||||||
.tintTarget(false)
|
|
||||||
.cancelable(true),
|
|
||||||
new TapTargetView.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onTargetClick(TapTargetView view) {
|
|
||||||
super.onTargetClick(view);
|
|
||||||
checkAndPerformedEducationForFingerprint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
TapTargetView.showFor(this,
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
TapTarget.forView(findViewById(R.id.password_input_container),
|
||||||
super.onOuterCircleClick(view);
|
getString(R.string.education_unlock_title),
|
||||||
view.dismiss(false);
|
getString(R.string.education_unlock_summary))
|
||||||
checkAndPerformedEducationForFingerprint();
|
.dimColor(R.color.green)
|
||||||
|
.icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(false)
|
||||||
|
.cancelable(true),
|
||||||
|
new TapTargetView.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTargetClick(TapTargetView view) {
|
||||||
|
super.onTargetClick(view);
|
||||||
|
checkAndPerformedEducationForFingerprint();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
});
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
// TODO make a period for donation
|
super.onOuterCircleClick(view);
|
||||||
PreferencesUtil.saveEducationPreference(PasswordActivity.this, R.string.education_unlock_key);
|
view.dismiss(false);
|
||||||
|
checkAndPerformedEducationForFingerprint();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// TODO make a period for donation
|
||||||
|
PreferencesUtil.saveEducationPreference(PasswordActivity.this, R.string.education_unlock_key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,14 +424,18 @@ public class PasswordActivity extends StylishActivity
|
|||||||
* Displays fingerprints if available
|
* Displays fingerprints if available
|
||||||
*/
|
*/
|
||||||
private void checkAndPerformedEducationForFingerprint() {
|
private void checkAndPerformedEducationForFingerprint() {
|
||||||
if (PreferencesUtil.isFingerprintEnable(getApplicationContext())) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
TapTargetView.showFor(this,
|
|
||||||
TapTarget.forView(fingerprintImageView,
|
if ( PreferencesUtil.isFingerprintEnable(getApplicationContext())
|
||||||
getString(R.string.education_fingerprint_title),
|
&& FingerPrintHelper.isFingerprintSupported(getSystemService(FingerprintManager.class))) {
|
||||||
getString(R.string.education_fingerprint_summary))
|
|
||||||
.textColorInt(Color.WHITE)
|
TapTargetView.showFor(this,
|
||||||
.tintTarget(false)
|
TapTarget.forView(fingerprintImageView,
|
||||||
.cancelable(true),
|
getString(R.string.education_fingerprint_title),
|
||||||
|
getString(R.string.education_fingerprint_summary))
|
||||||
|
.textColorInt(Color.WHITE)
|
||||||
|
.tintTarget(false)
|
||||||
|
.cancelable(true),
|
||||||
new TapTargetView.Listener() {
|
new TapTargetView.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onOuterCircleClick(TapTargetView view) {
|
public void onOuterCircleClick(TapTargetView view) {
|
||||||
@@ -396,6 +443,7 @@ public class PasswordActivity extends StylishActivity
|
|||||||
view.dismiss(false);
|
view.dismiss(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,10 +560,14 @@ public class PasswordActivity extends StylishActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add old listener to enable the button, only be call here because of onCheckedChange bug
|
||||||
|
if (enableButtonOncheckedChangeListener != null)
|
||||||
|
enableButtonOncheckedChangeListener.onCheckedChanged(compoundButton, checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
// callback for fingerprint findings
|
// callback for fingerprint findings
|
||||||
fingerPrintHelper.setAuthenticationCallback(new FingerprintManagerCompat.AuthenticationCallback() {
|
fingerPrintHelper.setAuthenticationCallback(new FingerprintManager.AuthenticationCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationError(
|
public void onAuthenticationError(
|
||||||
final int errorCode,
|
final int errorCode,
|
||||||
@@ -547,7 +599,7 @@ public class PasswordActivity extends StylishActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationSucceeded(final FingerprintManagerCompat.AuthenticationResult result) {
|
public void onAuthenticationSucceeded(final FingerprintManager.AuthenticationResult result) {
|
||||||
switch (fingerPrintMode) {
|
switch (fingerPrintMode) {
|
||||||
case STORE_MODE:
|
case STORE_MODE:
|
||||||
// newly store the entered password in encrypted way
|
// newly store the entered password in encrypted way
|
||||||
@@ -678,14 +730,14 @@ public class PasswordActivity extends StylishActivity
|
|||||||
// fingerprint not supported (by API level or hardware) so keep option hidden
|
// fingerprint not supported (by API level or hardware) so keep option hidden
|
||||||
// or manually disable
|
// or manually disable
|
||||||
if (!PreferencesUtil .isFingerprintEnable(getApplicationContext())
|
if (!PreferencesUtil .isFingerprintEnable(getApplicationContext())
|
||||||
|| !FingerPrintHelper.isFingerprintSupported(FingerprintManagerCompat.from(this))) {
|
|| !FingerPrintHelper.isFingerprintSupported(getSystemService(FingerprintManager.class))) {
|
||||||
setFingerPrintVisibility(View.GONE);
|
setFingerPrintVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
// fingerprint is available but not configured show icon but in disabled state with some information
|
// fingerprint is available but not configured show icon but in disabled state with some information
|
||||||
else {
|
else {
|
||||||
// show explanations
|
// show explanations
|
||||||
fingerprintContainerView.setOnClickListener(view -> {
|
fingerprintContainerView.setOnClickListener(view -> {
|
||||||
FingerPrintDialog fingerPrintDialog = new FingerPrintDialog();
|
FingerPrintExplanationDialog fingerPrintDialog = new FingerPrintExplanationDialog();
|
||||||
fingerPrintDialog.show(getSupportFragmentManager(), "fingerprintDialog");
|
fingerPrintDialog.show(getSupportFragmentManager(), "fingerprintDialog");
|
||||||
});
|
});
|
||||||
setFingerPrintVisibility(View.VISIBLE);
|
setFingerPrintVisibility(View.VISIBLE);
|
||||||
@@ -790,9 +842,9 @@ public class PasswordActivity extends StylishActivity
|
|||||||
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(KEY_DEFAULT_FILENAME, newDefaultFileName);
|
editor.putString(KEY_DEFAULT_FILENAME, newDefaultFileName);
|
||||||
EditorCompat.apply(editor);
|
editor.apply();
|
||||||
|
|
||||||
BackupManagerCompat backupManager = new BackupManagerCompat(PasswordActivity.this);
|
BackupManager backupManager = new BackupManager(PasswordActivity.this);
|
||||||
backupManager.dataChanged();
|
backupManager.dataChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -838,9 +890,9 @@ public class PasswordActivity extends StylishActivity
|
|||||||
// Show the progress dialog
|
// Show the progress dialog
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database);
|
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database);
|
||||||
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(
|
LoadDatabaseRunnable databaseLoadingTask = new LoadDatabaseRunnable(
|
||||||
database,
|
|
||||||
PasswordActivity.this,
|
PasswordActivity.this,
|
||||||
|
database,
|
||||||
mDbUri,
|
mDbUri,
|
||||||
password,
|
password,
|
||||||
keyfile,
|
keyfile,
|
||||||
@@ -852,8 +904,7 @@ public class PasswordActivity extends StylishActivity
|
|||||||
getSupportFragmentManager(),
|
getSupportFragmentManager(),
|
||||||
R.string.loading_database)
|
R.string.loading_database)
|
||||||
));
|
));
|
||||||
Thread t = new Thread(databaseLoadingTask);
|
new Thread(databaseLoadingTask).start();
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -902,11 +953,15 @@ public class PasswordActivity extends StylishActivity
|
|||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
assistStructure = autofillHelper.getAssistStructure();
|
assistStructure = autofillHelper.getAssistStructure();
|
||||||
if (assistStructure != null) {
|
if (assistStructure != null) {
|
||||||
GroupActivity.launch(PasswordActivity.this, assistStructure);
|
GroupActivity.launchForAutofillResult(PasswordActivity.this, assistStructure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (assistStructure == null) {
|
if (assistStructure == null) {
|
||||||
GroupActivity.launch(PasswordActivity.this);
|
if (entrySelectionMode) {
|
||||||
|
GroupActivity.launchForKeyboardResult(PasswordActivity.this);
|
||||||
|
} else {
|
||||||
|
GroupActivity.launch(PasswordActivity.this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.search;
|
|||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -36,9 +35,9 @@ import com.kunzisoft.keepass.database.Database;
|
|||||||
import com.kunzisoft.keepass.database.PwGroup;
|
import com.kunzisoft.keepass.database.PwGroup;
|
||||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||||
|
|
||||||
public class SearchResultsActivity extends ListNodesActivity {
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
private RecyclerView listView;
|
public class SearchResultsActivity extends ListNodesActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -52,23 +51,24 @@ public class SearchResultsActivity extends ListNodesActivity {
|
|||||||
assert getSupportActionBar() != null;
|
assert getSupportActionBar() != null;
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||||
|
groupNameView = findViewById(R.id.group_name);
|
||||||
|
|
||||||
|
attachFragmentToContentView();
|
||||||
|
|
||||||
listView = findViewById(R.id.nodes_list);
|
|
||||||
View notFoundView = findViewById(R.id.not_found_container);
|
View notFoundView = findViewById(R.id.not_found_container);
|
||||||
|
View listContainer = findViewById(R.id.nodes_list_fragment_container);
|
||||||
|
|
||||||
if ( mCurrentGroup == null || mCurrentGroup.numbersOfChildEntries() < 1 ) {
|
if ( mCurrentGroup == null || mCurrentGroup.numbersOfChildEntries() < 1 ) {
|
||||||
listView.setVisibility(View.GONE);
|
listContainer.setVisibility(View.GONE);
|
||||||
notFoundView.setVisibility(View.VISIBLE);
|
notFoundView.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
listView.setVisibility(View.VISIBLE);
|
listContainer.setVisibility(View.VISIBLE);
|
||||||
notFoundView.setVisibility(View.GONE);
|
notFoundView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
setGroupTitle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PwGroup initCurrentGroup() {
|
protected PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState) {
|
||||||
Database mDb = App.getDB();
|
Database mDb = App.getDB();
|
||||||
// Likely the app has been killed exit the activity
|
// Likely the app has been killed exit the activity
|
||||||
if ( ! mDb.getLoaded() ) {
|
if ( ! mDb.getLoaded() ) {
|
||||||
@@ -77,17 +77,11 @@ public class SearchResultsActivity extends ListNodesActivity {
|
|||||||
return mDb.search(getSearchStr(getIntent()).trim());
|
return mDb.search(getSearchStr(getIntent()).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected RecyclerView defineNodeList() {
|
|
||||||
return listView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
MenuUtil.contributionMenuInflater(inflater, menu);
|
MenuUtil.contributionMenuInflater(inflater, menu);
|
||||||
inflater.inflate(R.menu.tree, menu);
|
|
||||||
inflater.inflate(R.menu.default_menu, menu);
|
inflater.inflate(R.menu.default_menu, menu);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.selection;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.fileselect.FileSelectActivity;
|
||||||
|
|
||||||
|
public class EntrySelectionAuthActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
startFileSelectActivity();
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startFileSelectActivity() {
|
||||||
|
// Pass extra to get entry
|
||||||
|
FileSelectActivity.launchForKeyboardResult(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.kunzisoft.keepass.selection;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.database.PwEntry;
|
||||||
|
import com.kunzisoft.keepass_model.Entry;
|
||||||
|
|
||||||
|
public class EntrySelectionHelper {
|
||||||
|
|
||||||
|
public static final int ENTRY_SELECTION_RESPONSE_REQUEST_CODE = 5164;
|
||||||
|
|
||||||
|
public static final String EXTRA_ENTRY_SELECTION_MODE = "com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE";
|
||||||
|
|
||||||
|
public static void addEntrySelectionModeExtraInIntent(Intent intent) {
|
||||||
|
intent.putExtra(EXTRA_ENTRY_SELECTION_MODE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isIntentInEntrySelectionMode(Intent intent) {
|
||||||
|
return intent.getBooleanExtra(EXTRA_ENTRY_SELECTION_MODE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to hit when right key is selected
|
||||||
|
*/
|
||||||
|
public static void buildResponseWhenEntrySelected(Activity activity, PwEntry entry) {
|
||||||
|
Intent mReplyIntent;
|
||||||
|
Intent intent = activity.getIntent();
|
||||||
|
boolean entrySelectionMode = isIntentInEntrySelectionMode(intent);
|
||||||
|
if (entrySelectionMode) {
|
||||||
|
mReplyIntent = new Intent();
|
||||||
|
Log.d(activity.getClass().getName(), "Reply entry selection");
|
||||||
|
|
||||||
|
Entry entryModel = new Entry();
|
||||||
|
entryModel.setTitle(entry.getTitle());
|
||||||
|
entryModel.setUsername(entry.getUsername());
|
||||||
|
entryModel.setPassword(entry.getPassword());
|
||||||
|
entryModel.setUrl(entry.getUrl());
|
||||||
|
// TODO Fields
|
||||||
|
if (entry.containsCustomFields()) {
|
||||||
|
//entryModel.setCustomField(entry.getFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
mReplyIntent.putExtra(
|
||||||
|
EXTRA_ENTRY_SELECTION_MODE,
|
||||||
|
entryModel);
|
||||||
|
activity.setResult(Activity.RESULT_OK, mReplyIntent);
|
||||||
|
} else {
|
||||||
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to loop and close each activity with return data
|
||||||
|
*/
|
||||||
|
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == ENTRY_SELECTION_RESPONSE_REQUEST_CODE) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
activity.setResult(resultCode, data);
|
||||||
|
}
|
||||||
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
|
}
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,15 +21,12 @@ package com.kunzisoft.keepass.settings;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsFixPreferenceDialogFragmentCompat;
|
|
||||||
import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
|
|
||||||
|
|
||||||
public class MainPreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
|
public class MainPreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
|
||||||
|
|
||||||
@@ -68,21 +65,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisplayPreferenceDialog(Preference preference) {
|
|
||||||
// Try if the preference is one of our custom Preferences
|
|
||||||
if (preference instanceof InputNumberPreference) {
|
|
||||||
assert getFragmentManager() != null;
|
|
||||||
DialogFragment dialogFragment = RoundsFixPreferenceDialogFragmentCompat.newInstance(preference.getKey());
|
|
||||||
dialogFragment.setTargetFragment(this, 0);
|
|
||||||
dialogFragment.show(getFragmentManager(), null);
|
|
||||||
}
|
|
||||||
// Could not be handled here. Try with the super method.
|
|
||||||
else {
|
|
||||||
super.onDisplayPreferenceDialog(preference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
// here you should use the same keys as you used in the xml-file
|
// here you should use the same keys as you used in the xml-file
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -32,7 +33,6 @@ import android.support.annotation.RequiresApi;
|
|||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
@@ -46,19 +46,20 @@ import com.kunzisoft.keepass.R;
|
|||||||
import com.kunzisoft.keepass.app.App;
|
import com.kunzisoft.keepass.app.App;
|
||||||
import com.kunzisoft.keepass.database.Database;
|
import com.kunzisoft.keepass.database.Database;
|
||||||
import com.kunzisoft.keepass.dialogs.ProFeatureDialogFragment;
|
import com.kunzisoft.keepass.dialogs.ProFeatureDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.StorageAccessFrameworkDialog;
|
|
||||||
import com.kunzisoft.keepass.dialogs.UnavailableFeatureDialogFragment;
|
import com.kunzisoft.keepass.dialogs.UnavailableFeatureDialogFragment;
|
||||||
import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment;
|
import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment;
|
||||||
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
||||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.keyboard.KeyboardExplanationDialog;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseDescriptionPreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseDescriptionPreferenceDialogFragmentCompat;
|
||||||
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseKeyDerivationPreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseKeyDerivationPreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseNamePreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseNamePreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.MemoryUsagePreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.MemoryUsagePreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.ParallelismPreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.ParallelismPreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsPreferenceDialogFragmentCompat;
|
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsPreferenceDialogFragmentCompat;
|
||||||
import com.kunzisoft.keepass.stylish.Stylish;
|
import com.kunzisoft.keepass.stylish.Stylish;
|
||||||
|
import com.kunzisoft.magikeyboard.settings.MagikIMESettings;
|
||||||
|
|
||||||
public class NestedSettingsFragment extends PreferenceFragmentCompat
|
public class NestedSettingsFragment extends PreferenceFragmentCompat
|
||||||
implements Preference.OnPreferenceClickListener {
|
implements Preference.OnPreferenceClickListener {
|
||||||
@@ -114,6 +115,8 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
|||||||
case APPLICATION:
|
case APPLICATION:
|
||||||
setPreferencesFromResource(R.xml.application_preferences, rootKey);
|
setPreferencesFromResource(R.xml.application_preferences, rootKey);
|
||||||
|
|
||||||
|
allowCopyPassword();
|
||||||
|
|
||||||
Preference keyFile = findPreference(getString(R.string.keyfile_key));
|
Preference keyFile = findPreference(getString(R.string.keyfile_key));
|
||||||
keyFile.setOnPreferenceChangeListener((preference, newValue) -> {
|
keyFile.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
Boolean value = (Boolean) newValue;
|
Boolean value = (Boolean) newValue;
|
||||||
@@ -139,17 +142,18 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
|||||||
storageAccessFramework.setOnPreferenceChangeListener((preference, newValue) -> {
|
storageAccessFramework.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
Boolean value = (Boolean) newValue;
|
Boolean value = (Boolean) newValue;
|
||||||
if (!value && getContext() != null) {
|
if (!value && getContext() != null) {
|
||||||
StorageAccessFrameworkDialog safDialog = new StorageAccessFrameworkDialog(getContext());
|
AlertDialog alertDialog = new AlertDialog.Builder(getContext())
|
||||||
safDialog.setButton(AlertDialog.BUTTON1, getText(android.R.string.ok),
|
.setMessage(getString(R.string.warning_disabling_storage_access_framework)).create();
|
||||||
|
alertDialog.setButton(AlertDialog.BUTTON1, getText(android.R.string.ok),
|
||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
safDialog.setButton(AlertDialog.BUTTON2, getText(android.R.string.cancel),
|
alertDialog.setButton(AlertDialog.BUTTON2, getText(android.R.string.cancel),
|
||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
storageAccessFramework.setChecked(true);
|
storageAccessFramework.setChecked(true);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
safDialog.show();
|
alertDialog.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -158,9 +162,10 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
|||||||
(SwitchPreference) findPreference(getString(R.string.fingerprint_enable_key));
|
(SwitchPreference) findPreference(getString(R.string.fingerprint_enable_key));
|
||||||
// < M solve verifyError exception
|
// < M solve verifyError exception
|
||||||
boolean fingerprintSupported = false;
|
boolean fingerprintSupported = false;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||||
|
&& getActivity() != null)
|
||||||
fingerprintSupported = FingerPrintHelper.isFingerprintSupported(
|
fingerprintSupported = FingerPrintHelper.isFingerprintSupported(
|
||||||
FingerprintManagerCompat.from(getContext()));
|
getActivity().getSystemService(FingerprintManager.class));
|
||||||
if (!fingerprintSupported) {
|
if (!fingerprintSupported) {
|
||||||
// False if under Marshmallow
|
// False if under Marshmallow
|
||||||
fingerprintEnablePreference.setChecked(false);
|
fingerprintEnablePreference.setChecked(false);
|
||||||
@@ -277,8 +282,24 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchPreference keyboardPreference = (SwitchPreference) findPreference(getString(R.string.magic_keyboard_key));
|
Preference keyboardPreference = findPreference(getString(R.string.magic_keyboard_key));
|
||||||
preferenceInDevelopment(keyboardPreference);
|
keyboardPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
if (getFragmentManager() != null) {
|
||||||
|
KeyboardExplanationDialog fingerPrintDialog = new KeyboardExplanationDialog();
|
||||||
|
fingerPrintDialog.show(getFragmentManager(), "keyboardExplanationDialog");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Preference keyboardSubPreference = findPreference(getString(R.string.magic_keyboard_preference_key));
|
||||||
|
keyboardSubPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
Intent intentKeyboard = new Intent(getContext(), MagikIMESettings.class);
|
||||||
|
startActivity(intentKeyboard);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Present in two places
|
||||||
|
allowCopyPassword();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -410,6 +431,28 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void allowCopyPassword() {
|
||||||
|
SwitchPreference copyPasswordPreference = (SwitchPreference) findPreference(getString(R.string.allow_copy_password_key));
|
||||||
|
copyPasswordPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
if ((Boolean) newValue && getContext() != null) {
|
||||||
|
String message = getString(R.string.allow_copy_password_warning) +
|
||||||
|
"\n\n" +
|
||||||
|
getString(R.string.clipboard_warning);
|
||||||
|
AlertDialog warningDialog = new AlertDialog.Builder(getContext())
|
||||||
|
.setMessage(message).create();
|
||||||
|
warningDialog.setButton(AlertDialog.BUTTON1, getText(android.R.string.ok),
|
||||||
|
(dialog, which) -> dialog.dismiss());
|
||||||
|
warningDialog.setButton(AlertDialog.BUTTON2, getText(android.R.string.cancel),
|
||||||
|
(dialog, which) -> {
|
||||||
|
copyPasswordPreference.setChecked(false);
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
warningDialog.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void preferenceInDevelopment(Preference preferenceInDev) {
|
private void preferenceInDevelopment(Preference preferenceInDev) {
|
||||||
preferenceInDev.setOnPreferenceClickListener(preference -> {
|
preferenceInDev.setOnPreferenceClickListener(preference -> {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class PreferencesUtil {
|
|||||||
ctx.getResources().getBoolean(R.bool.auto_open_file_uri_default));
|
ctx.getResources().getBoolean(R.bool.auto_open_file_uri_default));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean allowCopyPassword(Context ctx) {
|
public static boolean allowCopyPasswordAndProtectedFields(Context ctx) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
return prefs.getBoolean(ctx.getString(R.string.allow_copy_password_key),
|
return prefs.getBoolean(ctx.getString(R.string.allow_copy_password_key),
|
||||||
ctx.getResources().getBoolean(R.bool.allow_copy_password_default));
|
ctx.getResources().getBoolean(R.bool.allow_copy_password_default));
|
||||||
@@ -152,6 +152,12 @@ public class PreferencesUtil {
|
|||||||
context.getString(R.string.setting_icon_pack_choose_default));
|
context.getString(R.string.setting_icon_pack_choose_default));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean emptyPasswordAllowed(Context context) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return prefs.getBoolean(context.getString(R.string.allow_no_password_key),
|
||||||
|
context.getResources().getBoolean(R.bool.allow_no_password_default));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All preference keys associated with education
|
* All preference keys associated with education
|
||||||
*/
|
*/
|
||||||
@@ -170,6 +176,12 @@ public class PreferencesUtil {
|
|||||||
R.string.education_entry_new_field_key
|
R.string.education_entry_new_field_key
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static boolean isEducationScreensEnabled(Context context) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return sharedPreferences.getBoolean(context.getString(R.string.enable_education_screens_key),
|
||||||
|
context.getResources().getBoolean(R.bool.enable_education_screens_default));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register education preferences as true in EDUCATION_PREFERENCE SharedPreferences
|
* Register education preferences as true in EDUCATION_PREFERENCE SharedPreferences
|
||||||
*
|
*
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user