得物.apk(点击下载) / AccountAuthServiceImpl.java


package com.huawei.hms.support.account.service;

import a.f;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.Base64;
import com.huawei.hms.api.Api;
import com.huawei.hms.common.ApiException;
import com.huawei.hms.common.HuaweiApi;
import com.huawei.hms.common.internal.AbstractClientBuilder;
import com.huawei.hms.hwid.ao;
import com.huawei.hms.hwid.as;
import com.huawei.hms.hwid.d;
import com.huawei.hms.hwid.h;
import com.huawei.hms.hwid.i;
import com.huawei.hms.hwid.j;
import com.huawei.hms.hwid.l;
import com.huawei.hms.hwid.m;
import com.huawei.hms.hwid.n;
import com.huawei.hms.hwid.o;
import com.huawei.hms.hwid.p;
import com.huawei.hms.support.account.request.AccountAuthParams;
import com.huawei.hms.support.account.result.AccountIcon;
import com.huawei.hms.support.account.result.AssistTokenResult;
import com.huawei.hms.support.account.result.AuthAccount;
import com.huawei.hms.support.api.account.AccountGetTokenOptions;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.account.AccountLogoutRequest;
import com.huawei.hms.support.api.entity.account.AccountSignInRequest;
import com.huawei.hms.support.api.entity.account.AccountSignOutReq;
import com.huawei.hms.support.api.entity.account.AccountStartAssistLoginRequest;
import com.huawei.hms.support.api.entity.account.GetAssistTokenRequest;
import com.huawei.hms.support.api.entity.auth.PermissionInfo;
import com.huawei.hms.support.hianalytics.HiAnalyticsClient;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.shizhuang.duapp.modules.du_mall_common.constant.MallABTest;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import s8.b;
import t8.e;

public class AccountAuthServiceImpl extends HuaweiApi<AccountAuthParams> implements AccountAuthService {
    private static final Api<AccountAuthParams> ACCOUNT_AUTH_API = new Api<>("AuthAccount.API");
    private static final Long ONE_WEEK_MILLISECOND = 604800000L;
    private String mAccountName;
    private boolean mFromRequestToken;

    public AccountAuthServiceImpl(Activity activity, AccountAuthParams accountAuthParams, int i) {
        super(activity, (Api) ACCOUNT_AUTH_API, (Api.ApiOptions) accountAuthParams, (AbstractClientBuilder) new d(), i);
    }

    private boolean checkIdTokenSignAlg(AccountAuthParams accountAuthParams) {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "checkIdTokenSignAlg", true);
        if (accountAuthParams == null) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "accountAuthParams is null", true);
            return false;
        }
        try {
            int i = new JSONObject(accountAuthParams.getSignInParams()).getInt("idTokenSignAlg");
            if (i == 1 || i == 2) {
                return true;
            }
            return false;
        } catch (JSONException e) {
            StringBuilder h12 = f.h("JSONException:");
            h12.append(e.getClass().getSimpleName());
            as.d("[ACCOUNT]AccountAuthServiceImpl", h12.toString(), true);
            return false;
        }
    }

    private b<AssistTokenResult> doWriteGetAssistToken(GetAssistTokenRequest getAssistTokenRequest) {
        try {
            return doWrite(new p("hwid.getAssistToken", getAssistTokenRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), "hwid.getAssistToken", 60400300)));
        } catch (JSONException unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
            e eVar = new e();
            ApiException apiException = new ApiException(new Status(2015));
            synchronized (eVar.f38376a) {
                if (!eVar.b) {
                    eVar.b = true;
                    eVar.e = apiException;
                    eVar.f38376a.notifyAll();
                    eVar.h();
                }
                return eVar;
            }
        }
    }

    private Bitmap stringToBitmap(String str) {
        try {
            byte[] decode = Base64.decode(str, 0);
            return BitmapFactory.decodeByteArray(decode, 0, decode.length);
        } catch (OutOfMemoryError unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "out of memory error ", true);
        } catch (Exception e) {
            StringBuilder h12 = f.h("stringToBitmap Exception is ");
            h12.append(e.getClass().getSimpleName());
            as.d("[ACCOUNT]AccountAuthServiceImpl", h12.toString(), true);
        }
        return null;
    }

    @Override // com.huawei.hms.support.feature.service.AuthService
    public b<Void> cancelAuthorization() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "cancelAuthorization", true);
        AccountSignInRequest accountSignInRequest = new AccountSignInRequest();
        accountSignInRequest.setAccountAuthParams((AccountAuthParams) getOption());
        try {
            return doWrite(new h("account.revokeAccess", accountSignInRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), "account.revokeAccess", 60400300)));
        } catch (JSONException unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
            e eVar = new e();
            ApiException apiException = new ApiException(new Status(2015));
            synchronized (eVar.f38376a) {
                if (!eVar.b) {
                    eVar.b = true;
                    eVar.e = apiException;
                    eVar.f38376a.notifyAll();
                    eVar.h();
                }
                return eVar;
            }
        }
    }

    @Override // com.huawei.hms.common.HuaweiApi
    public int getApiLevel() {
        List<PermissionInfo> permissionInfos;
        AccountAuthParams accountAuthParams = (AccountAuthParams) getOption();
        if (!(accountAuthParams == null || (permissionInfos = accountAuthParams.getPermissionInfos()) == null || permissionInfos.size() == 0)) {
            for (PermissionInfo permissionInfo : permissionInfos) {
                String permission = permissionInfo.getPermission();
                if (permission != null && permission.equals("https://www.huawei.com/auth/account/carrierid")) {
                    as.b("[ACCOUNT]AccountAuthServiceImpl", "permissioninfos contain carrierId and silentSignIn setApiLevel is 13", true);
                    return 13;
                }
            }
        }
        return 1;
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public b<AssistTokenResult> getAssistToken(GetAssistTokenRequest getAssistTokenRequest) {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "getAssistToken", true);
        return doWriteGetAssistToken(getAssistTokenRequest);
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public b<AccountIcon> getChannel() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "getChannel", true);
        AccountSignInRequest accountSignInRequest = new AccountSignInRequest();
        accountSignInRequest.setAccountAuthParams((AccountAuthParams) getOption());
        Context context = getContext();
        SharedPreferences sharedPreferences = context.getSharedPreferences("ACCOUNT_CHANNEL_CACHE", 0);
        String string = sharedPreferences.getString(MallABTest.Keys.AB_NEW_HOT, "");
        String string2 = sharedPreferences.getString("desc", "");
        long j = sharedPreferences.getLong("cache_time", 0);
        long a5 = ao.a();
        if (j == 0 || TextUtils.isEmpty(string) || TextUtils.isEmpty(string2) || a5 - j >= ONE_WEEK_MILLISECOND.longValue()) {
            try {
                return doWrite(new i("account.getChannel", accountSignInRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), "account.getChannel", 60400300), context));
            } catch (JSONException unused) {
                as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
                e eVar = new e();
                ApiException apiException = new ApiException(new Status(2015));
                synchronized (eVar.f38376a) {
                    if (!eVar.b) {
                        eVar.b = true;
                        eVar.e = apiException;
                        eVar.f38376a.notifyAll();
                        eVar.h();
                    }
                    return eVar;
                }
            }
        } else {
            TResult tresult = (TResult) new AccountIcon(string2, stringToBitmap(string));
            e eVar2 = new e();
            synchronized (eVar2.f38376a) {
                if (!eVar2.b) {
                    eVar2.b = true;
                    eVar2.d = tresult;
                    eVar2.f38376a.notifyAll();
                    eVar2.h();
                }
            }
            ApiException apiException2 = new ApiException(new Status(0));
            synchronized (eVar2.f38376a) {
                if (!eVar2.b) {
                    eVar2.b = true;
                    eVar2.e = apiException2;
                    eVar2.f38376a.notifyAll();
                    eVar2.h();
                }
            }
            return eVar2;
        }
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public Intent getIndependentSignInIntent(String str) {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "getIndependentSignInIntent", true);
        return com.huawei.hms.hwid.f.a(getContext(), (AccountAuthParams) getOption(), getSubAppID(), str);
    }

    @Override // com.huawei.hms.support.feature.service.AuthService
    public Intent getSignInIntent() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "getSignInIntent", true);
        return com.huawei.hms.hwid.f.a(getContext(), (AccountAuthParams) getOption(), getSubAppID());
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public b<Void> logout() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "logout", true);
        AccountLogoutRequest accountLogoutRequest = new AccountLogoutRequest();
        accountLogoutRequest.setAccountAuthParams((AccountAuthParams) getOption());
        try {
            return doWrite(new j("hwid.logout", accountLogoutRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), "hwid.logout", 60400300)));
        } catch (JSONException unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
            e eVar = new e();
            ApiException apiException = new ApiException(new Status(2015));
            synchronized (eVar.f38376a) {
                if (!eVar.b) {
                    eVar.b = true;
                    eVar.e = apiException;
                    eVar.f38376a.notifyAll();
                    eVar.h();
                }
                return eVar;
            }
        }
    }

    @Override // com.huawei.hms.support.feature.service.AuthService
    public b<Void> signOut() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "signOut", true);
        com.huawei.hms.hwid.f.a();
        AccountSignOutReq accountSignOutReq = new AccountSignOutReq();
        return doWrite(new n("account.signout", accountSignOutReq.toJson(), HiAnalyticsClient.reportEntry(getContext(), "hwid.signout", 60400300)));
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public b<AuthAccount> silentSignIn() {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "silentSignIn", true);
        AccountSignInRequest accountSignInRequest = new AccountSignInRequest();
        AccountAuthParams accountAuthParams = (AccountAuthParams) getOption();
        accountSignInRequest.setAccountAuthParams(accountAuthParams);
        boolean z = this.mFromRequestToken;
        if (z) {
            accountSignInRequest.setAccountGetTokenOptions(new AccountGetTokenOptions(this.mAccountName, z));
        }
        if (!checkIdTokenSignAlg(accountAuthParams)) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "idTokenSignAlg is invalid", true);
            e eVar = new e();
            ApiException apiException = new ApiException(new Status(PushConstants.NOTIFICATION_SERVICE_SEND_MESSAGE, "idTokenSignAlg is invalid"));
            synchronized (eVar.f38376a) {
                if (!eVar.b) {
                    eVar.b = true;
                    eVar.e = apiException;
                    eVar.f38376a.notifyAll();
                    eVar.h();
                }
            }
            return eVar;
        }
        try {
            String json = accountSignInRequest.toJson();
            String reportEntry = HiAnalyticsClient.reportEntry(getContext(), "account.silentSignIn", 60400300);
            if (this.mFromRequestToken) {
                return doWrite(new l("account.silentSignIn", json, reportEntry));
            }
            return doWrite(new m("account.silentSignIn", json, reportEntry));
        } catch (JSONException unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
            e eVar2 = new e();
            ApiException apiException2 = new ApiException(new Status(2015));
            synchronized (eVar2.f38376a) {
                if (!eVar2.b) {
                    eVar2.b = true;
                    eVar2.e = apiException2;
                    eVar2.f38376a.notifyAll();
                    eVar2.h();
                }
                return eVar2;
            }
        }
    }

    @Override // com.huawei.hms.support.account.service.AccountAuthService
    public b<Void> startAssistLogin(String str) {
        as.b("[ACCOUNT]AccountAuthServiceImpl", "startAssistLogin", true);
        try {
            return doWrite(new o("hwid.startAssistLogin", new AccountStartAssistLoginRequest(str).toJson(), HiAnalyticsClient.reportEntry(getContext(), "hwid.startAssistLogin", 60400300)));
        } catch (JSONException unused) {
            as.d("[ACCOUNT]AccountAuthServiceImpl", "JSONException, errorcode is:2015", true);
            e eVar = new e();
            ApiException apiException = new ApiException(new Status(2015));
            synchronized (eVar.f38376a) {
                if (!eVar.b) {
                    eVar.b = true;
                    eVar.e = apiException;
                    eVar.f38376a.notifyAll();
                    eVar.h();
                }
                return eVar;
            }
        }
    }

    public AccountAuthServiceImpl(Context context, AccountAuthParams accountAuthParams, int i) {
        super(context, ACCOUNT_AUTH_API, accountAuthParams, new d(), i);
    }

    public AccountAuthServiceImpl(Context context, AccountAuthParams accountAuthParams, String str, int i) {
        super(context, ACCOUNT_AUTH_API, accountAuthParams, new d(), i);
        this.mAccountName = str;
        this.mFromRequestToken = true;
    }

    public AccountAuthServiceImpl(Activity activity, AccountAuthParams accountAuthParams, String str, int i) {
        super(activity, (Api) ACCOUNT_AUTH_API, (Api.ApiOptions) accountAuthParams, (AbstractClientBuilder) new d(), i);
        this.mAccountName = str;
        this.mFromRequestToken = true;
    }
}