Skip to main content

Bug in Android Port in PlatformImplementation.java

1 reply [Last post]
ugosweb
Offline
Joined: 2009-11-03
Points: 0

Hi,
I found a bug in the Thorsten's Android Port in the class com.sun.lwuit.io.impl.PlatformImplementation.
The bugged methods are:

getRootSizeBytes(String root)

getRootAvailableSpace(String root)

In boths there are references to non existent methods in AndroidSDK:

File.getTotalSpace()

File.getUsableSpace()

Both methods are not present in the Android SDK.
The following are the working implementations:

    @Override
    public long getRootSizeBytes(String root) {
        String[] roots = this.listFilesystemRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].equals(root)) {
                File r = new File(root);
                StatFs stat = new StatFs(r.getPath());
                return stat.getBlockCount() * stat.getBlockSize();
                //return r.getTotalSpace() - r.getUsableSpace();  // not working
            }
        }
        return 0;
    }

    @Override
    public long getRootAvailableSpace(String root) {
        String[] roots = this.listFilesystemRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].equals(root)) {
                File r = new File(root);
                StatFs stat = new StatFs(r.getPath());
                return stat.getFreeBlocks() * stat.getBlockSize();
                //return r.getUsableSpace(); // not working
            }
        }
        return 0;
    }

Regards,

Ugo Chirico
http://www.ugochirico.com

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
thorsten_s
Offline
Joined: 2008-08-15
Points: 0

Hi,

thanks for the fix. I will apply it soon. The API docs say the methods are available from api level 9. I believe that is Android 2.3 and that is indeed a little high as a minimum requirement.