//Terminate Loader App public static void TerminateLoaderApp(string loaderAPKPackageName, bool enableADBUtilitiesLog) { ADBUtilities adbUtilitiesInstance = new ADBUtilities(enableADBUtilitiesLog); string error; int retCode = adbUtilitiesInstance.TerminateApp(loaderAPKPackageName, out error); if (retCode == ADBUtilities.adbNormalExitCode) { Debug.Log("Loader App terminated."); } }
private static DeviceAndAppStatus GetDeviceAndAppStatus() { ADBUtilities adbUtilitiesInstance = new ADBUtilities(enableADBUtilitiesLog); List <string> deviceList = null; string error = null; adbUtilitiesInstance.FindDevices(out deviceList, out error); if (!(deviceList == null)) { if (deviceList.Count == 0) { currentDeviceAndAppStatus = DeviceAndAppStatus.DEVICE_NOT_FOUND; } else if (deviceList.Count == 1) { error = null; List <string> packageList = null; adbUtilitiesInstance.GetPackageList(out packageList, out error); if (!(packageList == null)) { if (packageList.Contains(finalPackageName)) { currentDeviceAndAppStatus = DeviceAndAppStatus.APP_INSTALLED; } else { currentDeviceAndAppStatus = DeviceAndAppStatus.APP_NOT_FOUND; } } else { currentDeviceAndAppStatus = DeviceAndAppStatus.UNKNOWN; } } else if (deviceList.Count > 1) { currentDeviceAndAppStatus = DeviceAndAppStatus.DEVICE_MULTIPLE; } else { currentDeviceAndAppStatus = DeviceAndAppStatus.UNKNOWN; } } else { currentDeviceAndAppStatus = DeviceAndAppStatus.UNKNOWN; } return(currentDeviceAndAppStatus); }
//Remove device Asset Bundle public static void RemoveDeviceAssetBundles(string loaderAPKPackageName, bool enableADBUtilitiesLog) { string error = null; ADBUtilities adbUtilitiesInstance = new ADBUtilities(enableADBUtilitiesLog); remote_AssetBundlePathAbsolute = androidAppDataPath + "/" + loaderAPKPackageName + "/" + remote_AssetBundlePathRelative; Debug.Log("Remove device Asset Bundle Files from " + remote_AssetBundlePathAbsolute); if (adbUtilitiesInstance.RemoveDirectory(remote_AssetBundlePathAbsolute, out error) == ADBUtilities.adbNormalExitCode) { Debug.Log("Removed Asset Bundle Files from device."); } else { Debug.Log("Error occured when removeing asset bundle from device: " + error); } }
//Uninstall LoaderAPK public static void UninstallLoaderAPK(string loaderAPKPackageName, bool enableADBUtilitiesLog) { //Run adb command to uninstall apk ADBUtilities adbUtilitiesInstance = new ADBUtilities(enableADBUtilitiesLog); string output, error; string[] command = { "-d shell", "pm uninstall", loaderAPKPackageName }; if (adbUtilitiesInstance.RunADBCommand(command, out output, out error) == ADBUtilities.adbNormalExitCode) { Debug.Log("Loader APK uninstalled successfully"); } else { Debug.Log("Loader APK uninstalled failed with error: " + error); } }
//Push Asset Bundle private static bool PushAssetBundles(string loaderAPKPackageName, bool enableADBUtilitiesLog) { List <string> filesToBePushed = new List <string>(); List <string> filesToBeDeleted = new List <string>(); ADBUtilities adbUtilitiesInstance = new ADBUtilities(enableADBUtilitiesLog); remote_AssetBundlePathAbsolute = androidAppDataPath + "/" + loaderAPKPackageName + "/" + remote_AssetBundlePathRelative; string remote_MasterAssetBundlePathAbsolute = remote_AssetBundlePathAbsolute + "/" + remote_AssetBundlePathRelative; //Debug.Log("remote_AssetBundlePathAbsolute: " + remote_AssetBundlePathAbsolute); local_RemoteAssetBundlePullPathAbsolute = Path.Combine(Directory.GetParent(Application.dataPath).FullName, local_RemoteAssetBundlePullPathRelative).Replace("/", "\\"); //Debug.Log("local_RemoteAssetBundlePullPathAbsolute: " + local_RemoteAssetBundlePullPathAbsolute); if (!Directory.Exists(local_RemoteAssetBundlePullPathAbsolute)) { Directory.CreateDirectory(local_RemoteAssetBundlePullPathAbsolute); Debug.Log("Remote manifest temp directory not found, creating new directory at: " + local_RemoteAssetBundlePullPathAbsolute); } //Check Asset Bundle Manifest //1. Pull remote manifest files string output, error = null; if (adbUtilitiesInstance.PullFiles(remote_MasterAssetBundlePathAbsolute, local_RemoteAssetBundlePullPathAbsolute, out output, out error) == ADBUtilities.adbNormalExitCode) { //Read remote manifest Debug.Log("Reading Remote manifest..."); AssetBundle pulledBundle = AssetBundle.LoadFromFile(Path.Combine(local_RemoteAssetBundlePullPathAbsolute, remote_AssetBundlePathRelative)); if (pulledBundle == null) { Debug.Log("Failed to load pulled remote bundle."); return(false); } AssetBundleManifest pulledManifest = pulledBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); Dictionary <string, Hash128> pulledBundleHashDictionary = new Dictionary <string, Hash128>(); string[] pulledAssetBundles = null; if (pulledManifest != null) { pulledAssetBundles = pulledManifest.GetAllAssetBundles(); foreach (string assetBundle in pulledAssetBundles) { pulledBundleHashDictionary[assetBundle] = pulledManifest.GetAssetBundleHash(assetBundle); Debug.Log("Key: " + assetBundle + " Value: " + pulledBundleHashDictionary[assetBundle] + " added to pulled hash dictionary"); } } pulledBundle.Unload(true); //Read local manifest Debug.Log("Reading Local manifest..."); AssetBundle builtBundle = AssetBundle.LoadFromFile(Path.Combine(local_AssetBundlePathAbsolute, remote_AssetBundlePathRelative)); if (builtBundle == null) { Debug.Log("Failed to load built local bundle."); return(false); } AssetBundleManifest builtManifest = builtBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); Dictionary <string, Hash128> builtBundleHashDictionary = new Dictionary <string, Hash128>(); string[] builtAssetBundles = null; if (builtManifest != null) { builtAssetBundles = builtManifest.GetAllAssetBundles(); foreach (string assetBundle in builtAssetBundles) { builtBundleHashDictionary[assetBundle] = builtManifest.GetAssetBundleHash(assetBundle); Debug.Log("Key: " + assetBundle + " Value: " + builtBundleHashDictionary[assetBundle] + " added to built hash dictionary"); } } builtBundle.Unload(true); //2. Compare Remote manifest files and local manifest files foreach (string builtAssetBundle in builtAssetBundles) { if (!pulledBundleHashDictionary.ContainsKey(builtAssetBundle) || pulledBundleHashDictionary[builtAssetBundle] != builtBundleHashDictionary[builtAssetBundle]) { filesToBePushed.Add(builtAssetBundle); filesToBePushed.Add(builtAssetBundle + assetBundleManifestFileExtension); Debug.Log("Asset Bundle to be pushed: " + builtAssetBundle); } } foreach (string pulledAssetBundle in pulledAssetBundles) { if (!builtBundleHashDictionary.ContainsKey(pulledAssetBundle)) { filesToBeDeleted.Add(pulledAssetBundle); filesToBeDeleted.Add(pulledAssetBundle + assetBundleManifestFileExtension); Debug.Log("Asset Bundle to be deleted: " + pulledAssetBundle); } } //3. Must push Master Bundle and manifest filesToBePushed.Add(remote_AssetBundlePathRelative); filesToBePushed.Add(remote_AssetBundlePathRelative + assetBundleManifestFileExtension); } else { if (output.Contains("does not exist")) { //Create remote directory and add all asset bundles to push list Debug.Log("Creating new asset bundle directory on remote."); if (adbUtilitiesInstance.MakeDirectory(remote_AssetBundlePathAbsolute, out error) == ADBUtilities.adbNormalExitCode) { string[] builtAssetBundlePaths = Directory.GetFiles(local_AssetBundlePathAbsolute); if (builtAssetBundlePaths.Length > 0) { foreach (string builtAssetBundle in builtAssetBundlePaths) { filesToBePushed.Add(Path.Combine(local_AssetBundlePathAbsolute, builtAssetBundle)); Debug.Log("Asset Bundle to be pushed: " + builtAssetBundle); } } } } } //Push Asset Bundles if needed if (filesToBePushed.Count > 0) { foreach (string file in filesToBePushed) { string assetBundleLocalPath = Path.Combine(local_AssetBundlePathAbsolute, file); adbUtilitiesInstance.PushFiles(assetBundleLocalPath, remote_AssetBundlePathAbsolute); } Debug.Log("Number of bundles pushed: " + filesToBePushed.Count / 2); } //Delete Assest Bundles if needed if (filesToBeDeleted.Count > 0) { foreach (string file in filesToBeDeleted) { string assetBundleDevicePath = remote_AssetBundlePathAbsolute + "/" + Path.GetFileName(file); adbUtilitiesInstance.RemoveFile(assetBundleDevicePath); Debug.Log("Remove: " + assetBundleDevicePath); } Debug.Log("Number of bundles deleted: " + filesToBeDeleted.Count / 2); } //Clear pulled files if (Directory.Exists(local_RemoteAssetBundlePullPathAbsolute)) { string[] subDirectories = Directory.GetDirectories(local_RemoteAssetBundlePullPathAbsolute); if (subDirectories.Length > 0) { foreach (string directory in subDirectories) { string[] filePaths = Directory.GetFiles(directory); foreach (string file in filePaths) { File.Delete(file); } Directory.Delete(directory); } } } return(true); }