Skip to content

Commit

Permalink
Merge pull request #70 from luoyesiqiu/master
Browse files Browse the repository at this point in the history
Support older oppo devices
  • Loading branch information
liyujiang-gzu authored Nov 1, 2023
2 parents 73fd88d + a92fcb4 commit c875967
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ private static IOAID createManufacturerImpl(Context context) {
return new HuaweiImpl(context);
}
if (OAIDRom.isOppo() || OAIDRom.isOnePlus()) {
return new OppoImpl(context);
OppoImpl oppo = new OppoImpl(context);
if(oppo.supported()) {
return oppo;
}
else {
return new OppoExtImpl(context);
}
}
if (OAIDRom.isCoolpad(context)) {
return new CoolpadImpl(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com>
*
* The software is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

package com.github.gzuliyujiang.oaid.impl;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.IBinder;
import android.os.RemoteException;

import com.github.gzuliyujiang.oaid.IGetter;
import com.github.gzuliyujiang.oaid.OAIDException;
import com.github.gzuliyujiang.oaid.OAIDLog;

import repeackage.com.oplus.stdid.IStdID;

public class OppoExtImpl extends OppoImpl{
private final static String ACTION = "action.com.oplus.stdid.ID_SERVICE";
private final static String PACKAGE_NAME = "com.coloros.mcs";
private final static String CLASS_NAME = "com.oplus.stdid.IdentifyService";

private final Context context;
public OppoExtImpl(Context context) {
super(context);
this.context = context;
}

@Override
public boolean supported() {
if (context == null) {
return false;
}
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
return pi != null;
} catch (Exception e) {
OAIDLog.print(e);
return false;
}
}

@Override
public void doGet(IGetter getter) {
if (context == null || getter == null) {
return;
}
Intent intent = new Intent(ACTION);
intent.setComponent(new ComponentName(PACKAGE_NAME, CLASS_NAME));
OAIDService.bind(context, intent, getter, new OAIDService.RemoteCaller() {
@Override
public String callRemoteInterface(IBinder service) throws OAIDException, RemoteException {
try {
return realGetOUID(service);
} catch (OAIDException | RemoteException e) {
throw e;
} catch (Exception e) {
throw new OAIDException(e);
}
}
});
}

protected String getSerId(IBinder service, String pkgName, String sign) throws RemoteException, OAIDException {
IStdID anInterface = IStdID.Stub.asInterface(service);
if (anInterface == null) {
throw new OAIDException("IStdID is null");
}
return anInterface.getSerID(pkgName, sign, "OUID");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public String callRemoteInterface(IBinder service) throws OAIDException, RemoteE
}

@SuppressLint("PackageManagerGetSignatures")
private String realGetOUID(IBinder service) throws PackageManager.NameNotFoundException,
protected String realGetOUID(IBinder service) throws PackageManager.NameNotFoundException,
NoSuchAlgorithmException, RemoteException, OAIDException {
String pkgName = context.getPackageName();
if (sign == null) {
Expand All @@ -106,7 +106,7 @@ private String realGetOUID(IBinder service) throws PackageManager.NameNotFoundEx
return getSerId(service, pkgName, sign);
}

private String getSerId(IBinder service, String pkgName, String sign) throws RemoteException, OAIDException {
protected String getSerId(IBinder service, String pkgName, String sign) throws RemoteException, OAIDException {
IOpenID anInterface = IOpenID.Stub.asInterface(service);
if (anInterface == null) {
throw new OAIDException("IOpenID is null");
Expand Down
95 changes: 95 additions & 0 deletions library/src/main/java/repeackage/com/oplus/stdid/IStdID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com>
*
* The software is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

package repeackage.com.oplus.stdid;


import repeackage.com.heytap.openid.IOpenID;

public interface IStdID extends IOpenID {
public static abstract class Stub extends IOpenID.Stub {
private static final java.lang.String DESCRIPTOR = "com.oplus.stdid.IStdID";

public Stub() {
this.attachInterface(this, DESCRIPTOR);
}

public static IStdID asInterface(android.os.IBinder obj) {
if ((obj == null)) {
return null;
}
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
if (((iin != null) && (iin instanceof IStdID))) {
return ((IStdID) iin);
}
return (IStdID)new IStdID.Stub.Proxy(obj);
}


private static class Proxy implements IStdID {
private android.os.IBinder mRemote;

Proxy(android.os.IBinder remote) {
mRemote = remote;
}

@Override
public android.os.IBinder asBinder() {
return mRemote;
}

public java.lang.String getInterfaceDescriptor() {
return DESCRIPTOR;
}

@Override
public java.lang.String getSerID(java.lang.String pkgName, java.lang.String sign, java.lang.String type) throws android.os.RemoteException {
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
java.lang.String _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeString(pkgName);
_data.writeString(sign);
_data.writeString(type);
boolean _status = mRemote.transact(IStdID.Stub.TRANSACTION_getSerID, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
return getDefaultImpl().getSerID(pkgName, sign, type);
}
_reply.readException();
_result = _reply.readString();
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
public static IOpenID sDefaultImpl;
}

static final int TRANSACTION_getSerID = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);

public static boolean setDefaultImpl(IOpenID impl) {
if (Proxy.sDefaultImpl == null && impl != null) {
Proxy.sDefaultImpl = impl;
return true;
}
return false;
}

public static IOpenID getDefaultImpl() {
return Proxy.sDefaultImpl;
}
}

}

0 comments on commit c875967

Please sign in to comment.