Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. package org.apache.cordova.device;
  18. import java.util.TimeZone;
  19. import org.apache.cordova.CordovaWebView;
  20. import org.apache.cordova.CallbackContext;
  21. import org.apache.cordova.CordovaPlugin;
  22. import org.apache.cordova.CordovaInterface;
  23. import org.json.JSONArray;
  24. import org.json.JSONException;
  25. import org.json.JSONObject;
  26. import android.provider.Settings;
  27. public class Device extends CordovaPlugin {
  28. public static final String TAG = "Device";
  29. public static String platform; // Device OS
  30. public static String uuid; // Device UUID
  31. private static final String ANDROID_PLATFORM = "Android";
  32. private static final String AMAZON_PLATFORM = "amazon-fireos";
  33. private static final String AMAZON_DEVICE = "Amazon";
  34. /**
  35. * Constructor.
  36. */
  37. public Device() {
  38. }
  39. /**
  40. * Sets the context of the Command. This can then be used to do things like
  41. * get file paths associated with the Activity.
  42. *
  43. * @param cordova The context of the main Activity.
  44. * @param webView The CordovaWebView Cordova is running in.
  45. */
  46. public void initialize(CordovaInterface cordova, CordovaWebView webView) {
  47. super.initialize(cordova, webView);
  48. Device.uuid = getUuid();
  49. }
  50. /**
  51. * Executes the request and returns PluginResult.
  52. *
  53. * @param action The action to execute.
  54. * @param args JSONArry of arguments for the plugin.
  55. * @param callbackContext The callback id used when calling back into JavaScript.
  56. * @return True if the action was valid, false if not.
  57. */
  58. public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
  59. if ("getDeviceInfo".equals(action)) {
  60. JSONObject r = new JSONObject();
  61. r.put("uuid", Device.uuid);
  62. r.put("version", this.getOSVersion());
  63. r.put("platform", this.getPlatform());
  64. r.put("model", this.getModel());
  65. r.put("manufacturer", this.getManufacturer());
  66. r.put("isVirtual", this.isVirtual());
  67. r.put("serial", this.getSerialNumber());
  68. callbackContext.success(r);
  69. }
  70. else {
  71. return false;
  72. }
  73. return true;
  74. }
  75. //--------------------------------------------------------------------------
  76. // LOCAL METHODS
  77. //--------------------------------------------------------------------------
  78. /**
  79. * Get the OS name.
  80. *
  81. * @return
  82. */
  83. public String getPlatform() {
  84. String platform;
  85. if (isAmazonDevice()) {
  86. platform = AMAZON_PLATFORM;
  87. } else {
  88. platform = ANDROID_PLATFORM;
  89. }
  90. return platform;
  91. }
  92. /**
  93. * Get the device's Universally Unique Identifier (UUID).
  94. *
  95. * @return
  96. */
  97. public String getUuid() {
  98. String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
  99. return uuid;
  100. }
  101. public String getModel() {
  102. String model = android.os.Build.MODEL;
  103. return model;
  104. }
  105. public String getProductName() {
  106. String productname = android.os.Build.PRODUCT;
  107. return productname;
  108. }
  109. public String getManufacturer() {
  110. String manufacturer = android.os.Build.MANUFACTURER;
  111. return manufacturer;
  112. }
  113. public String getSerialNumber() {
  114. String serial = android.os.Build.SERIAL;
  115. return serial;
  116. }
  117. /**
  118. * Get the OS version.
  119. *
  120. * @return
  121. */
  122. public String getOSVersion() {
  123. String osversion = android.os.Build.VERSION.RELEASE;
  124. return osversion;
  125. }
  126. public String getSDKVersion() {
  127. @SuppressWarnings("deprecation")
  128. String sdkversion = android.os.Build.VERSION.SDK;
  129. return sdkversion;
  130. }
  131. public String getTimeZoneID() {
  132. TimeZone tz = TimeZone.getDefault();
  133. return (tz.getID());
  134. }
  135. /**
  136. * Function to check if the device is manufactured by Amazon
  137. *
  138. * @return
  139. */
  140. public boolean isAmazonDevice() {
  141. if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) {
  142. return true;
  143. }
  144. return false;
  145. }
  146. public boolean isVirtual() {
  147. return android.os.Build.FINGERPRINT.contains("generic") ||
  148. android.os.Build.PRODUCT.contains("sdk");
  149. }
  150. }