Android Question Illogical solution to problem.

vecino

Well-Known Member
Licensed User
Longtime User
A problem has been solved in this thread. But the solution does not have logic.
In short, in an "if else", which always runs the "else", it works if the content of the "if" is modified.
I think it's easier to understand if you look at #34 of the thread. I copy it here:
Can anyone explain this strange case?

If I do not see it, I do not believe it.
Finally, I have found the problem, and it is impossible to believe.
I have done many tests and the result is always the same.

With DirInternal it does not work.
With DirDefaultExternal it works.

It's incredible, because the code does not pass through there, but rather through the else:
Does anyone have a reasonable explanation?

00ee2796375ca0c3d74c47023e366c89o.png
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Have you tried
B4X:
If (p.SdkVersion >= 24) Or (File.ExternalWritable = False) Then
...
to see if it's some type of compiling optimization gone wrong?
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I just checked and the result is the same.
Works with DirDefaultExternal. It does not work with DirInternal.
Although that code is not executed because it passes through the "else"
Thank you.

Logger connected to: unknown miTab LIVE
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(2)--->>>>>> SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
SDK#: 19 - UseFP: false - SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
check 4
---- AppUpdating.UpdateApk
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Webserver's info file content:
ver=2
Web version number: 2
Current Version: 1
Newer version available. Now I try its downloading
-- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? TRUE
new apk version downloaded and ready to install
user asked to install new apk
UpdateComplete - time: 00:04:11
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(2)--->>>>>> SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
SDK#: 19 - UseFP: false - SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
check 4
---- AppUpdating.UpdateApk
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Webserver's info file content:
ver=2
Web version number: 2
Current Version: 1
Newer version available. Now I try its downloading
-- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? FALSE
failed download of new apk version
UpdateComplete - time: 00:05:12
** Activity (main) Pause, UserClosed = true **
Logger connected to: unknown miTab LIVE
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(2)--->>>>>> SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
SDK#: 19 - UseFP: false - SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
check 4
---- AppUpdating.UpdateApk
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Webserver's info file content:
ver=2
Web version number: 2
Current Version: 1
Newer version available. Now I try its downloading
-- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? TRUE
new apk version downloaded and ready to install
user asked to install new apk
UpdateComplete - time: 00:04:11
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(2)--->>>>>> SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
SDK#: 19 - UseFP: false - SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
check 4
---- AppUpdating.UpdateApk
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Webserver's info file content:
ver=2
Web version number: 2
Current Version: 1
Newer version available. Now I try its downloading
-- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? FALSE
failed download of new apk version
UpdateComplete - time: 00:05:12
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(2)--->>>>>> SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
SDK#: 19 - UseFP: false - SharedFolder: /mnt/sdcard/Android/data/viamos.com/files/shared
check 4
---- AppUpdating.UpdateApk
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Webserver's info file content:
ver=2
Web version number: 2
Current Version: 1
Newer version available. Now I try its downloading
-- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? TRUE
new apk version downloaded and ready to install
user asked to install new apk
UpdateComplete - time: 00:06:00
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @KMatle ,
let me summarize for @vecino what happened so far.
Originally, running the same exact code on two different devices it resulted in:
Device #1: always fail
Device #2: fail if run in release mode, working if run in debug mode

Then we tried a modified version of original code where a lot of Logs where added in order to better understand what happened.

What @vecino says in his post is that, although the execution path is correctly the one in the else branch above, it makes a difference if he changes the if branch content substituting DirInternal with DirDefaultExternal.
Obviously this shouldn't be.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
No, KMatle, my question is another.
I show you an example of what happens.
B4X:
Dim bBool As Boolean = False
 
If bBool Then  ' It never goes through here.
  
  'SharedFolder = File.Combine(File.DirInternal, "shared")
  SharedFolder = File.Combine(File.DirDefaultExternal, "shared")

Else ' It always goes through here.
  
  SharedFolder = rp.GetSafeDirDefaultExternal("shared")
End If

With File.DirInternal the software does NOT work.
With File.DirDefaultExternal the software DOES work.

Although the code NEVER passes through the "if", it ALWAYS goes through the "else".


EDIT: I had not seen UDG's message.
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Is not that.
The code goes through the "else". That is good, it is correct.

But the program does not work if in the "if" it says DirInternal.
The program works well if in the "if" it says DirDefaultExternal.

Although the code never goes through "if".
That is the mystery. It has no logic.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @Erel,
since I tried to support @vecino since the beginning, let me explain what's happening.
In a previous thread we confronted ourselves with a strange problem: the same exact code didn't work on a first device while on a second one it worked in debug mode but not in release mode.
To better understand what was goign on, I modified my AppUpdating library in order to add a lot more Logs.
What vecino found is that, altough the code in the class initialization always and correctly follows the else branch in the code posted (identical to your FileProvider one), it makes a difference what constitutes the content of the unused if branch.
In fact, if he correctly uses DirInternal the app fails, but if he writes DirDefaultExternal (which he agrees is wrong) the app works ok.

A few facts about his device:
- sdk is 19
- the failing occurs on line "out = File.OpenOutput(SharedFolder,"tmp.apk",False)"
- SharedFolder is: /mnt/sdcard/Android/data/viamos.com/files/shared

On my testing devices everything works right since the beginning and so, I guess, is for those other memebers using the lib. So what could cause the described failings on both the devices hold by vecino?

udg

ps: please find attached the code used so far for testing
 

Attachments

  • AU202_src.zip
    15.1 KB · Views: 258
  • viamos2.zip
    30 KB · Views: 248
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
When you use File.DirDefaultExternal, anywhere in your code, the external storage permission is added to the manifest. You can see it if you click on the List Permissions button.

The permission is not added automatically when you use RuntimePermissions.GetSafeDirDefaultExternal. It is not added because it is only needed on Android 4.3-. The developer needs to manually add the permission with:
B4X:
AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)


Where is the error message?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I think that the most recent error log is this one.
The snippet about the write external permission is part of the app Manifest (see viamos2.zip above)
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you very much.
Let's wait for vecino to test again with the snippet you suggested.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello friends:
The tablet has android 4.4.2

If I add android:maxSdkVersion="19", it works well.
And if I eliminate that line, it also works well.

Where can I learn these things? :eek:

I have lost a week of work. I would never have solved it myself.
Thank you very much, friends.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
@vecino note for future posts that you should post error messages and code as text.
:confused::confused::confused: Hello, Erel, the source code, the error message, examples of use, attached project, etc. Everything is published here and in the link indicated at the beginning.

With this code it does not work.
B4X:
Dim bBool as Boolean=False
If bBool then
  log(File.DirInternal)
Else
  SharedFolder=rp.GetSafeDirDefaultExternal("shared")
End If

And with this code it works.
B4X:
Dim bBool as Boolean=False
If bBool then
  log(File.DirDefaultExternal)
Else
  SharedFolder=rp.GetSafeDirDefaultExternal("shared")
End If

The error occurs in this line.
B4X:
out = File.OpenOutput(SharedFolder,"tmp.apk",False)
A copy of the screen.

9d396a8fdb438b8f8b9b2a96875130bbo.png


Thank you very much for everything.
 
Upvote 0
Top