diff --git a/gpii/node_modules/deviceReporter/deviceReporter.js b/gpii/node_modules/deviceReporter/deviceReporter.js new file mode 100644 index 0000000..ee9b7e4 --- /dev/null +++ b/gpii/node_modules/deviceReporter/deviceReporter.js @@ -0,0 +1,49 @@ +/*! +GPII Android Device Reporter + +Copyright 2014 Emergya + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +// Currently we need to do this in order to work correctly with + +(function () { + "use strict"; + + var fluid = require("universal"); + var gpii = fluid.registerNamespace("gpii"); + + fluid.registerNamespace("gpii.androidDeviceReporter"); + + fluid.defaults("gpii.androidDeviceReporter.findService", { + gradeNames: "fluid.function", + argumentMap: { + name: 0 + } + }); + + fluid.defaults("gpii.androidDeviceReporter.findApplication", { + gradeNames: "fluid.function", + argumentMap: { + name: 0 + } + }); + + gpii.androidDeviceReporter.findService = function (name) { + return gpii.androidDeviceReporter.deviceInfoCache.Services.some(function (srv) { + return srv === name; + }); + }; + + gpii.androidDeviceReporter.findApplication = function (name) { + return gpii.androidDeviceReporter.deviceInfoCache.Applications.some(function (app) { + return app === name; + }); + }; + +})(); diff --git a/gpii/node_modules/deviceReporter/deviceReporterTests.js b/gpii/node_modules/deviceReporter/deviceReporterTests.js new file mode 100644 index 0000000..46a5b72 --- /dev/null +++ b/gpii/node_modules/deviceReporter/deviceReporterTests.js @@ -0,0 +1,75 @@ +/* + * GPII Android Device Reporter Tests + * + * Copyright 2013, 2014, 2015 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ + +var thatall = this; + +(function () { + "use strict"; + + var fluid = require("universal"), + gpii = fluid.registerNamespace("gpii"), + jqUnit = fluid.require("jqUnit"), + bridge = require("bridge"), + androidDeviceReporter = bridge.load("net.gpii.AndroidDeviceReporterImpl", + thatall); + + jqUnit.module("GPII Android deviceReporter"); + + jqUnit.test("Running tests for deviceReporter node module", function () { + // Check if all required methods are available through the java bridge + // + var methods = ["getJSONOutput"]; + + for (var method in methods) { + jqUnit.assertTrue("Checking availability of method '" + method + "'", + (methods[method] in androidDeviceReporter)); + } + + jqUnit.assertNotEquals("'getJSONOutput' does not return an empty object", + androidDeviceReporter.getJSONOutput(), + null); + + // Check information that JSONOutput must contain + // + var deviceInfoCache = JSON.parse(androidDeviceReporter.getJSONOutput()); + + var fields = ["Device", "Model", "Manufacturer", "Product", "Brand", + "CPU", "rootAccess", "OS Version", "Build name", + "Kernel Version", "OS API Level", "Applications", + "Services"]; + + for (var field in fields) { + jqUnit.assertTrue("Checking availability of field '" + field + "'", + (fields[field] in deviceInfoCache)); + } + + // Check find methods + // + require("deviceReporter"); + + fluid.registerNamespace("gpii.androidDeviceReporter"); + gpii.androidDeviceReporter.deviceInfoCache = deviceInfoCache; + + jqUnit.assertNotEquals("Testing gpii.androidDeviceReporter.findApplication with a non-existent app name", + gpii.androidDeviceReporter.findApplication("should.not.exist"), true); + + jqUnit.assertTrue("Testing gpii.androidDeviceReporter.findService", + gpii.androidDeviceReporter.findService("android")); + + + }); + +})(); diff --git a/gpii/node_modules/deviceReporter/index.js b/gpii/node_modules/deviceReporter/index.js new file mode 100644 index 0000000..fad803a --- /dev/null +++ b/gpii/node_modules/deviceReporter/index.js @@ -0,0 +1,26 @@ +/*! +GPII Android Activity Manager + +Copyright 2014 Emergya + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ +var fluid = require("universal"); + +var loader = fluid.getLoader(__dirname); + +loader.require("./deviceReporter.js"); + +// Initialize the Device Reporter at the very beginning and avoid a delay when +// a user is logging in into the system. +// +var gpii = fluid.registerNamespace("gpii"); +fluid.registerNamespace("gpii.androidDeviceReporter"); + +var bridge = require("bridge"); +var deviceReporter = bridge.load("net.gpii.AndroidDeviceReporterImpl", this); +gpii.androidDeviceReporter.deviceInfoCache = JSON.parse(deviceReporter.getJSONOutput()); diff --git a/gpii/node_modules/deviceReporter/package.json b/gpii/node_modules/deviceReporter/package.json new file mode 100644 index 0000000..00f9e68 --- /dev/null +++ b/gpii/node_modules/deviceReporter/package.json @@ -0,0 +1,19 @@ +{ + "name": "deviceReporter", + "description": "This module provides information about the device.", + "version": "0.1", + "author": "Javier Hernández", + "bugs": "http://wiki.gpii.net/index.php/Main_Page", + "homepage": "http://gpii.net/", + "dependencies": {}, + "licenses": [ + { + "type": "BSD-3-Clause", + "url": "http://www.opensource.org/licenses/BSD-3-Clause" + } + ], + "keywords": ["gpii", "accessibility", "settings", "fluid"], + "repository": "git://github.com:GPII/android.git", + "main": "./index.js", + "engines": { "node" : ">=0.1.9" } +} diff --git a/index.js b/index.js index ba02fff..5c02ff6 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,11 @@ var fluid = require("universal"); fluid.module.register("gpii-android", __dirname, require); +// Settings Handlers & Lifecycle Actions-related modules fluid.require("activitymanager", require); fluid.require("androidSettings", require); fluid.require("audioManager", require); fluid.require("persistentConfiguration", require); + +// Android Device Reporter +fluid.require("deviceReporter", require); diff --git a/platform/app/ant.properties b/platform/app/ant.properties index d530201..0c1e2ef 100644 --- a/platform/app/ant.properties +++ b/platform/app/ant.properties @@ -16,4 +16,4 @@ # The password will be asked during the build when you use the 'release' target. #source.dir=src;${env.ANODE_ROOT}/bridge-java/src;${env.ANODE_ROOT}/libnode/src;../anodeshare/src;../intents/src;../a11yservices/src -source.dir=src;${env.ANODE_ROOT}/bridge-java/src;${env.ANODE_ROOT}/libnode/src;../anodeshare/src;../intents/src;../a11yservices/src;../androidSettings/src;../audioManager/src;../persistentconfig/src;libs +source.dir=src;${env.ANODE_ROOT}/bridge-java/src;${env.ANODE_ROOT}/libnode/src;../anodeshare/src;../intents/src;../a11yservices/src;../androidSettings/src;../audioManager/src;../persistentconfig/src;../devicereporter/src;libs diff --git a/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporter.java b/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporter.java new file mode 100644 index 0000000..ffe8510 --- /dev/null +++ b/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporter.java @@ -0,0 +1,10 @@ +package net.gpii; + +import org.meshpoint.anode.bridge.Env; +import org.meshpoint.anode.java.Base; + +public abstract class AndroidDeviceReporter extends Base { + private static short classId = Env.getInterfaceId(AndroidDeviceReporter.class); + public AndroidDeviceReporter() { super(classId); } + public abstract String getJSONOutput(); +} diff --git a/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporterImpl.java b/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporterImpl.java new file mode 100644 index 0000000..5b66ae6 --- /dev/null +++ b/platform/devicereporter/src/net/gpii/AndroidDeviceReporter/AndroidDeviceReporterImpl.java @@ -0,0 +1,733 @@ +package net.gpii; + +/* + +DeviceReporterEngine +This class explores hardware and software on the device to make the Device reporter results list. + + Copyright (c) 2013, Technosite R&D + All rights reserved. +The research leading to these results has received funding from the European Union's Seventh Framework Programme (FP7/2007-2013) under grant agreement n° 289016 + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +   list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +   this list of conditions and the following disclaimer in the documentation +   and/or other materials provided with the distribution. + * Neither the name of Technosite R&D nor the names of its contributors may +   be used to endorse or promote products derived from this software without +   specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + */ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import android.annotation.SuppressLint; +import android.bluetooth.BluetoothAdapter; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.res.Configuration; +import android.graphics.Point; +import android.hardware.Camera; +import android.hardware.Camera.CameraInfo; +import android.hardware.Sensor; +import android.hardware.SensorManager; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbManager; +import android.media.AudioManager; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.nfc.NfcAdapter; +import android.nfc.NfcManager; +import android.os.BatteryManager; +import android.os.Build; +import android.os.Environment; +import android.speech.tts.TextToSpeech; +import android.telephony.TelephonyManager; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.Display; +import android.view.WindowManager; + +import org.meshpoint.anode.AndroidContext; +import org.meshpoint.anode.module.IModule; +import org.meshpoint.anode.module.IModuleContext; +import org.json.JSONObject; +import org.json.JSONException; + +public class AndroidDeviceReporterImpl extends AndroidDeviceReporter implements IModule { + private static final String TAG = "net.gpii.AndroidDeviceReporterImpl"; + + IModuleContext ctx; + private Context androidContext; + + private JSONObject jsonResults = new JSONObject(); + + private HashMapresults = new HashMap(); + + public Map getResults() { + return (Map) this.results; + } + + @Override + public Object startModule(IModuleContext ctx) { + Log.v(TAG, "AndroidDeviceReporterImpl.startModule()"); + this.ctx = ctx; + this.androidContext = ((AndroidContext) ctx).getAndroidContext(); + + return this; + } + + @Override + public void stopModule() { + Log.v(TAG, "AndroidDeviceReporterImpl.stopModule()"); + } + + @Override + public String getJSONOutput() { + getDataAboutDevice(); + getDataAboutOperatingSystem(androidContext); + //getDataAboutHardware(androidContext); + //getDataAboutSensors(androidContext); + //getDataAboutSound(androidContext); + //getDataAboutScreen(androidContext); + + //JSONObject output = new JSONObject(results); + + return jsonResults.toString(); + } + + // *** Device reporter getters + + // ** Software + + private void getDataAboutDevice() { + try { + jsonResults.put("Device" , android.os.Build.DEVICE); + jsonResults.put("Model" , android.os.Build.MODEL); + jsonResults.put("Manufacturer" , android.os.Build.MANUFACTURER); + jsonResults.put("Product" , android.os.Build.PRODUCT); + jsonResults.put("Brand" , android.os.Build.BRAND); + jsonResults.put("CPU" , android.os.Build.CPU_ABI); + jsonResults.accumulate("CPU", android.os.Build.CPU_ABI2); + + if (isDeviceRooted()) { + jsonResults.put("rootAccess", "yes"); + } else { + jsonResults.put("rootAccess", "no"); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private void getDataAboutOperatingSystem(Context ct) { + try { + jsonResults.put("OS Version", "Android " + android.os.Build.VERSION.RELEASE ); + jsonResults.put("Build name" , android.os.Build.FINGERPRINT); + jsonResults.put("Kernel Version", System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")"); + jsonResults.put("OS API Level" , String.valueOf(android.os.Build.VERSION.SDK_INT)); + + // Services and Installed Applications + // + PackageManager packageManager = ct.getPackageManager(); + List applicationList = packageManager.getInstalledApplications (0); + if (applicationList.size()>0) { + for (int i=0; i packageList = packageManager.getInstalledPackages (PackageManager.GET_SERVICES); + for (int i=0; i=12) { + HashMap deviceList = usb.getDeviceList(); + Iterator> it = deviceList.entrySet().iterator(); + int c = 1; + if (it.hasNext()) { + while (it.hasNext()) { + Map.Entry e = (Map.Entry) it.next(); + results.put("USB attached device " + String.valueOf(c), e.getKey()); + c++; + } + } else results.put("USB attached device", "None"); + } + } else results.put("USB", "Not supported"); + } catch (Exception e) { + results.put("USB", "Not supported\nError:" + e.toString()); + } + + // Keyboard + results.put("System board" , android.os.Build.BOARD); + boolean keyboardPresent = (ct.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS); + results.put("Keyboard hardware" , String.valueOf(keyboardPresent)); + + switch (ct.getResources().getConfiguration().keyboard ) { + case Configuration.KEYBOARD_12KEY : + results.put("Keyboard type", "Numeric"); + break; + case Configuration.KEYBOARD_QWERTY : + results.put("Keyboard type", "Qwerty"); + break; + case Configuration.KEYBOARD_NOKEYS : + results.put("Keyboard type", "No keys"); + break; + default : + results.put("Keyboard type", "UNKNOWN"); + break; + } + + // Navigation mode + switch (ct.getResources().getConfiguration().navigation) { + case Configuration.NAVIGATION_TRACKBALL : + results.put("Navigator mode", "Trackball"); + break; + case Configuration.NAVIGATION_WHEEL : + results.put("Navigator mode", "Wheel"); + break; + case Configuration.NAVIGATION_DPAD : + results.put("Navigator mode", "DPad"); + break; + case Configuration.NAVIGATION_NONAV : + results.put("Navigator mode", "None"); + break; + case Configuration.NAVIGATION_UNDEFINED : + results.put("Navigator mode", "Unknown"); + break; + } + + // Battery + try + { + IntentFilter batIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent battery = ct.registerReceiver(null, batIntentFilter); + int batteryLevel = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); + int batteryStatus = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); + boolean isCharging = (batteryStatus == BatteryManager.BATTERY_STATUS_CHARGING || batteryStatus == BatteryManager.BATTERY_STATUS_FULL); + boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; + boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; + results.put("Battery level", String.valueOf(batteryLevel)); + results.put("Battery charging", String.valueOf(isCharging)); + if (isCharging) { + if (usbCharge ) results.put("Battery charging mode", "USB"); + else if (acCharge) results.put("Battery charging mode", "AC "); + else results.put("Battery charging mode", "UNKNOWN"); + } + } + catch (Exception e) + { + results.put("Battery level", "UNKNOWN"); + } + } + + @SuppressLint("NewApi") + private void getDataAboutSensors(Context ct) { + // Wifi + try { + WifiManager wifi = (WifiManager) ct.getSystemService(Context.WIFI_SERVICE); + if (wifi!=null) { + results.put("Wifi", "Supported"); + if (wifi.isWifiEnabled()) { + results.put("Wifi state", "Enabled"); + WifiInfo info = wifi.getConnectionInfo(); + results.put("Wifi SSID", info.getSSID()); + results.put("Wifi BSSID", info.getBSSID()); + results.put("Wifi Mac address", info.getMacAddress()); + results.put("Wifi network Id", String.valueOf(info.getNetworkId() )); + results.put("Wifi IP address", String.valueOf(info.getIpAddress() )); + results.put("Wifi link speed", String.valueOf(info.getLinkSpeed() )); + results.put("Wifi Rssi", String.valueOf(info.getRssi() )); + } else results.put("Wifi state", "Disabled"); + } else results.put("Wifi", "Not supported"); + } catch (Exception e) { + results.put("Wifi", "Not supported\nError:" + e.toString()); + } + + // Bluetooth + try { + BluetoothAdapter bluetoothLocalAdapter = BluetoothAdapter.getDefaultAdapter(); + if (bluetoothLocalAdapter!= null) { + results.put("Bluetooth", "Supported"); + results.put("Bluetooth address", bluetoothLocalAdapter.getAddress()); + results.put("Bluetooth name", bluetoothLocalAdapter.getName()); + switch (bluetoothLocalAdapter.getState()) { + case android.bluetooth.BluetoothAdapter.STATE_OFF : + results.put("Bluetooth state", "Off"); + break; + case android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF : + results.put("Bluetooth state", "Turning off"); + break; + case android.bluetooth.BluetoothAdapter.STATE_ON : + results.put("Bluetooth state", "On"); + break; + case android.bluetooth.BluetoothAdapter.STATE_TURNING_ON : + results.put("Bluetooth state", "Turning on"); + break; + case android.bluetooth.BluetoothAdapter.STATE_CONNECTED : + results.put("Bluetooth state", "Connected"); + break; + case android.bluetooth.BluetoothAdapter.STATE_CONNECTING : + results.put("Bluetooth state", "Connecting"); + break; + case android.bluetooth.BluetoothAdapter.STATE_DISCONNECTED : + results.put("Bluetooth state", "Disconnected"); + break; + case android.bluetooth.BluetoothAdapter.STATE_DISCONNECTING : + results.put("Bluetooth state", "Disconnecting"); + break; + } + } else { + results.put("Bluetooth", "Not supported"); + } + } catch (Exception e) { + results.put("Bluetooth", "Not supported\nError:" + e.toString()); + } + + // NFC + NfcManager nfcManager = (NfcManager) ct.getSystemService(Context.NFC_SERVICE); + NfcAdapter nfc = nfcManager.getDefaultAdapter(); + if (nfc != null) { + results.put("NFC", "Supported"); + results.put("NFC enabled", String.valueOf(nfc.isEnabled() )); + if (Build.VERSION.SDK_INT>=16) results.put("NFC NDefPush enabled", String.valueOf(nfc.isNdefPushEnabled() )); + } else results.put("NFC", "Not supported"); + + // Camera + int numCameras = android.hardware.Camera.getNumberOfCameras(); + if (numCameras > 0 ) { + results.put("Cameras", String.valueOf(numCameras)); + for (int i=0;i sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); + for (int i=0;i=14) { + mTts.shutdown(); + } + } + } catch (Exception e) { + results.put("TTS supported", "No:\n Error:" + e.toString()); + } + + + // Sound device + AudioManager audioManager = (AudioManager) ct.getSystemService(Context.AUDIO_SERVICE); + if (audioManager != null) { + results.put("Sound system volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM))); + results.put("Sound music volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC))); + results.put("Sound alarm volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_ALARM))); + results.put("Sound ring volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_RING))); + results.put("Sound voice call volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL ))); + results.put("Sound notification volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION))); + results.put("Sound DTMF volume", String.valueOf(audioManager.getStreamVolume(AudioManager.STREAM_DTMF))); + results.put("Max sound system volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM))); + results.put("Max sound music volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC))); + results.put("Max sound alarm volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM))); + results.put("Max sound ring volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_RING))); + results.put("Max sound voice call volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL ))); + results.put("Max sound notification volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION))); + results.put("Max sound DTMF volume", String.valueOf(audioManager.getStreamMaxVolume(AudioManager.STREAM_DTMF))); + + int audioStatus = audioManager.getMode(); + switch (audioStatus) { + case AudioManager.MODE_NORMAL : + results.put("Audio mode", "Normal"); + break; + case AudioManager.MODE_RINGTONE : + results.put("Audio mode", "Ringtone"); + break; + case AudioManager.MODE_IN_CALL : + results.put("Audio mode", "In call"); + break; + case AudioManager.MODE_IN_COMMUNICATION : + results.put("Audio mode", "In communication"); + break; + case AudioManager.MODE_INVALID : + results.put("Audio mode", "Invalid"); + break; + } + // Sound flags + results.put("Wired eadsets", String.valueOf(audioManager.isWiredHeadsetOn())); + results.put("Bluetooth Sco", String.valueOf(audioManager.isBluetoothScoOn())); + results.put("Bluetooth Sco available off call", String.valueOf(audioManager.isBluetoothScoAvailableOffCall())); + results.put("Microphone muted", String.valueOf(audioManager.isMicrophoneMute())); + results.put("Music active", String.valueOf(audioManager.isMusicActive())); + results.put("Speaker phone", String.valueOf(audioManager.isSpeakerphoneOn())); + results.put("Bluetooth A2dp speaker", String.valueOf(audioManager.isBluetoothA2dpOn())); + } else { // Errors getting info about Sound device + results.put("Sound volume", "UNKNOWN"); + } + } + + @SuppressLint("NewApi") + private void getDataAboutScreen(Context ct) { + WindowManager wm = (WindowManager) ct.getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + + if (Build.VERSION.SDK_INT<=16){ // Android 4.0 and lowers + if (Build.VERSION.SDK_INT>13){ + Point size = new Point(); + display.getSize(size); + results.put("Screen width", String.valueOf(size.x)); + results.put("Screen height", String.valueOf(size.y)); + } else { + try { + Method mGetRawH = Display.class.getMethod("getRawHeight"); + Method mGetRawW = Display.class.getMethod("getRawWidth"); + results.put("Screen width",String.valueOf((Integer) mGetRawW.invoke(display))); + results.put("Screen height", String.valueOf((Integer) mGetRawH.invoke(display))); + } catch (Exception e) { + Log.d("Error", "\n Error accessing to video data."); + results.put("Screen width", "UNKNOWN"); + results.put("Screen height", "UNKNOWN"); + } + } + } else { // Android 4.1 or highers + DisplayMetrics displayMetrics = new DisplayMetrics(); + display.getRealMetrics(displayMetrics); + results.put("Screen width", String.valueOf(displayMetrics.widthPixels)); + results.put("Screen height", String.valueOf(displayMetrics.heightPixels)); + } + results.put("Density DPI" , String.valueOf(ct.getResources().getConfiguration().densityDpi)); + results.put("Font scale" , String.valueOf(ct.getResources().getConfiguration().fontScale)); + //Screen orientation)) + switch (ct.getResources().getConfiguration().orientation) { + case Configuration.ORIENTATION_LANDSCAPE : + results.put("Screen orientation", "Landscape"); + break; + case Configuration.ORIENTATION_PORTRAIT : + results.put("Screen orientation", "Portrait"); + break; + } + // Type of Touch screen + results.put("Touch screen", String.valueOf((ct.getResources().getConfiguration().touchscreen != Configuration. + TOUCHSCREEN_NOTOUCH))); + } + + // CheckForRoot management + + private static String LOG_TAG = AndroidDeviceReporterImpl.class.getName(); + + public static enum SHELL_CMD { + check_su_binary(new String[] { "su", "-c", "ls /" }), ; + + String[] command; + + SHELL_CMD(String[] command) { + this.command = command; + } + } + + /* + * Three method to check the root permissions + */ + public boolean isDeviceRooted() { + if (checkRootMethod1()) { + Log.d(LOG_TAG, "method 1: true"); + return true; + } + if (checkRootMethod2()) { + Log.d(LOG_TAG, "method 2: true"); + return true; + } + if (checkRootMethod3()) { + Log.d(LOG_TAG, "method 3: true"); + return true; + } + return false; + } + + /* + * Method 1, check the SO builds Tags, Usually don't response with the + * correct answer + */ + public boolean checkRootMethod1() { + String buildTags = android.os.Build.TAGS; + + if (buildTags != null && buildTags.contains("test-keys")) { + return true; + } + return false; + } + + /* + * Method 2, If exists Superuser.apk, you can access as SuperUser. Usually, + * if the device is root, this method return true. + */ + public boolean checkRootMethod2() { + try { + File file = new File("/system/app/Superuser.apk"); + if (file.exists()) { + return true; + } + } catch (Exception e) { + } + + return false; + } + + /* + * Method 2, check thought the shell. If you can exec su, the device is + * root. + */ + public boolean checkRootMethod3() { + if (executeCommand(SHELL_CMD.check_su_binary) != null) { + return true; + } else { + return false; + } + } + + public ArrayList executeCommand(SHELL_CMD shellCmd) { + String line = null; + ArrayList fullResponse = new ArrayList(); + Process localProcess = null; + + try { + localProcess = Runtime.getRuntime().exec(shellCmd.command); + } catch (Exception e) { + + e.printStackTrace(); + return null; + } + + BufferedWriter out = new BufferedWriter(new OutputStreamWriter( + localProcess.getOutputStream())); + BufferedReader in = new BufferedReader(new InputStreamReader( + localProcess.getInputStream())); + + try { + while ((line = in.readLine()) != null) { + Log.d(LOG_TAG, "--> Line received: " + line); + fullResponse.add(line); + } + } catch (Exception e) { + e.printStackTrace(); + } + + Log.d(LOG_TAG, "--> Full response was: " + fullResponse); + + return fullResponse; + } + +} diff --git a/platform/devicereporter/src/org/meshpoint/anode/stub/gen/platform/Net_gpii_AndroidDeviceReporter.java b/platform/devicereporter/src/org/meshpoint/anode/stub/gen/platform/Net_gpii_AndroidDeviceReporter.java new file mode 100644 index 0000000..b66d3aa --- /dev/null +++ b/platform/devicereporter/src/org/meshpoint/anode/stub/gen/platform/Net_gpii_AndroidDeviceReporter.java @@ -0,0 +1,15 @@ +/* This file has been automatically generated; do not edit */ + +package org.meshpoint.anode.stub.gen.platform; + +public final class Net_gpii_AndroidDeviceReporter { + + private static Object[] __args = new Object[0]; + + public static Object[] __getArgs() { return __args; } + + static Object __invoke(net.gpii.AndroidDeviceReporter inst, int opIdx, Object[] args) { + return inst.getJSONOutput(); + } + +} diff --git a/platform/makestubs.sh b/platform/makestubs.sh index 76b66c4..3759e14 100644 --- a/platform/makestubs.sh +++ b/platform/makestubs.sh @@ -6,3 +6,4 @@ java -jar ./anode/sdk/java/tools/stubgen.jar --verbose --out ./androidSettings/s java -jar ./anode/sdk/java/tools/stubgen.jar --verbose --out ./androidSettings/src --classpath ./app/bin/classes net.gpii.AndroidSettings java -jar ./anode/sdk/java/tools/stubgen.jar --verbose --out ./audioManager/src --classpath ./app/bin/classes net.gpii.AndroidAudioManager java -jar ./anode/sdk/java/tools/stubgen.jar --verbose --out ./persistentconfig/src --classpath ./app/bin/classes net.gpii.AndroidPersistentConfiguration +java -jar ./anode/sdk/java/tools/stubgen.jar --verbose --out ./devicereporter/src --classpath ./app/bin/classes net.gpii.AndroidDeviceReporter