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