Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23562] Android 6.0: reading to tempDirectory fails without External storage permissions

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2016-07-15T06:50:17.000+0000
Affected Version/sRelease 5.3.0
Fix Version/sn/a
ComponentsAndroid
Labelsfile, tempdirectory
ReporterMotiur Rahman
AssigneeAshraf Abu
Created2016-06-27T16:47:43.000+0000
Updated2017-03-24T18:27:48.000+0000

Description

Description

Can not read tempDirectory file without External storage permissions.

Steps to Reproduce:

1. Create a classic project. 2. Paste this code on app.js file. 3. Run it on android 6 device.

Test Case

var win = Ti.UI.createWindow({
	backgroundColor : '#ffffff'
});
var button = Ti.UI.createButton({
	top : 10,
	width : 200,
	height : 50,
	title : "Read files"
});
win.add(button);

var f = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'fileter.txt');
f.write('writing to the file would be enough to create it');

button.addEventListener('click', function(e) {
	alert(f.read());

});

win.open();

[ERROR] :  SensorManager: uid = 10318
[INFO] :   SensorManager: registerListenerImpl: listener = android.view.OrientationEventListener$SensorEventListenerImpl@33dd978, sensor = {Sensor name="Accelerometer Sensor", vendor="HTC Group Ltd.", version=1, type=1, maxRange=19.6133, resolution=0.01, power=0.17, minDelay=10000}, delay = 200000, handler = null
[ERROR] :  TiFileProxy: (KrollRuntimeThread) [6877,6877] IOException encountered
[ERROR] :  TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.a.permision/cache/_tmp/fileter.txt: open failed: ENOENT (No such file or directory)
[ERROR] :  TiFileProxy: 	at libcore.io.IoBridge.open(IoBridge.java:452)
[ERROR] :  TiFileProxy: 	at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.getOutputStream(TiFile.java:273)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.open(TiFile.java:336)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.write(TiFile.java:460)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.TiFileProxy.write(TiFileProxy.java:287)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:918)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1141)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:356)
[ERROR] :  TiFileProxy: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiFileProxy: 	at android.os.Looper.loop(Looper.java:168)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
[ERROR] :  TiFileProxy: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
[ERROR] :  TiFileProxy: 	at libcore.io.Posix.open(Native Method)
[ERROR] :  TiFileProxy: 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
[ERROR] :  TiFileProxy: 	at libcore.io.IoBridge.open(IoBridge.java:438)
[ERROR] :  TiFileProxy: 	... 13 more
[ERROR] :  TiBlob: (KrollRuntimeThread) [49,6926] /storage/emulated/0/Android/data/com.a.permision/cache/_tmp/fileter.txt: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.a.permision/cache/_tmp/fileter.txt: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: 	at libcore.io.IoBridge.open(IoBridge.java:452)
[ERROR] :  TiBlob: 	at java.io.FileInputStream.<init>(FileInputStream.java:76)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.io.TiFile.getInputStream(TiFile.java:264)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.getInputStream(TiBlob.java:389)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.guessContentTypeFromStream(TiBlob.java:209)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.loadBitmapInfo(TiBlob.java:270)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:140)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:113)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.io.TiFile.read(TiFile.java:351)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiFileProxy.read(TiFileProxy.java:239)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:918)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1141)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:356)
[ERROR] :  TiBlob: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiBlob: 	at android.os.Looper.loop(Looper.java:168)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
[ERROR] :  TiBlob: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: 	at libcore.io.Posix.open(Native Method)
[ERROR] :  TiBlob: 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
[ERROR] :  TiBlob: 	at libcore.io.IoBridge.open(IoBridge.java:438)
[ERROR] :  TiBlob: 	... 17 more
[ERROR] :  TiBlob: (KrollRuntimeThread) [7,6933] /storage/emulated/0/Android/data/com.a.permision/cache/_tmp/fileter.txt: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.a.permision/cache/_tmp/fileter.txt: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: 	at libcore.io.IoBridge.open(IoBridge.java:452)
[ERROR] :  TiBlob: 	at java.io.FileInputStream.<init>(FileInputStream.java:76)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.io.TiFile.getInputStream(TiFile.java:264)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.getInputStream(TiBlob.java:389)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.getBytes(TiBlob.java:324)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.getText(TiBlob.java:452)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.toString(TiBlob.java:511)
[ERROR] :  TiBlob: 	at ti.modules.titanium.TitaniumModule.alert(TitaniumModule.java:232)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:918)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1141)
[ERROR] :  TiBlob: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:356)
[ERROR] :  TiBlob: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiBlob: 	at android.os.Looper.loop(Looper.java:168)
[ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
[ERROR] :  TiBlob: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
[ERROR] :  TiBlob: 	at libcore.io.Posix.open(Native Method)
[ERROR] :  TiBlob: 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
[ERROR] :  TiBlob: 	at libcore.io.IoBridge.open(IoBridge.java:438)
[ERROR] :  TiBlob: 	... 15 more

*Connected Android Devices* htc_melsuhl State = device SDK Version = 6.0.1 (android-23) ABIs = armeabi-v7a, armeabi, Thanks

Attachments

FileDateSize
First Click Event.jpg2016-07-13T00:19:09.000+0000982613
Second Click Event.jpg2016-07-13T00:19:09.000+00001043269

Comments

  1. Ashraf Abu 2016-06-29

  2. Ashraf Abu 2016-06-29

  3. Ajith Rohini 2016-06-29

    [~Ricardo][~sliang], Can one of you guys please look into this and update ?
  4. Ashraf Abu 2016-07-13

    Looks like there is a bug that is happening. It first reads the writes the file. It works fine. But after that, the file gets removed... Perhaps it is being in the tempDirectory and it was being emptied.
  5. Neeraj Mishra 2016-07-13

    Hi [~cng]/[~msamah], Could you please provide an ETA on this? Thanks
  6. Ashraf Abu 2016-07-14

  7. Ashraf Abu 2016-07-15

    Will say that the example in this ticket is not the best example to use tempDirectory. Related links: [https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-property-tempDirectory] [https://github.com/appcelerator/titanium_mobile/blob/23c9e3fb93694950d33a8b4b79fbb2129ff9001b/android/runtime/common/src/java/org/appcelerator/kroll/util/TiTempFileHelper.java#L24-L28] The temp files are cleared at the start, when restarted and when it is deemed necessary. In this example, the file is created before the window opens. After the window opens, the file is cleared out as it is temporary. Instead if you were to use this:
       var win = Ti.UI.createWindow({
       	backgroundColor : '#ffffff'
       });
       var button = Ti.UI.createButton({
       	top : 10,
       	width : 200,
       	height : 50,
       	title : "Read files"
       });
       win.add(button);
       
       var button2 = Ti.UI.createButton({
       	top : 100,
       	width : 200,
       	height : 50,
       	title : "Create file"
       });
       win.add(button2);
        
       
        
       button2.addEventListener('click', function(e) {
       	var f = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'fileter.txt');
       	f.write('writing to the file would be enough to create it');
        
       });
       button.addEventListener('click', function(e) {
       	var ss = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'fileter.txt');
       	alert(ss.read() + ' - '+ Ti.Filesystem.tempDirectory);
        
       });
        
       win.open();
       
    The file will stay there till the app restarts. It is a tempDirectory, thus it's only temporary.
  8. Ashraf Abu 2016-07-15

    Will be resolving this issue as it's behaving as expected.
  9. Lee Morris 2017-03-24

    Closing ticket as duplicate with reference to the linked issues.

JSON Source