
/*

CLASS {NATIVE_Hardware|_Android},
UNTESTED:

NATIVE: "///COPY NATIVE_Hardware.java" .

*/


//import android.content.*;
//import android.widget.*;
//import android.app.AlertDialog;
//import android.view.*;
import java.io.*;
import java.util.*;
//import android.graphics.Paint;
import android.os.Environment;
import android.util.*;
//import android.graphics.drawable.Drawable;
//import android.graphics.*;
import android.os.StatFs;

public class NATIVE_Hardware
{

    //public static uint Do_Get_system_drives()
    //{
    //    return 0;
    //}
	
    //[DllImport("kernel32", SetLastError = true)]
    //private static extern IntPtr CreateFile
    //    (string filename, uint desiredAccess,
    //        uint shareMode, IntPtr securityAttributes,
    //        int creationDisposition, int flagsAndAttributes,
    //        IntPtr templateFile);
    //[DllImport("kernel32")]
    //private static extern int DeviceIoControl
    //    (IntPtr deviceHandle, uint ioControlCode,
    //        IntPtr inBuffer, int inBufferSize,
    //        IntPtr outBuffer, int outBufferSize,
    //        ref int bytesReturned, IntPtr overlapped);
    //[DllImport("kernel32.dll", SetLastError = true)]
    //[return: MarshalAs(UnmanagedType.Bool)]
    //private static extern bool CloseHandle(IntPtr hObject);
	
    //const uint GENERIC_READ = 0x80000000;
    //const uint GENERIC_WRITE = 0x40000000;
    //const uint FILE_SHARE_READ = 0x1;
    //const uint FILE_SHARE_WRITE = 0x2;
    //const uint IOCTL_STORAGE_EJECT_MEDIA = 0x2D4808;
	
    //public static bool EjectDrive(char driveLetter)
    //{
    //    string path = @"\\.\" + driveLetter + @":";
    //    IntPtr handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE,
    //    FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, 0x3, 0, IntPtr.Zero);
	
    //    if ((long)handle == -1)
    //    {
    //        return false;
    //    }
	
    //    int dummy = 0;
	
    //    DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0,
    //        IntPtr.Zero, 0, ref dummy, IntPtr.Zero);
	
    //    CloseHandle(handle);
    //    return true;
    //}
	
	
	
    //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    //static extern bool GlobalMemoryStatusEx( [In,Out] MEMORYSTATUSEX lpBuffer);
    //[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    //public class MEMORYSTATUSEX
    //{
    //    public uint dwLength;
    //    public uint dwMemoryLoad;
    //    public ulong ullTotalPhys;
    //    public ulong ullAvailPhys;
    //    public ulong ullTotalPageFile;
    //    public ulong ullAvailPageFile;
    //    public ulong ullTotalVirtual;
    //    public ulong ullAvailVirtual;
    //    public ulong ullAvailExtendedVirtual;
    //    public MEMORYSTATUSEX()
    //    {
    //        this.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
    //    }
   //}
   
    //public static void Do_Memory_status(ArrayReal mem)
    //{
    //    MEMORYSTATUSEX gms = new MEMORYSTATUSEX();
    //    GlobalMemoryStatusEx(gms);
    //    mem.Add(gms.dwMemoryLoad);
    //    mem.Add(gms.ullTotalPhys);
    //    mem.Add(gms.ullAvailPhys);
    //    mem.Add(gms.ullTotalPageFile);
    //    mem.Add(gms.ullAvailPageFile);
    //    mem.Add(gms.ullTotalVirtual);
    //    mem.Add(gms.ullAvailExtendedVirtual);
    //}

    //[DllImport(("kernel32.dll"))]
    //static extern bool GetSystemTimes(out double idleTime,
    //    out double kernelTime, out double userTime);
	
    //private static double prev_idle;
    //private static double prev_busy;
	
    //public static double GetCPULoad()
    //{
    //double idleTime, kernelTime, userTime;
    //double idle, busy, delta_idle, delta_busy;
    //    double Result = -1;
    //    if (!GetSystemTimes(out idleTime, out kernelTime, out userTime))
    //        return Result;
    //    idle = idleTime;
    //    busy = kernelTime + userTime;
    //    delta_idle = idle - prev_idle;
    //    delta_busy = busy - prev_busy;
    //    if (prev_busy > 0)
    //    {
    //        if (delta_busy > 0)
    //            Result = (1.0 - delta_idle / delta_busy) * 100.0;
    //        else Result = 0;
    //    }
    //    else Result = 0;
    //    prev_idle = idle;
    //    prev_busy = busy;
    //    return Result;
    //}
 		
    //[DllImport("kernel32.dll")]
    //static extern bool GetSystemPowerStatus(out SYSTEM_POWER_STATUS sps);
	
    //struct SYSTEM_POWER_STATUS {
    //    public byte ACLineStatus;
    //    public byte BatteryFlag;
    //    public byte BatteryLifePercent;
    //    public byte Reserved1;
    //    public uint BatteryLifeTime;
    //    public uint BatteryFullLifeTime;
    //}
	
    //public static double Get_power_status(ArrayInt pow)
    //{
    //    double result = 0;
    //    SYSTEM_POWER_STATUS sps = new SYSTEM_POWER_STATUS();
    //    if (GetSystemPowerStatus(out sps))
    //    {
    //        pow.Add(sps.ACLineStatus);
    //        int flag = 0;
    //        if (sps.BatteryFlag == 255) flag = 1;
    //        if (sps.BatteryFlag != 255)
    //        {
    //            if ((sps.BatteryFlag & 1) != 0) flag |= 2; //high
    //            if ((sps.BatteryFlag & 2) != 0) flag |= 4; //low
    //            if ((sps.BatteryFlag & 4) != 0) flag |= 8; //critical
    //            if ((sps.BatteryFlag & 8) != 0) flag |= 16; //charging
    //            if ((sps.BatteryFlag & 128) != 0) flag |= 32; //no batt
    //        }
    //        if (sps.BatteryLifePercent > 100) flag |= 64;
    //        if (((int)sps.BatteryLifeTime) == -1) flag |= 128;
    //        if (((int)sps.BatteryFullLifeTime) == -1) flag |= 256;
    //        pow.Add(flag);
			
    //        int life_percent = sps.BatteryLifePercent;
    //        result = life_percent;
    //        if ((flag & 256) == 0 && life_percent > 0 && life_percent < 100)
    //            result = sps.BatteryLifeTime * 100.0
    //                / sps.BatteryFullLifeTime;
    //        pow.Add(life_percent);
    //        pow.Add((int)sps.BatteryLifeTime);
    //        pow.Add((int)sps.BatteryFullLifeTime);
    //    }
    //    return result;
    //}
	
	public static long DiskTotalSize(String Path) {
		StatFs stat = new StatFs(
			Environment.getExternalStorageDirectory().getPath());
		long bytes = (long)stat.getBlockSize() * stat.getBlockCountLong();
		return bytes;
	}

	public static long DiskFreeSpace(String Path) {
		StatFs stat = new StatFs(
			Environment.getExternalStorageDirectory().getPath());
		long bytes = (long)stat.getBlockSize() * stat.getAvailableBlocksLong();
		return bytes;
	}

/*

CONST STR:
	NATIVE_Hardware_import = @
	""	

	NATIVE_Get_drives = @
	"	"
	
	NATIVE_Get_drive_type = @
	"	"
	
	NATIVE_Eject_drive = @
	"	"
	
	NATIVE_Disk_volume_label = @
	"	RESULT = "#QU#QU";"	
	
	NATIVE_Disk_total_size = @
	"	RESULT = NATIVE_Hardware.DiskTotalSize(X_disk);"	
	
	NATIVE_Disk_free_space = @
	"	RESULT = NATIVE_Hardware.DiskFreeSpace(X_disk);"	
	
	NATIVE_Memory_status = @
	"//NATIVE_Hardware.Do_Memory_status(X_mem);" //todo
	
	NATIVE_Processor_load = @
	"//RESULT = NATIVE_Hardware.GetCPULoad();" //todo
	
	NATIVE_Processors_count = @
	"	RESULT = Runtime().getRuntime().availableProcessors();"
	
	NATIVE_Power_status = @
	"	//RESULT = NATIVE_Hardware.Get_power_status(X_pow);" //todo
	.

END

*/

}


