Last active
August 29, 2015 14:12
-
-
Save thurask/04dc9607d000ad4e1826 to your computer and use it in GitHub Desktop.
escreens uptime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| |
package rim.escreens.security { | |
import flash.display.*; | |
import flash.errors.*; | |
import qnx.system.*; | |
import flash.filesystem.*; | |
public class EScreenSecurityData extends Sprite { | |
private static | |
const SYS_INFO: string = "/var/boottime.txt"; | |
private static | |
const COLON: string = ":"; | |
private static | |
const HOUR: number = 3600000; | |
private static | |
const MINUTES: number = 60000; | |
private | |
var __pin: string; | |
private | |
var __uptime: string; | |
private | |
var __osVersion: string; | |
private | |
var __batteryLevel: int; | |
private | |
var __vendorID: int; | |
private | |
var __serialNumber: string; | |
private | |
var __systemInfo: string; | |
public | |
function EScreenSecurityData() { | |
this.updateItems(); | |
} | |
public | |
function destroy(): void { | |
this.__pin = null; | |
this.__uptime = null; | |
this.__osVersion = null; | |
this.__batteryLevel = 0; | |
this.__vendorID = 0; | |
this.__serialNumber = null; | |
this.__systemInfo = null; | |
} | |
public | |
function get pin(): string { | |
return (this.__pin); | |
} | |
public | |
function get osVersion(): string { | |
return (this.__osVersion); | |
} | |
public | |
function get uptime(): string { | |
return (this.__uptime); | |
} | |
public | |
function get batteryLevel(): int { | |
return (this.__batteryLevel); | |
} | |
public | |
function get vendorID(): int { | |
return (this.__vendorID); | |
} | |
public | |
function serialNumber(): string { | |
return (this.__serialNumber); | |
} | |
private | |
function updateItems(): void { | |
var bootTime: * = null; | |
var systeminfoStream: * = new FileStream(); | |
var open: * = false; | |
try { | |
systeminfoStream.open(new File(SYS_INFO), FileMode.READ); | |
open = true; | |
} catch (error: IOError) { | |
Logger.logger.log(Logger.error, "IOError when opening systemInfo file"); | |
}; | |
if (open) { | |
bootTime = systeminfoStream.readUTFBytes(systeminfoStream.bytesAvailable); | |
systeminfoStream.close(); | |
this.convertToUpTime(bootTime); | |
}; | |
var device: * = Device.device; | |
if (device) { | |
this.__pin = this.formatPIN(device.pin); | |
this.__osVersion = device.scmBundle; | |
this.__batteryLevel = device.batteryLevel; | |
this.__vendorID = device.vendorID; | |
this.__serialNumber = device.serialNumber; | |
}; | |
} | |
private | |
function convertToUpTime(_arg1: string): void { | |
var _local4: number; | |
var _local5: number; | |
var _local6: array; | |
var _local7: number; | |
var _local8: number; | |
var _local9: number; | |
var _local10: string; | |
var _local11: number; | |
var _local12: number; | |
var _local13: number; | |
var _local14: date; | |
var _local2: array = _arg1.split(" "); | |
var _local3: date = new date(); | |
if (_local2.length > 0) { | |
_local4 = number(this.getShortMonthIndex(_local2.shift())); | |
_local5 = number(_local2.shift()); | |
_local6 = _local2.shift().split(COLON); | |
if (_local6.length > 0) { | |
_local7 = _local6.shift(); | |
_local8 = _local6.shift(); | |
_local9 = _local6.shift(); | |
}; | |
_local10 = _local2.shift(); | |
_local11 = _local2.shift(); | |
_local12 = date.utc(_local11, _local4, _local5, _local7, _local8, _local9, 0); | |
_local13 = this.handleTimeZone(_local10); | |
_local14 = new date((_local12 - _local13)); | |
this.__uptime = string((_local3.gettime() - _local14.gettime())); | |
}; | |
} | |
private | |
function getShortMonthIndex(_arg1: string): int { | |
switch (_arg1.touppercase()) { | |
case "JAN": | |
return (0); | |
case "FEB": | |
return (1); | |
case "MAR": | |
return (2); | |
case "APR": | |
return (3); | |
case "MAY": | |
return (4); | |
case "JUN": | |
return (5); | |
case "JUL": | |
return (6); | |
case "AUG": | |
return (7); | |
case "SEP": | |
return (8); | |
case "OCT": | |
return (9); | |
case "NOV": | |
return (10); | |
case "DEC": | |
return (11); | |
}; | |
return (0); | |
} | |
private | |
function handleTimeZone(_arg1: string): number { | |
var _local3: number; | |
var _local4: number; | |
var _local5: number; | |
var _local2: number = 0; | |
if (_arg1.search(/\d/) == -1) { | |
switch (_arg1) { | |
case "UT": | |
_local2 = 0; | |
break; | |
case "UTC": | |
_local2 = 0; | |
break; | |
case "GMT": | |
_local2 = 0; | |
break; | |
case "EST": | |
_local2 = (-5 * HOUR); | |
break; | |
case "EDT": | |
_local2 = (-4 * HOUR); | |
break; | |
case "CST": | |
_local2 = (-6 * HOUR); | |
break; | |
case "CDT": | |
_local2 = (-5 * HOUR); | |
break; | |
case "MST": | |
_local2 = (-7 * HOUR); | |
break; | |
case "MDT": | |
_local2 = (-6 * HOUR); | |
break; | |
case "PST": | |
_local2 = (-8 * HOUR); | |
break; | |
case "PDT": | |
_local2 = (-7 * HOUR); | |
break; | |
case "Z": | |
_local2 = 0; | |
break; | |
case "A": | |
_local2 = (-1 * HOUR); | |
break; | |
case "M": | |
_local2 = (-12 * HOUR); | |
break; | |
case "N": | |
_local2 = (1 * HOUR); | |
break; | |
case "Y": | |
_local2 = (12 * HOUR); | |
break; | |
default: | |
_local2 = 0; | |
}; | |
} else { | |
_local3 = 1; | |
_local4 = 0; | |
_local5 = 0; | |
if (_arg1.length != 4) { | |
if (_arg1.charat(0) == "-") { | |
_local3 = -1; | |
}; | |
_arg1 = _arg1.substr(1, 4); | |
}; | |
_local4 = number(_arg1.substr(0, 2)); | |
_local5 = number(_arg1.substr(2, 2)); | |
_local2 = (((_local4 * HOUR) + (_local5 * MINUTES)) * _local3); | |
}; | |
return (_local2); | |
} | |
private | |
function formatPIN(_arg1: string): string { | |
return (parseint(_arg1).tostring(16).tolowercase()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment