EddyVerbruggen / nativescript-secure-storage

:closed_lock_with_key: NativeScript plugin for secure local storage of fi. passwords
MIT License
111 stars 26 forks source link

Clear all data on Uninstall #26

Open thukuwanjiku opened 5 years ago

thukuwanjiku commented 5 years ago

Hi Eddy! Thanks for the great work, this plugin has helped me a lot. I observed some weird behavior though, which I do not think is expected. I store data in an app with this plugin, but if I uninstall the app and re-install it later, the app still accesses (recovers?) the data stored in the previous installation. How can clear data during uninstall?

EddyVerbruggen commented 5 years ago

I think you're talking about iOS, right?

thukuwanjiku commented 5 years ago

I think you're talking about iOS, right?

No sir, on android

EddyVerbruggen commented 5 years ago

Hmm, OK. Does this help? https://github.com/orhanobut/hawk/issues/169#issuecomment-261004284

thukuwanjiku commented 5 years ago

Eddy, the issue you referenced helped a lot, but their fix seems to affect another plugin in the app,
nativescript-google-maps-sdk. If I launch the app and then exit without killing the app, it crashes (in background) with this Log

An uncaught Exception occurred on "main" thread. com.tns.NativeScriptException: Calling js method run failed

Error: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.impl.bu.q()' on a null object reference com.google.maps.api.android.lib6.impl.dd.d(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):17) com.google.android.gms.maps.internal.u.a(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):33) fw.onTransact(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):4) android.os.Binder.transact(Binder.java:504) com.google.android.gms.internal.maps.zza.zzb(Unknown Source) com.google.android.gms.maps.internal.zzk.onDestroy(Unknown Source) com.google.android.gms.maps.MapView$zza.onDestroy(Unknown Source) com.google.android.gms.dynamic.DeferredLifecycleHelper.onDestroy(Unknown Source) com.google.android.gms.maps.MapView.onDestroy(Unknown Source) com.tns.Runtime.callJSMethodNative(Native Method) com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) com.tns.Runtime.callJSMethodImpl(Runtime.java:996) com.tns.Runtime.callJSMethod(Runtime.java:983) com.tns.Runtime.callJSMethod(Runtime.java:967) com.tns.Runtime.callJSMethod(Runtime.java:959) com.tns.gen.java.lang.Runnable.run(Runnable.java:15) android.os.Handler.handleCallback(Handler.java:836) android.os.Handler.dispatchMessage(Handler.java:103) android.os.Looper.loop(Looper.java:203) android.app.ActivityThread.main(ActivityThread.java:6259) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) File: "file:///data/data/com.uzahost.dropit/files/app/vendor.js, line: 42226, column: 22

StackTrace: Frame: function:'MapView.disposeNativeView', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 42226, column: 23 Frame: function:'ViewBase._tearDownUI', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95422, column: 10 Frame: function:'', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95413, column: 13 Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 105953, column: 20 Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 96710, column: 10 Frame: function:'ViewBase._tearDownUI', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95412, column: 10 Frame: function:'', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95413, column: 13 Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 105953, column: 20 Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 96710, column: 10 Frame: function:'ViewBase._tearDownUI', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95412, column: 10 Frame: function:'', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95413, column: 13 Frame: function:'ContentView.eachChildView', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 92629, column: 7 Frame: function:'PageBase.eachChildView', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 107380, column: 36 Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 96710, column: 10 Frame: function:'ViewBase._tearDownUI', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 95412, column: 10 Frame: function:'clearEntry', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 102065, column: 24 Frame: function:'Frame.setCurrent', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 101784, column: 11 Frame: function:'', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 100702, column: 24 Frame: function:'invoke', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 88539, column: 21 Frame: function:'run', file:'file:///data/data/com.uzahost.dropit/files/app/vendor.js', line: 88545, column: 7

at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
at com.tns.Runtime.callJSMethod(Runtime.java:983)
at com.tns.Runtime.callJSMethod(Runtime.java:967)
at com.tns.Runtime.callJSMethod(Runtime.java:959)
at com.tns.gen.java.lang.Runnable.run(Runnable.java:15)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6259)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.impl.bu.q()' on a null object reference at com.google.maps.api.android.lib6.impl.dd.d(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):17) at com.google.android.gms.maps.internal.u.a(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):33) at fw.onTransact(:com.google.android.gms.dynamite_mapsdynamite@15090047@15.0.90 (040308-231259764):4) at android.os.Binder.transact(Binder.java:504) at com.google.android.gms.internal.maps.zza.zzb(Unknown Source) at com.google.android.gms.maps.internal.zzk.onDestroy(Unknown Source) at com.google.android.gms.maps.MapView$zza.onDestroy(Unknown Source) at com.google.android.gms.dynamic.DeferredLifecycleHelper.onDestroy(Unknown Source) at com.google.android.gms.maps.MapView.onDestroy(Unknown Source) ... 14 more

MCurran16 commented 5 years ago

Hello Eddy, this behavior is occurring on iOS for me. Any advice? I’m uninstalling my app and when I reinstall a different build, it somehow persists to the next build.

Robsta84 commented 5 years ago

The advice is to do not use the keychain. Uninstall the application never clears the keychain.

See this: https://forums.developer.apple.com/thread/36442

kefahB commented 5 years ago

Hi everybody,

I have same problem and I writing this demo in order to achieve clearing all data as a keychain in the app .. it work for me, hope this will help !

here is discussion with NS Team

EddyVerbruggen commented 5 years ago

Hey @kefahB, I like your solution.

For others: it doesn't remove data on uninstall, but it will clear the keychain in case the app runs for "the first time" (since an uninstall). Which effectively means lingering keychain data will not be used when reinstalling the app.

Are you willing to do a PR to this plugin to integrate that code (for iOS)?

kefahB commented 5 years ago

@EddyVerbruggen Yeah sure .. I will in a few days

kefahB commented 5 years ago

It can be for android as well ?

EddyVerbruggen commented 5 years ago

Awesome, thanks!

I was under the impression Android didn't have this persistency issue.

jannomeister commented 5 years ago

I'm still experiencing this issue in android. :( Data still exists even after uninstall.

EddyVerbruggen commented 5 years ago

On android we don’t clear any data because I wasn’t aware the problem existed at all..

jannomeister commented 5 years ago

@EddyVerbruggen is there any workaround on android? because I really need to remove all the cache data once the app is reinstalled.

EddyVerbruggen commented 5 years ago

@jannomeister Scrap my previous comment; we actually do clear all data on Android when the app is reinstalled. Or at least the code is in place to do so. Are you sure you're using the latest plugin version, and there's no other explanation for the behaviour you're seeing?

I'll try and run the demo app in this repo today to verify myself as well.

UPDATE: tried it on Android and didn't see a problem. Perhaps it has to do with the Android version (9) but code-wise there's nothing preventing it from working, if you invoke that clearAllOnFirstRun method.

kefahB commented 5 years ago

@jannomeister can you please tel us where you use the code to deleting data ?

I think there is a limited number of scenarios for usage cases : once the App installed the user will be navigated to register / login page before use the App. I prefer to do stuff on those pages when the navigation was ended navigatedTo or loaded because there maybe sum issue if you use deleting data once the app being navigation.

farfromrefug commented 4 years ago

@EddyVerbruggen just faced that. Could we add like a BIG warning at the top of the README :D

EddyVerbruggen commented 4 years ago

@farfromrefug Sure