Skip to content

Commit

Permalink
Merge branch 'release/1.0.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
Foboz committed Mar 6, 2020
2 parents 2352e8d + 61fc127 commit 5f0f0bb
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Release 1.0.11 (20030501)

- Minor improvements

### Release 1.0.10 (20021301)

- Stability improvements
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'org.jetbrains.kotlin.android.extensions'

int MAJOR_VERSION = 1
int MINOR_VERSION = 0
int MICRO_VERSION = 10
int MICRO_VERSION = 11
int BUILD_FOR_TODAY = 1

def secretsPropertiesFile = rootProject.file("secrets.properties")
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<uses-permission android:name="android.permission.USE_BIOMETRIC" />

<permission
android:name="com.myetherwallet.mewconnect.ACCESS_SECRET_DATA"
android:protectionLevel="signature" />
android:name="com.myetherwallet.mewconnect.ACCESS_DANGEROUS_DATA"
android:description="@string/import_permission_description"
android:icon="@drawable/notification_icon"
android:label="@string/import_permission_label"
android:protectionLevel="dangerous" />

<application
android:name=".MewApplication"
Expand Down Expand Up @@ -65,10 +68,16 @@
android:exported="false" />

<provider
android:name=".content.provider.MewContentProvider"
android:name=".content.provider.MewInfoContentProvider"
android:authorities="com.myetherwallet.mewconnect.info"
android:enabled="true"
android:exported="true" />

<provider
android:name=".content.provider.MewSecretContentProvider"
android:authorities="com.myetherwallet.mewconnect.secret"
android:enabled="true"
android:exported="true"
android:permission="com.myetherwallet.mewconnect.ACCESS_SECRET_DATA" />
android:permission="com.myetherwallet.mewconnect.ACCESS_DANGEROUS_DATA" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.myetherwallet.mewconnect.content.provider

import android.content.ContentProvider
import android.database.Cursor
import android.database.MatrixCursor

/**
* Created by BArtWell on 27.02.2020.
*/

abstract class BaseMewContentProvider : ContentProvider() {

protected fun <T> createOneItemCursor(data: T): Cursor {
val cursor = MatrixCursor(arrayOf("_id", "data"))
cursor.newRow()
.add(0)
.add(data)
return cursor
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.myetherwallet.mewconnect.content.provider

import android.content.ContentValues
import android.content.UriMatcher
import android.database.Cursor
import android.net.Uri
import com.myetherwallet.mewconnect.BuildConfig
import com.myetherwallet.mewconnect.MewApplication
import com.myetherwallet.mewconnect.core.persist.prefenreces.PreferencesManager
import com.myetherwallet.mewconnect.core.utils.MewLog
import javax.inject.Inject

private const val TAG = "MewContentProvider"
private const val AUTHORITY = "com.myetherwallet.mewconnect.info"
private const val PATH_VERSION = "version"
private const val ID_VERSION = 0
private const val PATH_IS_WALLET_AVAILABLE = "is_wallet_available"
private const val ID_IS_AVAILABLE = 1

class MewInfoContentProvider : BaseMewContentProvider() {

@Inject
lateinit var preferences: PreferencesManager
private val uriMatcher = UriMatcher(UriMatcher.NO_MATCH)

override fun onCreate(): Boolean {
MewLog.d(TAG, "onCreate")
(context?.applicationContext as MewApplication?)?.appComponent?.inject(this)
uriMatcher.addURI(AUTHORITY, PATH_VERSION, ID_VERSION)
uriMatcher.addURI(AUTHORITY, PATH_IS_WALLET_AVAILABLE, ID_IS_AVAILABLE)
return true
}

override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor? {
MewLog.d(TAG, "query")
when (uriMatcher.match(uri)) {
ID_VERSION -> {
MewLog.d(TAG, "Version")
return createOneItemCursor(BuildConfig.VERSION_CODE)
}
ID_IS_AVAILABLE -> {
MewLog.d(TAG, "Is wallet available")
val data = if (preferences.getCurrentWalletPreferences().isWalletExists() &&
!preferences.applicationPreferences.wasExportedToMewWallet() &&
!preferences.applicationPreferences.isExportToMewWalletDenied()) {
1
} else {
0
}
return createOneItemCursor(data)
}
}
return null
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
return 0
}

override fun getType(uri: Uri): String? {
return null
}

override fun insert(uri: Uri, values: ContentValues?): Uri? {
return null
}

override fun update(uri: Uri, values: ContentValues?, selection: String?,
selectionArgs: Array<String>?): Int {
return 0
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.myetherwallet.mewconnect.content.provider

import android.content.ContentProvider
import android.content.ContentValues
import android.content.UriMatcher
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import com.myetherwallet.mewconnect.BuildConfig
import com.myetherwallet.mewconnect.MewApplication
import com.myetherwallet.mewconnect.core.persist.prefenreces.KeyStore
import com.myetherwallet.mewconnect.core.persist.prefenreces.PreferencesManager
Expand All @@ -16,13 +13,11 @@ import javax.inject.Inject

private const val TAG = "MewContentProvider"
private const val AUTHORITY = "com.myetherwallet.mewconnect.secret"
private const val PATH_VERSION = "version"
private const val ID_VERSION = 0
private const val PATH_GET_MNEMONIC = "mnemonic"
private const val ID_MNEMONIC = 1
private const val ID_MNEMONIC = 0
private const val QUERY_PASSWORD = "password"

class MewContentProvider : ContentProvider() {
class MewSecretContentProvider : BaseMewContentProvider() {

@Inject
lateinit var preferences: PreferencesManager
Expand All @@ -31,41 +26,34 @@ class MewContentProvider : ContentProvider() {
override fun onCreate(): Boolean {
MewLog.d(TAG, "onCreate")
(context?.applicationContext as MewApplication?)?.appComponent?.inject(this)
uriMatcher.addURI(AUTHORITY, PATH_VERSION, ID_VERSION)
uriMatcher.addURI(AUTHORITY, PATH_GET_MNEMONIC, ID_MNEMONIC)
return true
}

override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor? {
MewLog.d(TAG, "query")
when (uriMatcher.match(uri)) {
ID_VERSION -> {
MewLog.d(TAG, "Version")
return createOneItemCursor(BuildConfig.VERSION_CODE)
}
ID_MNEMONIC -> {
MewLog.d(TAG, "Mnemonic")
val password = uri.getQueryParameter(QUERY_PASSWORD)
if (!password.isNullOrEmpty()) {
val keystoreHelper = PasswordKeystoreHelper(password)
val mnemonic = keystoreHelper.decrypt(preferences.applicationPreferences.getWalletMnemonic(KeyStore.PASSWORD))
if (mnemonic.isNotEmpty()) {
return createOneItemCursor(mnemonic)
if (!preferences.applicationPreferences.wasExportedToMewWallet() &&
!preferences.applicationPreferences.isExportToMewWalletDenied()) {
val password = uri.getQueryParameter(QUERY_PASSWORD)
if (!password.isNullOrEmpty()) {
val keystoreHelper = PasswordKeystoreHelper(password)
val mnemonic = keystoreHelper.decrypt(preferences.applicationPreferences.getWalletMnemonic(KeyStore.PASSWORD))
if (mnemonic.isEmpty()) {
preferences.applicationPreferences.updateExportToMewWalletDenied()
} else {
preferences.applicationPreferences.setWasExportedToMewWallet(true)
return createOneItemCursor(mnemonic)
}
}
}
}
}
return null
}

private fun <T> createOneItemCursor(data: T): Cursor {
val cursor = MatrixCursor(arrayOf("_id", "data"))
cursor.newRow()
.add(0)
.add(data)
return cursor
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
return 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.myetherwallet.mewconnect.core.di

import com.myetherwallet.mewconnect.MewApplication
import com.myetherwallet.mewconnect.content.provider.MewContentProvider
import com.myetherwallet.mewconnect.content.provider.MewInfoContentProvider
import com.myetherwallet.mewconnect.content.provider.MewSecretContentProvider
import com.myetherwallet.mewconnect.core.di.viewmodel.ViewModelModule
import com.myetherwallet.mewconnect.core.persist.database.DatabaseModule
import com.myetherwallet.mewconnect.core.persist.prefenreces.PreferencesModule
Expand Down Expand Up @@ -97,5 +98,7 @@ interface ApplicationComponent {

fun inject(view: StaticToolbar)

fun inject(provider: MewContentProvider)
fun inject(provider: MewSecretContentProvider)

fun inject(provider: MewInfoContentProvider)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private const val AUTH_TIMER_TIME = "auth_timer_time"
private const val WHATS_NEW_DIALOG_VERSION = "whats_new_dialog_version"
private const val IS_BIOMETRIC_PROMO_SHOWN = "is_biometric_promo_shown"
private const val SIMPLEX_USER_ID = "simplex_user_id"
private const val WAS_EXPORTED_TO_MEW_WALLET = "was_exported_to_mew_wallet"
private const val EXPORT_TO_MEW_WALLET_DENIED_COUNT = "export_to_mew_wallet_denied_count"

private const val DEPRECATED_WALLET_MNEMONIC = "wallet_mnemonic"

Expand Down Expand Up @@ -141,6 +143,18 @@ class ApplicationPreferences(context: Context, private val preferences: SharedPr

fun resetAuthTimerTime() = preferences.edit().remove(AUTH_TIMER_TIME).apply()

fun wasExportedToMewWallet() = preferences.getBoolean(WAS_EXPORTED_TO_MEW_WALLET, false)

fun setWasExportedToMewWallet(was: Boolean) = preferences.edit().putBoolean(WAS_EXPORTED_TO_MEW_WALLET, was).apply()

fun isExportToMewWalletDenied() = getExportToMewWalletDeniedCount() > 20

private fun getExportToMewWalletDeniedCount() = preferences.getInt(EXPORT_TO_MEW_WALLET_DENIED_COUNT, 0)

fun updateExportToMewWalletDenied() {
preferences.edit().putInt(EXPORT_TO_MEW_WALLET_DENIED_COUNT, getExportToMewWalletDeniedCount() + 1).apply()
}

fun shouldShowWhatsNewDialog(): Boolean {
val current = preferences.getInt(WHATS_NEW_DIALOG_VERSION, 0)
preferences.edit().putInt(WHATS_NEW_DIALOG_VERSION, BuildConfig.VERSION_CODE).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class GeneratingFragment : BaseViewModelFragment() {
override fun inject(appComponent: ApplicationComponent) {
appComponent.inject(this)
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,7 @@
<string name="fingerprint_enabled_title" comment="Fingerprint enabled screen - title">Fingerprint unlock is now enabled</string>

<string name="whats_new_title" comment="'What's new' screen - title">What’s new</string>

<string name="import_permission_label">Import wallet data</string>
<string name="import_permission_description">to import your account from MEWconnect app</string>
</resources>

0 comments on commit 5f0f0bb

Please sign in to comment.