Skip to content

Commit

Permalink
v1.0.5 release
Browse files Browse the repository at this point in the history
1.优化华为、荣耀手机获取方法
2.如果未获取到oaid值,现在会回调为空
  • Loading branch information
flayone committed Apr 6, 2023
1 parent e1fdd5e commit b4f5d3b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OaidProject

获取Android手机oaid源代码,oaid值准确性和msa OAID SDK方式一致,代码透明,调用简洁,崩溃防护,更安全高效。

## 开始使用
Expand All @@ -20,18 +21,14 @@

```
dependencies {
implementation 'com.github.flayone.OaidProject:myOaid:1.0.4'
implementation 'com.github.flayone.OaidProject:myOaid:1.0.5'
}
```


### 获取OAID



获取oaid结果有可能是异步返回的,使用时请注意这一点差异


```
MyOAID.getOAID(this, new ResultCallBack() {
@Override
Expand All @@ -41,3 +38,8 @@
});
```

### 版本更新

| 版本 | 日期 | 内容 |
|--------|------------|--------------------------------------------|
| v1.0.5 | 2023.04.06 | 1.优化华为、荣耀手机获取方法 <br/>2.如果未获取到oaid值,现在会回调为空 |
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ android {
}

buildTypes {
debug{
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
Expand All @@ -32,10 +37,10 @@ dependencies {


//OAID gradle 引入,推荐使用此方式:源代码方式获取,大小65k
implementation 'com.github.flayone.OaidProject:myOaid:1.0.4'
// implementation 'com.github.flayone.OaidProject:myOaid:1.0.4'

//msa SDK方式获取,大小1.0M
implementation 'io.github.flayone:oaid-sdk:1.0.25'

// implementation project(path: ':myOaid')
implementation project(path: ':myOaid')
}
7 changes: 6 additions & 1 deletion myOaid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ group = 'com.github.flayone'


def pomName = "oaid-source"
def oaidVersionName = "1.0.4"
def oaidVersionName = "1.0.5"
def outputName = pomName + "_" + oaidVersionName + ".aar"

android {
Expand All @@ -28,6 +28,11 @@ android {
}

buildTypes {
debug{
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
Expand Down
1 change: 1 addition & 0 deletions myOaid/src/main/java/com/flayone/oaid/DeviceTypeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum DeviceTypeEnum {
Unknown("未知手机", "UNKNOWN"),
HuaShuo("华硕手机", "ASUS"),
HuaWei("华为手机", "HUAWEI"),
Honor("荣耀手机", "HONOR"),
Lenove("联想手机", "LENOVO"),
Motolora("摩托罗拉手机", "MOTOLORA"),
Nubia("努比亚手机", "NUBIA"),
Expand Down
10 changes: 6 additions & 4 deletions myOaid/src/main/java/com/flayone/oaid/MyOAID.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public static void init(final Context context, final ResultCallBack callBack) {
public void OnIdsAvalid(@NonNull final String oaid) {
try {
Log.d(TAG, "[OnIdsAvalid] oaid= " + oaid);

//无论获取值是否为空,都应该回调出去,防止无响应结果导致业务处理异常
if (callBack != null) {
callBack.onResult(oaid);
}
if (TextUtils.isEmpty(oaid)) {
Log.e(TAG, "oaid为空,未获取到oaid");
return;
}
if (callBack != null) {
callBack.onResult(oaid);
}
OAIDManager.getInstance().setOaId(oaid);
OAIDManager.saveString(context, SP_OAID, oaid);
} catch (Throwable e) {
Expand All @@ -45,6 +45,8 @@ public static void getOAID(Context context, final ResultCallBack callBack) {
try {
String insOaid = OAIDManager.getInstance().getOaId();
String savedOaid = OAIDManager.getSavedString(context, SP_OAID);
// String insOaid = "";
// String savedOaid = "";
if (TextUtils.isEmpty(insOaid)) {
if (TextUtils.isEmpty(savedOaid)) {
//获取oaid
Expand Down
7 changes: 6 additions & 1 deletion myOaid/src/main/java/com/flayone/oaid/MyOAIDHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public MyOAIDHelper() {
public static void getOAid(Context context, AppIdsUpdater mAppIdUpdateListener) {

try {
String oaid = null;
String oaid = "";
String manufacturer = getManufacturer().toUpperCase();
Log.d("MyOAIDHelper", "manufacturer===> " + manufacturer);
if (mAppIdUpdateListener == null) {
Expand All @@ -58,6 +58,7 @@ public static void getOAid(Context context, AppIdsUpdater mAppIdUpdateListener)
switch (deviceType) {
case HuaShuo:
case HuaWei:
case Honor:
case Oppo:
case OnePlus:
case ZTE:
Expand Down Expand Up @@ -86,6 +87,9 @@ public static void getOAid(Context context, AppIdsUpdater mAppIdUpdateListener)
oaid = new XiaomiDeviceIDHelper(context).getOAID();
mAppIdUpdateListener.OnIdsAvalid(oaid);
break;
default:
mAppIdUpdateListener.OnIdsAvalid(oaid);
break;
}
} catch (Throwable e) {
e.printStackTrace();
Expand Down Expand Up @@ -145,6 +149,7 @@ public void run() {
new ASUSDeviceIDHelper(context).getID(mAppIdUpdateListener);
break;
case HuaWei:
case Honor:
new HWDeviceIDHelper(context).getHWID(mAppIdUpdateListener);
break;
case Oppo:
Expand Down
49 changes: 48 additions & 1 deletion myOaid/src/main/java/com/flayone/oaid/imp/HWDeviceIDHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import com.flayone.oaid.AppIdsUpdater;
import com.flayone.oaid.interfaces.HWIDInterface;
Expand All @@ -27,14 +32,56 @@ public HWDeviceIDHelper(Context ctx) {
public void getHWID(AppIdsUpdater _listener) {
this._listener = _listener;
try {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
String oaid = Settings.Global.getString(mContext.getContentResolver(), "pps_oaid");
if (!TextUtils.isEmpty(oaid)) {
Log.d("HWDeviceIDHelper", "Get oaid from global settings: " + oaid);
if (_listener != null) {
_listener.OnIdsAvalid(oaid);
}
return;
}
} catch (Exception e) {
// OAIDLog.print(e);
}
}

boolean ret = false;
String packageName = "com.huawei.hwid";
try {

PackageManager pm = mContext.getPackageManager();
if (pm.getPackageInfo("com.huawei.hwid", 0) != null) {
packageName = "com.huawei.hwid";
ret = true;
} else if (pm.getPackageInfo("com.huawei.hwid.tv", 0) != null) {
packageName = "com.huawei.hwid.tv";
ret = true;
} else {
packageName = "com.huawei.hms";
ret = pm.getPackageInfo(packageName, 0) != null;
}
} catch (Exception e) {

}
try {
mContext.getPackageManager().getPackageInfo("com.huawei.hwid", 0);
} catch (Throwable e) {
e.printStackTrace();
}
// 不支持返回空信息
if (!ret) {
Log.d("HWDeviceIDHelper", "not supported");
if (_listener != null) {
_listener.OnIdsAvalid("");
}
return;
}

Intent bindIntent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE");
bindIntent.setPackage("com.huawei.hwid");
bindIntent.setPackage(packageName);
boolean isBin = mContext.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
// if (isBin) {
// try {
Expand Down

0 comments on commit b4f5d3b

Please sign in to comment.