com.android.ide.common.packaging
Class PackagingUtils

java.lang.Object
  extended by com.android.ide.common.packaging.PackagingUtils

public class PackagingUtils
extends java.lang.Object

Utility class for packaging.


Field Summary
static com.google.common.collect.ImmutableList<java.lang.String> NON_RESOURCES_EXTENSIONS
          Returns the list of file extensions that represents non resources files.
static com.google.common.collect.ImmutableList<java.lang.String> NON_RESOURCES_FILENAMES
          Return file names that are not resource files.
 
Constructor Summary
PackagingUtils()
           
 
Method Summary
static boolean checkFileForPackaging(java.lang.String fileName)
          Checks a file to make sure it should be packaged as standard resources.
static boolean checkFileForPackaging(java.lang.String fileName, boolean allowClassFiles)
          Checks a file to make sure it should be packaged as standard resources.
static boolean checkFileForPackaging(java.lang.String fileName, java.lang.String extension)
          Checks a file to make sure it should be packaged as standard resources.
static boolean checkFileForPackaging(java.lang.String fileName, java.lang.String extension, boolean allowClassFiles)
          Checks a file to make sure it should be packaged as standard resources.
static boolean checkFolderForPackaging(java.lang.String folderName)
          Checks whether a folder and its content is valid for packaging into the .apk as standard Java resource.
static long computeApplicationHash(java.io.File projectDir)
          Computes an "application hash", a reasonably unique identifier for an app.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NON_RESOURCES_EXTENSIONS

public static final com.google.common.collect.ImmutableList<java.lang.String> NON_RESOURCES_EXTENSIONS
Returns the list of file extensions that represents non resources files.


NON_RESOURCES_FILENAMES

public static final com.google.common.collect.ImmutableList<java.lang.String> NON_RESOURCES_FILENAMES
Return file names that are not resource files.

Constructor Detail

PackagingUtils

public PackagingUtils()
Method Detail

checkFolderForPackaging

public static boolean checkFolderForPackaging(@NonNull
                                              java.lang.String folderName)
Checks whether a folder and its content is valid for packaging into the .apk as standard Java resource.

Parameters:
folderName - the name of the folder.
Returns:
true if the folder is valid for packaging.

checkFileForPackaging

public static boolean checkFileForPackaging(@NonNull
                                            java.lang.String fileName,
                                            boolean allowClassFiles)
Checks a file to make sure it should be packaged as standard resources.

Parameters:
fileName - the name of the file (including extension)
allowClassFiles - whether to allow java class files
Returns:
true if the file should be packaged as standard java resources.

checkFileForPackaging

public static boolean checkFileForPackaging(@NonNull
                                            java.lang.String fileName)
Checks a file to make sure it should be packaged as standard resources.

Parameters:
fileName - the name of the file (including extension)
Returns:
true if the file should be packaged as standard java resources.

checkFileForPackaging

public static boolean checkFileForPackaging(@NonNull
                                            java.lang.String fileName,
                                            @NonNull
                                            java.lang.String extension,
                                            boolean allowClassFiles)
Checks a file to make sure it should be packaged as standard resources.

Parameters:
fileName - the name of the file (including extension)
extension - the extension of the file (excluding '.')
allowClassFiles - whether to allow java class files
Returns:
true if the file should be packaged as standard java resources.

checkFileForPackaging

public static boolean checkFileForPackaging(@NonNull
                                            java.lang.String fileName,
                                            @NonNull
                                            java.lang.String extension)
Checks a file to make sure it should be packaged as standard resources.

Parameters:
fileName - the name of the file (including extension)
extension - the extension of the file (excluding '.')
Returns:
true if the file should be packaged as standard java resources.

computeApplicationHash

public static long computeApplicationHash(@NonNull
                                          java.io.File projectDir)
Computes an "application hash", a reasonably unique identifier for an app.

This is currently used by Instant Run to prevent apps on a device from guessing the authentication token associated with an instant run developed app on the same device.

This method creates the "secret", the field in the AppInfo class which is used as a simple authentication token between the IDE and the app server.

This is not a cryptographically strong unique id; we could attempt to make a truly random number here, but we'd need to store that id somewhere such that subsequent builds will use the same secret, to avoid having the IDE and the app getting out of sync, and there isn't really a natural place for us to store the key to make it survive across a clean build. (One possibility is putting it into local.properties).

However, we have much simpler needs: we just need a key that can't be guessed from a hostile app on the developer's device, and it only has a few guesses (after providing the wrong secret to the server a few times, the server will shut down.) We can't rely on the package name along, since the port number is known, and the package name is discoverable by the hostile app (by querying the contents of /data/data/*). Therefore we also include facts that the hostile app can't know, such as as the path on the developer's machine to the app project and the name of the developer's machine, etc. The goal is for this secret to be reasonably stable (e.g. the same from build to build) yet not something an app could guess if it only has a couple of tries.