第一次提交

This commit is contained in:
被淹死的鱼
2026-03-11 18:26:29 +08:00
commit cd3b53759e
8532 changed files with 522078 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.fengliyan.device;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.caivideo.device.test", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fengliyan.device" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

View File

@@ -0,0 +1,253 @@
package com.fengliyan.device;
import android.Manifest;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebSettings;
import com.github.gzuliyujiang.oaid.DeviceIdentifier;
import com.fengliyan.base.base.utils.NoClearSPUtils;
/**
* Created by abby on 2018/4/15.
*/
public class DeviceManager {
private String mImei = "unknown";
private String mVersion = "unknown";
private String mUuid = "";
private String mToken = "";
private Context mContext;
private static DeviceManager mInstance;
private String oAid = "";
public static DeviceManager getInstance() {
if (null == mInstance) {
mInstance = new DeviceManager();
}
return mInstance;
}
private DeviceManager() {
}
public void init(Context context) {
mContext = context;
}
public String getDeviceUUID() {
if (!TextUtils.isEmpty(mUuid)) {
return mUuid;
} else {
if (null != mContext) {
return mUuid = Settings.System.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
} else {
return "unknown";
}
}
}
public String getDeviceImei() {
if (null != mContext) {
if (!TextUtils.isEmpty(mImei)) {
return mImei;
} else {
if (Build.VERSION.SDK_INT >= 29) {
mImei = Settings.System.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
} else {
final TelephonyManager mTelephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mContext.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return "";
}
}
assert mTelephony != null;
if (mTelephony.getDeviceId() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mImei = mTelephony.getImei();
} else {
mImei = mTelephony.getDeviceId();
}
} else {
mImei = "";
}
}
}
}
return mImei;
}
public String getApplicationMarket() {
if (null != mContext) {
try {
PackageManager packageManager = mContext.getPackageManager();
if (null != packageManager) {
ApplicationInfo applicationInfo = packageManager
.getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
if (null != applicationInfo) {
return applicationInfo.metaData.getString("MARKET_NAME");
}
}
} catch (Exception ignored) {
}
}
return "";
}
//获取OAID
public String getOaid() {
SharedPreferences sp = mContext.getSharedPreferences("config", Context.MODE_PRIVATE);
oAid = sp.getString("OAID", "");
if (!TextUtils.isEmpty(oAid)) {
return oAid;
} else {
String oaid = DeviceIdentifier.getOAID(mContext);
if (!TextUtils.isEmpty(oaid)) {
return oaid;
}
String aid = DeviceIdentifier.getAndroidID(mContext);
if (!TextUtils.isEmpty(aid)) {
return aid;
}
String ids = DeviceIdentifier.getPseudoID();
if (!TextUtils.isEmpty(ids)) {
return ids;
}
}
return oAid;
}
public String getAppVersion() {
if (null == mContext) {
return mVersion;
}
try {
mVersion = mContext.getPackageManager().
getPackageInfo(mContext.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
}
return mVersion;
}
public String getPhoneVersion() {
return android.os.Build.VERSION.SDK_INT + "";
}
public String getChannel() {
try {
if (mContext != null) {
PackageManager packageManager = mContext.getPackageManager();
if (null != packageManager) {
ApplicationInfo applicationInfo = packageManager
.getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
if (null != applicationInfo) {
return (String) applicationInfo.metaData.get("MARKET_NAME");
// return "no channel";
}
}
}
} catch (PackageManager.NameNotFoundException e) {
}
return null;
}
public String getPackageName() {
return mContext.getPackageName();
}
public String getSystemModel() {
return android.os.Build.MODEL;
}
public String getToken() {
if (!TextUtils.isEmpty(mToken)) {
return mToken;
} else {
return NoClearSPUtils.getString(mContext, "token");
}
}
public void setToken(String token) {
this.mToken = token;
}
public String getAPNType() {
String netType = "none";
ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_WIFI) {
netType = "wifi";
} else if (nType == ConnectivityManager.TYPE_MOBILE) {
int nSubType = networkInfo.getSubtype();
TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (nSubType == TelephonyManager.NETWORK_TYPE_LTE
&& !telephonyManager.isNetworkRoaming()) {
netType = "4g";
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
|| nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
|| nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming()) {
netType = "3g";
} else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS
|| nSubType == TelephonyManager.NETWORK_TYPE_EDGE
|| nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming()) {
netType = "2g";
} else {
netType = "2g";
}
}
return netType;
}
public String getUserAgent() {
String userAgent = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
try {
userAgent = WebSettings.getDefaultUserAgent(mContext);
} catch (Exception e) {
userAgent = System.getProperty("http.agent");
}
} else {
userAgent = System.getProperty("http.agent");
}
StringBuffer sb = new StringBuffer();
for (int i = 0, length = userAgent.length(); i < length; i++) {
char c = userAgent.charAt(i);
if (c <= '\u001f' || c >= '\u007f') {
sb.append(String.format("\\u%04x", (int) c));
} else {
sb.append(c);
}
}
return sb.toString();
}
public String getRiskEngineToken() {
Log.i("TAG", "getRiskEngineToken: ----------->" + NoClearSPUtils.getString(mContext, "x-risk-engine-token"));
return NoClearSPUtils.getString(mContext, "x-risk-engine-token");
}
}

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Device</string>
</resources>

View File

@@ -0,0 +1,17 @@
package com.fengliyan.device;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}