Class SysUtil


  • public final class SysUtil
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SysUtil.Api14Utils  
    • Constructor Summary

      Constructors 
      Constructor Description
      SysUtil()  
    • Method Summary

      Modifier and Type Method Description
      static void deleteOrThrow​(java.io.File file)  
      static void dumbDeleteRecursive​(java.io.File file)
      Delete a directory and its contents.
      static void fallocateIfSupported​(java.io.FileDescriptor fd, long length)
      Pre-allocate disk space for a file if we can do that on this version of the OS.
      static int findAbiScore​(java.lang.String[] supportedAbis, java.lang.String abi)
      Determine how preferred a given ABI is on this system.
      static void fsyncRecursive​(java.io.File fileName)  
      static long getApkDepBlockLength​(java.io.File apkFile)
      Retrieve the size of dependency file.
      static int getAppVersionCode​(android.content.Context context)  
      static java.lang.String getBaseName​(java.lang.String fileName)
      Gets the base name, without extension, of given file name.
      static FileLocker getOrCreateLockOnDir​(java.io.File soDirectory, java.io.File lockFileName, boolean blocking)  
      static java.lang.String[] getSupportedAbis()
      Return an list of ABIs we supported on this device ordered according to preference.
      static boolean is64Bit()  
      static boolean isDisabledExtractNativeLibs​(android.content.Context context)  
      static boolean isSupportedDirectLoad​(android.content.Context context, int appType)  
      static byte[] makeApkDepBlock​(java.io.File apkFile, android.content.Context context)
      N.B.
      static void mkdirOrThrow​(java.io.File dir)
      Like File.mkdirs, but throws on error.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SysUtil

        public SysUtil()
    • Method Detail

      • findAbiScore

        public static int findAbiScore​(java.lang.String[] supportedAbis,
                                       java.lang.String abi)
        Determine how preferred a given ABI is on this system.
        Parameters:
        supportedAbis - ABIs on this system
        abi - ABI of a shared library we might want to unpack
        Returns:
        -1 if not supported or an integer, smaller being more preferred
      • deleteOrThrow

        public static void deleteOrThrow​(java.io.File file)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getSupportedAbis

        public static java.lang.String[] getSupportedAbis()
        Return an list of ABIs we supported on this device ordered according to preference. Use a separate inner class to isolate the version-dependent call where it won't cause the whole class to fail preverification.
        Returns:
        Ordered array of supported ABIs
      • fallocateIfSupported

        public static void fallocateIfSupported​(java.io.FileDescriptor fd,
                                                long length)
                                         throws java.io.IOException
        Pre-allocate disk space for a file if we can do that on this version of the OS.
        Parameters:
        fd - File descriptor for file
        length - Number of bytes to allocate.
        Throws:
        java.io.IOException - IOException
      • dumbDeleteRecursive

        public static void dumbDeleteRecursive​(java.io.File file)
                                        throws java.io.IOException
        Delete a directory and its contents.

        WARNING: Java APIs do not let us distinguish directories from symbolic links to directories. Consequently, if the directory contains symbolic links to directories, we will attempt to delete the contents of pointed-to directories.

        Parameters:
        file - File or directory to delete
        Throws:
        java.io.IOException - IOException
      • mkdirOrThrow

        public static void mkdirOrThrow​(java.io.File dir)
                                 throws java.io.IOException
        Like File.mkdirs, but throws on error. Succeeds even if File.mkdirs "fails", but dir still names a directory.
        Parameters:
        dir - Directory to create. All parents created as well.
        Throws:
        java.io.IOException - IOException
      • fsyncRecursive

        public static void fsyncRecursive​(java.io.File fileName)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getApkDepBlockLength

        public static long getApkDepBlockLength​(java.io.File apkFile)
                                         throws java.io.IOException
        Retrieve the size of dependency file.
        Parameters:
        apkFile - the apk file
        Returns:
        the size of dependency file
        Throws:
        java.io.IOException - IOException
      • makeApkDepBlock

        public static byte[] makeApkDepBlock​(java.io.File apkFile,
                                             android.content.Context context)
                                      throws java.io.IOException
        N.B. If this method is changed, the above method getApkDepBlockLength(java.io.File) must also be updated to reflect the expected size of the dep block
        Parameters:
        apkFile - apk file
        context - application context
        Returns:
        dependency file in bytes
        Throws:
        java.io.IOException - IOException
      • getAppVersionCode

        public static int getAppVersionCode​(android.content.Context context)
      • is64Bit

        public static boolean is64Bit()
      • isSupportedDirectLoad

        public static boolean isSupportedDirectLoad​(android.content.Context context,
                                                    int appType)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • isDisabledExtractNativeLibs

        public static boolean isDisabledExtractNativeLibs​(android.content.Context context)
      • getOrCreateLockOnDir

        @Nullable
        public static FileLocker getOrCreateLockOnDir​(java.io.File soDirectory,
                                                      java.io.File lockFileName,
                                                      boolean blocking)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getBaseName

        public static java.lang.String getBaseName​(java.lang.String fileName)
        Gets the base name, without extension, of given file name.
        Parameters:
        fileName - full file name
        Returns:
        base name