- code foramtting only mostly of whitespace for readability of a few Android files

This commit is contained in:
rolzad73@gmail.com
2013-06-01 16:02:10 +00:00
parent 8a7d5f4490
commit a400cabfc7
3 changed files with 956 additions and 873 deletions
@@ -1,4 +1,5 @@
package net.wagic.utils; package net.wagic.utils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -7,7 +8,8 @@ import java.util.Scanner;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
public class StorageOptions { public class StorageOptions
{
private static ArrayList<String> mMounts = new ArrayList<String>(); private static ArrayList<String> mMounts = new ArrayList<String>();
private static ArrayList<String> mVold = new ArrayList<String>(); private static ArrayList<String> mVold = new ArrayList<String>();
@@ -16,7 +18,8 @@ public class StorageOptions {
public static int count = 0; public static int count = 0;
public static String defaultMountPoint; public static String defaultMountPoint;
public static void determineStorageOptions() { public static void determineStorageOptions()
{
initializeMountPoints(); initializeMountPoints();
readMountsFile(); readMountsFile();
readVoldFile(); readVoldFile();
@@ -25,93 +28,95 @@ public class StorageOptions {
setProperties(); setProperties();
} }
private static void initializeMountPoints() private static void initializeMountPoints()
{ {
try try
{ {
defaultMountPoint = Environment.getExternalStorageDirectory().getCanonicalPath(); defaultMountPoint = Environment.getExternalStorageDirectory().getCanonicalPath();
} } catch (Exception ioEx)
catch (Exception ioEx)
{ {
// an error occurred trying to get the canonical path, use '/mnt/sdcard' instead // an error occurred trying to get the canonical path, use '/mnt/sdcard' instead
defaultMountPoint = "/mnt/sdcard"; defaultMountPoint = "/mnt/sdcard";
} }
} }
private static void readMountsFile()
private static void readMountsFile() { {
/* /*
* Scan the /proc/mounts file and look for lines like this: * Scan the /proc/mounts file and look for lines like this: /dev/block/vold/179:1 /mnt/sdcard vfat
* /dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0 * rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
* *
* When one is found, split it into its elements * When one is found, split it into its elements and then pull out the path to the that mount point and add it to the arraylist
* and then pull out the path to the that mount point
* and add it to the arraylist
*/ */
try { try
{
Scanner scanner = new Scanner(new File("/proc/mounts")); Scanner scanner = new Scanner(new File("/proc/mounts"));
while (scanner.hasNext()) { while (scanner.hasNext())
{
String line = scanner.nextLine(); String line = scanner.nextLine();
if (line.startsWith("/dev/block/vold/")) { if (line.startsWith("/dev/block/vold/"))
{
String[] lineElements = line.split(" "); String[] lineElements = line.split(" ");
lineElements[1].replaceAll(":.*$", ""); lineElements[1].replaceAll(":.*$", "");
mMounts.add(lineElements[1]); mMounts.add(lineElements[1]);
} }
} }
} } catch (FileNotFoundException fnfex)
catch (FileNotFoundException fnfex){ {
// if proc/mount doesn't exist we just use // if proc/mount doesn't exist we just use
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} catch (Exception e) { } catch (Exception e)
{
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} }
} }
private static void readVoldFile() { private static void readVoldFile()
{
/* /*
* Scan the /system/etc/vold.fstab file and look for lines like this: * Scan the /system/etc/vold.fstab file and look for lines like this: dev_mount sdcard /mnt/sdcard 1 /devices/platform/s3c-sdhci.0/mmc_host/mmc0
* dev_mount sdcard /mnt/sdcard 1 /devices/platform/s3c-sdhci.0/mmc_host/mmc0
* *
* When one is found, split it into its elements * When one is found, split it into its elements and then pull out the path to the that mount point and add it to the arraylist
* and then pull out the path to the that mount point
* and add it to the arraylist
*/ */
try { try
{
Scanner scanner = new Scanner(new File("/system/etc/vold.fstab")); Scanner scanner = new Scanner(new File("/system/etc/vold.fstab"));
while (scanner.hasNext()) { while (scanner.hasNext())
{
String line = scanner.nextLine(); String line = scanner.nextLine();
if (line.startsWith("dev_mount")) { if (line.startsWith("dev_mount"))
{
String[] lineElements = line.split(" "); String[] lineElements = line.split(" ");
lineElements[2] = lineElements[2].replaceAll(":.*$", ""); lineElements[2] = lineElements[2].replaceAll(":.*$", "");
mVold.add(lineElements[2]); mVold.add(lineElements[2]);
} }
} }
} } catch (FileNotFoundException fnfex)
catch (FileNotFoundException fnfex){ {
// if vold.fstab doesn't exist we use the value gathered from the Environment // if vold.fstab doesn't exist we use the value gathered from the Environment
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} } catch (Exception e)
catch (Exception e) { {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint); mMounts.add(defaultMountPoint);
} }
} }
private static void compareMountsWithVold() { private static void compareMountsWithVold()
{
/* /*
* Sometimes the two lists of mount points will be different. * Sometimes the two lists of mount points will be different. We only want those mount points that are in both list.
* We only want those mount points that are in both list.
* *
* Compare the two lists together and remove items that are not in both lists. * Compare the two lists together and remove items that are not in both lists.
*/ */
for (int i = 0; i < mMounts.size(); i++) { for (int i = 0; i < mMounts.size(); i++)
{
String mount = mMounts.get(i); String mount = mMounts.get(i);
if (!mVold.contains(mount)) if (!mVold.contains(mount))
mMounts.remove(i--); mMounts.remove(i--);
@@ -122,15 +127,14 @@ public class StorageOptions {
mVold.clear(); mVold.clear();
} }
private static void testAndCleanMountsList() { private static void testAndCleanMountsList()
{
/* /*
* Now that we have a cleaned list of mount paths * Now that we have a cleaned list of mount paths Test each one to make sure it's a valid and available path. If it is not, remove it from the list.
* Test each one to make sure it's a valid and
* available path. If it is not, remove it from
* the list.
*/ */
for (int i = 0; i < mMounts.size(); i++) { for (int i = 0; i < mMounts.size(); i++)
{
String mount = mMounts.get(i); String mount = mMounts.get(i);
File root = new File(mount); File root = new File(mount);
if (!root.exists() || !root.isDirectory() || !root.canWrite()) if (!root.exists() || !root.isDirectory() || !root.canWrite())
@@ -138,10 +142,10 @@ public class StorageOptions {
} }
} }
private static void setProperties() { private static void setProperties()
{
/* /*
* At this point all the paths in the list should be * At this point all the paths in the list should be valid. Build the public properties.
* valid. Build the public properties.
*/ */
ArrayList<String> mLabels = new ArrayList<String>(); ArrayList<String> mLabels = new ArrayList<String>();
File diff suppressed because it is too large Load Diff