Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Stringlate cannot "Export to SD card" under AOSP 4.1.2 (Jelly Bean) #160

Open
Olf0 opened this issue Nov 12, 2017 · 23 comments
Open

Stringlate cannot "Export to SD card" under AOSP 4.1.2 (Jelly Bean) #160

Olf0 opened this issue Nov 12, 2017 · 23 comments
Labels

Comments

@Olf0
Copy link

Olf0 commented Nov 12, 2017

Stringlate v0.11 from F-Droid under AOSP 4.1.2 (API level 16) is unable to "Export to SD card": "Could not export strings.xml file".

This was somewhat expected, as the README.md states: "This application has not yet been tested on pre-Lollipop devices and it might fail on some operations, such as exporting a file to the SD card. If this is the case, please let me know, or create a new pull request with a fix."

Although I am unable to write code for a PR, I can provide logs, if that is deemed helpful.

@gsantner
Copy link
Contributor

Can you try with adb logcat -s io.github.lonamiwebs.stringlate to get some error logs? Or maybe step into with debugger?

@Olf0
Copy link
Author

Olf0 commented Nov 24, 2017

Log taken locally with aLogcat Root:
alogcat_stringlate0.11_export-to-sd_filtered-stringlate.txt
Pretty terse, IMO.

@Olf0
Copy link
Author

Olf0 commented Dec 10, 2017

Tried again with Stringlate 0.12, took a thorough look at the aLogcat settings, still there seems to be nothing meaningful in either main-log or event-log:

How to use a debugger on the device (I fail to run adb from the PC with this device)? Can you provide any web-pointers, please?

@Olf0
Copy link
Author

Olf0 commented Dec 13, 2017

Well, with the right settings, logs taken with aLogcat are a bit more comprehensive (but on first sight not sufficiently so):

@Olf0
Copy link
Author

Olf0 commented Dec 13, 2017

Tried with Catlog, which is a bit awkward to use and has issues when trying to filter, but the latter actually makes a difference, as the interesting output does not contain the string stringlate!
See for yourself (and supposedly these logs in combination with the last two logs taken with aLogcat are helpful):

P.S. (edit): IMO the following three lines can be ignored (occurring in Catlog's logs), as they seem to be caused by the platform / software stack I am using and occur with many other apps, too:
E/AndroidRuntime(6926): No DOWNLOAD_CACHE is set!
E/AndroidRuntime(6926): '(null)' directory does not exist!
E/AndroidRuntime(6926): loadLocale: can't get locale.

@Olf0
Copy link
Author

Olf0 commented Dec 13, 2017

Looks pretty much the same, when filtering for gsantner in aLogcat:
alogcat-mainlog_stringlate0.12_export-to-sd_filtered-gsantner.txt

@gsantner
Copy link
Contributor

Hmm. weird, the code should work down to API 14 which is used on Markor too. I will update the utils, tell me then after next uprate if that helped

@Olf0 Olf0 changed the title Stringlate v0.11 cannot "Export to SD card" under ICS (Ice Cream Sandwich) Stringlate cannot "Export to SD card" under ICS (Ice Cream Sandwich) Dec 13, 2017
@Olf0
Copy link
Author

Olf0 commented Dec 13, 2017

Well, Markor does not exhibit issues when writing files (tried a regular note and a quick-note), but shows a few similar (but fewer) error messages in the log (I just took a mainlog, filtered for gsantner):
alogcat-mainlog_gsantner-markor-024.txt

If I can help by investigating this further, please let me know (and how to).

@gsantner
Copy link
Contributor

You told Markor doesn't crash right? The said things seem to have todo with java imports, but not calls itself ( which are checked against API version). Both of these image methods are not used in stringlate, so I don't see any problem with it (in meaning of I don't think they are the cause of your problems)

screenshot_2017-12-14__16-06_1

@gsantner
Copy link
Contributor

gsantner commented Dec 14, 2017

The issue may be somewhere in TranslateActivtiy, but I cannot find any at the fast browsing throguh (doExportToSd,exportToSd). Maybe @Lonami has an idea on that

@Olf0
Copy link
Author

Olf0 commented Dec 14, 2017

@gsantner,

You told Markor doesn't crash right?

  • Stringlate also does not crash, it just replies "Could not export strings.xml file" in a small, black notification at the middle bottom of the screen (see original description in the first post of this thread / issue), when trying to use its function "Export to SD-card" on my device (AOSP 4.1.2).
  • As Markor has no "Export to SD-card" function AFAICS, I did not know (and still don't) how to trigger a similar behaviour, thus I just saved a note and a quick-note in Markor. Looking at the logs the actions carried out are somewhat different. Do you have any specific suggestion, what to test and log with Markor in order to provoke a failure to write as with Stringlate?

@gsantner
Copy link
Contributor

gsantner commented Dec 14, 2017

If markor does save your notes i see no problem, it always writes to sd/external.

What you can do is to try out all of my apps and can tell if you can find some real crash (where the app quits/exits). For me this all this seems to be not a big error in utils code but maybe some minor thing in stringlate. Still I am happy about fixing any bug in the used utils.

These utils are used in all of my apps, so try maybe Markor, MemeTastic, openlauncher, dandelion*, froody and stringlate.

@Olf0
Copy link
Author

Olf0 commented Dec 15, 2017

If markor does save your notes i see no problem, it always writes to sd/external.

Markor successfully does that (I may have missed to state that 100% clearly in my former comment), in contrast to Stringlate.

@Olf0 Olf0 changed the title Stringlate cannot "Export to SD card" under ICS (Ice Cream Sandwich) Stringlate cannot "Export to SD card" under AOSP 4.1.2 (Jelly Bean) Mar 12, 2018
@Olf0
Copy link
Author

Olf0 commented Mar 12, 2018

@Lonami, as I am not (yet) willing "to try out all of (@gsantner's) apps and can tell if you can find some real crash (where the app quits/exits)", which may provide a hint what goes wrong in Stringlate when trying to "export to SD" under Android 4.1.2 (API level 16), I retested with Stringlate 0.13:

AFAICS the four consecutive "System.err:"-lines at the end of the Mainlog point to io.github.lonamiwebs.stringlate.activities.translate.TranslateActivity.doExportToSd(TranslateActivity.java) as cause, but this is where my Android / Java debugging skills end.

@gsantner
Copy link
Contributor

gsantner commented Mar 19, 2018

Logcat guide update: Maybe take a look at https://gsantner.net/android-contribution-guide/?packageid=io.github.lonamiwebs.stringlate#logcat (has already filled out the right package id)

@Olf0
Copy link
Author

Olf0 commented Mar 19, 2018

Well, what's wrong or missing in the last logs I provided?

Side note: Thanks for your well written, brief guide. But it uses ADB, which I fail to get working.
I run an AOSP 4.1.2 based Android runtime environment (AlienDalvik) under (i.e. in a chroot environment) Linux (SailfishOS) on my phone. Using ADB installed on the host Linux (SailfishOS), I see the Android runtime environment (AlienDalvik) as an emulator. Trying to connect via TCP using 127.0.0.1 and the right port (which is not the default one) fails, everything else finds no device. Starting adbd as root on an Android shell (i.e. inside the Android runtime environment) made no difference. Any ideas what else to try?

@gsantner
Copy link
Contributor

gsantner commented Mar 19, 2018

I just search through projects and pasted the link 😄 , because the existing recommended command seemed not to work.

If you can't start adb wifi (adb tcpip 5555, systemsettings or some wireless app) and cannot get it work over usb, I'm not aware any other way to get some debug logs, at least without having root rights. How did you get the logs above?

The existing logs seem to be fine, and should give us some info to fix this.

Any ideas what else to try?

(Note: Personal recommendation) Yeah, buy a new device. You have a big security hole with such a thing. What's even more bad than android fragmentation and outdated android versions are unmaintained/outdated solutions which do try to integrate an again very old android version. OR at least don't be dependant on Android on that device. (it's great you use this app, but this won't help you if your data gets copied by bad people)

@Olf0
Copy link
Author

Olf0 commented Mar 19, 2018

If you can't start adb wifi (adb tcpip 5555,

adb tcpip 127.0.0.1:5556 on the host Linux finds the "emulator", but fails to connect (as stated).
Or do I have to start adb this way on the Android side as well?

systemsettings

There are no Android system settings, unfortunately.

or some wireless app

Can you please name two or three suitable "wireless apps" you were thinking of, as I have not found anything such for debugging purposes.

and cannot get it work over usb, I'm not aware any other way to get some debug logs, at least without having root rights.

As I am root on the host side anyway, placing a su binary and control app inside the Android container was feasible. When taking logs this way (under Android < 4.3) with "aLogcat root", I cannot see any difference compared to other logs taken with adb (although it took me a while to figure out the proper settings for aLogcat), in contrast to "CatLog".

You have a big security hole with such a thing.

As the Android runtime environment was updated until last year (i.e. as long as Google maintained AOSP 4), I don't think this is worse than most devices running Android 5 and 6 (and receiving no updates from their manufacturers for longer).

Yeah, buy a new device.

I did (but did not migrate to it, yet), but SailfishOS currently provides a AOSP 4 based Android runtime (this is supposed to change), so no fundamental difference besides newer hardware. ;)
Note, that I use Android apps only for functionality SailfishOS native apps (or Unix commands) do not provide (e.g. Stringlate).

What's even more bad than android fragmentation and outdated android versions are unmaintained/outdated solutions which do try to integrate an again very old android version.

This was not the case, when designed and implemented in 2013 and was O.K. until 2017 (when Google stopped maintaining AOSP 4). But something has to be (and is promised to be) to be done above this in 2018 , be it Anbox or a license for a newer AlienDalvik.

Well ok, that was my personal recommendation.

"You are a strongly opinionated man!" (this quote was originally directed at me, but fits well here, IMHO).

@gsantner
Copy link
Contributor

gsantner commented Mar 19, 2018

Or do I have to start adb this way on the Android side as well?

You need to give adb access to your device, which is the counterpart of the PC's adb. But no, this is not the same adb executeable that you run on your desktop. I have to admit if you can't get any help on your devices/OSs forums, I too can't give any advice, as I don't own any. EDIT: Doesn't seem to be a seperate process where adb is running on the device.

Can you please name two or three suitable "wireless apps", you were thinking of, as I have not found anything such for debugging purposes.

I had an app called "adb wireless" from F-Droid installed, which basically did the same like the Adb-Wireless-option in systemsettings.

aLogcat root

Yeah, that was the one last option I can think off.

Other than that, read (update came right after my comment) the more clear comment above :D

@gsantner
Copy link
Contributor

OS Monitor (Monitor the Operating System) - https://f-droid.org/app/com.eolwral.osmonitor

seems to give logs too reliable, after enabling root.

@Lonami Lonami added the bug label Mar 27, 2018
@Lonami
Copy link
Member

Lonami commented Apr 6, 2018

@Olf0 thank you so much for providing so much information and sorry for the huge delay. The latest logs point to these lines:

private void doExportToSd(Uri uri, File template)
throws IOException {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream out = new FileOutputStream(pfd.getFileDescriptor());
if (!mRepo.applyTemplate(template, mSelectedLocale, out))
throw new IOException("Apply default template failed.");
out.close();
pfd.close();
}

642, to be precise. And I think it's because that method is also used even on pre-Lolipop devices (notice inside the else it's called, in the for):

private void doExportManyToSd(Uri uri) {
boolean ok = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// DocumentFile.fromTreeUri:
// "This is only useful on devices running LOLLIPOP or later,
// and will return null when called on earlier platform versions."
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, uri);
try {
for (File template : mRepo.getDefaultResourcesFiles()) {
// Do not bother creating a file unless there is some strings for it
if (mRepo.canApplyTemplate(template, mSelectedLocale)) {
DocumentFile outFile = pickedDir.createFile("text/xml", template.getName());
doExportToSd(outFile.getUri(), template);
}
}
} catch (IOException e) {
e.printStackTrace();
ok = false;
}
} else {
try {
File root = new File(uri.getPath());
if (!root.isDirectory() && !root.mkdirs())
throw new IOException("Could not create the root directory.");
for (File template : mRepo.getDefaultResourcesFiles()) {
// Do not bother creating a file unless there is some strings for it
if (mRepo.canApplyTemplate(template, mSelectedLocale)) {
File outFile = new File(root, template.getName());
doExportToSd(Uri.fromFile(outFile), template);
}
}
} catch (IOException e) {
e.printStackTrace();
ok = false;
}
}

@Olf0
Copy link
Author

Olf0 commented Apr 8, 2018

@Lonami, thanks for the analysis and explanation.

@gsantner,

  • Thanks for the pointer to adbWireless (seems to be unmaintained, v1.5.4 on F-Droid is from 2013), it helped me finding ADB Manager and Wirebug on F-Droid, which are more recent. But in the end, they all just start adbd, which I already tried manually before. Anyway, they helped me confirm, that I had no fundamental misconception, how this is supposed to work (rsp. still doesn't).
  • I use OS Monitor for its detailed network interface monitoring capabilities, but it fails to take logs in my environment, hence I retracted its root access. Anyway as aLogcat root and CatLog work and the former records comprehensive logs with the right settings (I failed to configure CatLog to do that, though), this is a non-issue.

Thanks for your support.

@Lonami
Copy link
Member

Lonami commented Apr 23, 2018

This fails:

File root = new File(uri.getPath());
if (!root.isDirectory() && !root.mkdirs())
throw new IOException("Could not create the root directory.");

But I don't know why. mkdirs returns false for directory on sd card while the parent directory is writable advices to check our permissions but we have them:

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="21" />

I have checked the root path and it's the same as the one returned by Environment.getExternalStorageDirectory() which in the case of the emulator is /mnt/sdcard. So it's not that the path is being inferred incorrectly.


Oh apparently I don't have a sdcard at all in my emulator (downloads don't work either). Anyway, I created a separate sd card with mksdcard and it's not working either, no matter how I start it. Not even with the -sdcard sd.img switch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants