Skip to content

Commit

Permalink
Add content provider in order to prevent the use of init in Applicati…
Browse files Browse the repository at this point in the history
…on class
  • Loading branch information
ptsiogas4 committed May 29, 2019
1 parent 8e5f932 commit 057d3d2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
SecureBoxHelper.instance.init(this)
val sampleText = "This is a properly decrypted text."
testTextView.text = sampleText
SecureBoxHelper.instance.encryptString("testVar", sampleText, "mySecurePassword")
Expand Down
10 changes: 9 additions & 1 deletion securebox/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ptsiogas.gr.securebox"/>
package="ptsiogas.gr.securebox">

<application>

<provider
android:name=".SecureBoxContentProvider"
android:authorities="${applicationId}.SecureBoxContentProvider" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ptsiogas.gr.securebox

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri

class SecureBoxContentProvider : ContentProvider() {
override fun onCreate(): Boolean {
if (this.context != null) {
SecureBoxHelper.instance.init(this.context)
}
return true
}

override fun insert(uri: Uri, values: ContentValues?): Uri {
//do nothing
return uri
}

override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor {
throw Exception("unimplemented")
}

override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int {
throw Exception("unimplemented")
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
throw Exception("unimplemented")
}

override fun getType(uri: Uri): String {
throw Exception("unimplemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SecureBoxHelper {
private var context: Context? = null

// only call from App!
fun init(appContext: Context) {
fun init(appContext: Context?) {
this.context = appContext
}

Expand Down

0 comments on commit 057d3d2

Please sign in to comment.