思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 License.java 源代码,内容仅作参考
package com.baidu.idl.license;
import android.content.Context;
import android.content.res.AssetManager;
import android.text.TextUtils;
import com.baidu.idl.authority.AuthorityState;
import com.baidu.idl.authority.IDLAuthorityException;
import com.baidu.idl.util.HttpClient;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class License {
public static final int LICENSE_AG_ID = -1;
public static final String LICENSE_ASSETS_FILE = "idl_license";
public static final String LICENSE_ASSETS_MULTIPLE_FILE = "license/idl_license_%s";
public static final String LICENSE_FILE = "license";
public static final String LICENSE_LICENSE_FILE_NAME = "idl_license_%s";
public static final String TAG = "IDL-License";
public static final String URL = "http://sdkss.shitu.baidu.com/cgi-bin/queryLicense.py";
public static License mInstance;
public ArrayList<String> mALLicense;
public int mAuthorityStatus = 256;
public int mAlgorithmId = -1;
public String mAlgorithmIdLicenseName = "";
private ArrayList<String> analyseLicense(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
ArrayList<String> arrayList = new ArrayList<>();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
return arrayList;
}
arrayList.add(readLine);
}
}
public static native String getAlgorithmVersion();
private InputStream getAssetsLicenseFileInputStream(AssetManager assetManager) {
InputStream open;
try {
if (TextUtils.isEmpty(this.mAlgorithmIdLicenseName)) {
open = assetManager.open(LICENSE_ASSETS_FILE);
} else {
open = assetManager.open(String.format(LICENSE_ASSETS_MULTIPLE_FILE, this.mAlgorithmIdLicenseName));
}
return open;
} catch (IOException unused) {
return null;
}
}
public static native String getAuthorityVersion();
private File getDataLicenseFile(Context context) {
if (TextUtils.isEmpty(this.mAlgorithmIdLicenseName)) {
return context.getDir(LICENSE_FILE, 0);
}
File dir = context.getDir(LICENSE_FILE, 0);
if (!dir.exists() || !dir.isDirectory()) {
dir.mkdirs();
}
return new File(dir.getAbsolutePath() + File.separator + String.format(LICENSE_LICENSE_FILE_NAME, this.mAlgorithmIdLicenseName));
}
public static synchronized License getInstance() {
License license;
synchronized (License.class) {
if (mInstance == null) {
mInstance = new License();
}
license = mInstance;
}
return license;
}
public void getLatestLicense(Context context, String str) {
ArrayList<String> licenseByNetwork = getLicenseByNetwork(context, str);
if (licenseByNetwork == null || licenseByNetwork.size() <= 0 || initLicense(context, str, (String[]) licenseByNetwork.toArray(new String[licenseByNetwork.size()])) >= 48) {
return;
}
WriteLicense(context, licenseByNetwork);
String str2 = "LatestLicense " + licenseByNetwork;
}
private ArrayList<String> getLicenseByNetwork(Context context, String str) {
JSONObject jSONObject;
ArrayList<String> arrayList;
String postData = getPostData(context, str);
String str2 = "Network Request " + postData;
String post = HttpClient.post(URL, postData);
if (post != null && post.length() > 0) {
String str3 = "Network Response " + post;
}
if (post == null) {
return null;
}
try {
jSONObject = new JSONObject(post);
} catch (JSONException e) {
e.printStackTrace();
jSONObject = null;
}
if (jSONObject != null) {
int i = -1;
int optInt = jSONObject.optInt("errno", -1);
jSONObject.optString("msg");
JSONArray optJSONArray = jSONObject.optJSONArray(LICENSE_FILE);
if (optJSONArray == null || optJSONArray.length() <= 0) {
arrayList = null;
} else {
ArrayList<String> arrayList2 = new ArrayList<>();
for (int i2 = 0; i2 < optJSONArray.length(); i2++) {
String optString = optJSONArray.optString(i2);
if (optString != null) {
arrayList2.add(optString);
}
}
arrayList = arrayList2;
i = optInt;
}
if (i != 0 || optJSONArray == null || optJSONArray.length() <= 0) {
return null;
}
return arrayList;
}
return null;
}
private ArrayList<String> getLocalLicense(Context context) {
ArrayList<String> ReadLicenseFromData = ReadLicenseFromData(context);
return (ReadLicenseFromData == null || ReadLicenseFromData.size() < 1) ? ReadLicenseFromAsset(context) : ReadLicenseFromData;
}
private int initWithAlgorithmId(Context context, String str) {
int i = this.mAuthorityStatus;
if (272 == i) {
return i;
}
this.mAuthorityStatus = 272;
this.mAuthorityStatus = verifyByLocalData(context, str);
String str2 = "Local License Authority State Is :" + AuthorityState.getStateName(this.mAuthorityStatus);
if (this.mAuthorityStatus > 48) {
this.mAuthorityStatus = verifyByNetworkData(context, str);
String str3 = "Net License Authority State Is :" + AuthorityState.getStateName(this.mAuthorityStatus);
}
int i2 = this.mAuthorityStatus;
if (i2 <= 48) {
return i2;
}
throw new IDLAuthorityException(AuthorityState.getStateName(i2));
}
private int verifyByLocalData(final Context context, final String str) {
this.mALLicense = getLocalLicense(context);
ArrayList<String> arrayList = this.mALLicense;
if (arrayList == null || arrayList.size() <= 0) {
return 49;
}
ArrayList<String> arrayList2 = this.mALLicense;
int initLicense = initLicense(context, str, (String[]) arrayList2.toArray(new String[arrayList2.size()]));
if (initLicense == 0) {
return initLicense;
}
if (initLicense == 16) {
new Thread(new Runnable() {
@Override
public void run() {
License.this.getLatestLicense(context, str);
}
}).start();
return initLicense;
}
deleteErrorLicense(context);
return initLicense;
}
private int verifyByNetworkData(Context context, String str) {
this.mALLicense = getLicenseByNetwork(context, str);
String str2 = "Net License:" + this.mALLicense;
ArrayList<String> arrayList = this.mALLicense;
if (arrayList != null && arrayList.size() > 0) {
ArrayList<String> arrayList2 = this.mALLicense;
int initLicense = initLicense(context, str, (String[]) arrayList2.toArray(new String[arrayList2.size()]));
if (initLicense < 48) {
WriteLicense(context, this.mALLicense);
return initLicense;
}
return initLicense;
}
deleteErrorLicense(context);
return 49;
}
public ArrayList<String> ReadLicenseFromAsset(Context context) {
InputStream inputStream;
?? assets = context.getAssets();
ArrayList<String> arrayList = null;
try {
} catch (Throwable th) {
th = th;
}
try {
try {
inputStream = getAssetsLicenseFileInputStream(assets);
if (inputStream != null) {
try {
arrayList = analyseLicense(inputStream);
} catch (IOException e) {
e = e;
e.printStackTrace();
if (inputStream != null) {
inputStream.close();
}
if (arrayList != null) {
WriteLicense(context, arrayList);
}
return arrayList;
}
}
} catch (IOException e2) {
e2.printStackTrace();
}
} catch (IOException e3) {
e = e3;
inputStream = null;
} catch (Throwable th2) {
th = th2;
assets = 0;
if (assets != 0) {
try {
assets.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
throw th;
}
if (inputStream != null) {
inputStream.close();
}
if (arrayList != null && arrayList.size() > 0) {
WriteLicense(context, arrayList);
}
return arrayList;
}
public ArrayList<String> ReadLicenseFromData(Context context) {
if (context == null) {
return null;
}
File dataLicenseFile = getDataLicenseFile(context);
if (dataLicenseFile != null) {
String str = "ReadLicenseFromData file type " + dataLicenseFile.isDirectory() + dataLicenseFile.getAbsolutePath();
}
try {
return analyseLicense(new FileInputStream(dataLicenseFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (IOException e2) {
e2.printStackTrace();
return null;
} catch (Exception e3) {
e3.printStackTrace();
return null;
}
}
public boolean WriteLicense(Context context, ArrayList<String> arrayList) {
FileOutputStream fileOutputStream;
boolean z = false;
if (arrayList == null || arrayList.size() == 0 || context == null) {
return false;
}
File dataLicenseFile = getDataLicenseFile(context);
if (dataLicenseFile != null) {
dataLicenseFile.delete();
}
if (dataLicenseFile != null || !dataLicenseFile.exists()) {
try {
dataLicenseFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fileOutputStream2 = null;
try {
try {
try {
String str = "WriteLicense path " + dataLicenseFile.getAbsolutePath();
fileOutputStream = new FileOutputStream(dataLicenseFile);
} catch (IOException e2) {
e2.printStackTrace();
}
} catch (FileNotFoundException e3) {
e = e3;
} catch (IOException e4) {
e = e4;
}
} catch (Throwable th) {
th = th;
}
try {
Iterator<String> it = arrayList.iterator();
while (it.hasNext()) {
fileOutputStream.write(it.next().getBytes());
fileOutputStream.write(10);
}
fileOutputStream.close();
z = true;
} catch (FileNotFoundException e5) {
e = e5;
fileOutputStream2 = fileOutputStream;
e.printStackTrace();
if (fileOutputStream2 != null) {
fileOutputStream2.close();
}
return z;
} catch (IOException e6) {
e = e6;
fileOutputStream2 = fileOutputStream;
e.printStackTrace();
if (fileOutputStream2 != null) {
fileOutputStream2.close();
}
return z;
} catch (Throwable th2) {
th = th2;
fileOutputStream2 = fileOutputStream;
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (IOException e7) {
e7.printStackTrace();
}
}
throw th;
}
return z;
}
public void deleteErrorLicense(Context context) {
if (context == null) {
return;
}
File dir = context.getDir(LICENSE_FILE, 0);
if (dir.exists()) {
dir.delete();
}
}
public native long getLicenseRemnant(int i);
public native int getLicenseState(int i);
public int getLicenseStateWithAlgorithmId(int i) {
return getLicenseState(i);
}
public native String getPostData(Context context, String str);
@Deprecated
public int init(Context context, String str) {
this.mAlgorithmId = -1;
this.mAlgorithmIdLicenseName = "";
int i = this.mAuthorityStatus;
if (272 == i) {
return i;
}
this.mAuthorityStatus = 272;
this.mAuthorityStatus = verifyByLocalData(context, str);
String str2 = "Local License Authority State Is :" + AuthorityState.getStateName(this.mAuthorityStatus);
if (this.mAuthorityStatus > 48) {
this.mAuthorityStatus = verifyByNetworkData(context, str);
String str3 = "Net License Authority State Is :" + AuthorityState.getStateName(this.mAuthorityStatus);
}
if (this.mAuthorityStatus > 48) {
String str4 = "IDLAuthorityException :" + AuthorityState.getStateName(this.mAuthorityStatus);
}
return this.mAuthorityStatus;
}
public native int initLicense(Context context, String str, String[] strArr);
public native int initLicenseWithToken(String str);
public int init(String str) {
int i = this.mAuthorityStatus;
if (272 == i) {
return i;
}
this.mAuthorityStatus = 272;
if (str != null && str.length() > 0) {
this.mAuthorityStatus = initLicenseWithToken(str);
if (this.mAuthorityStatus != 0) {
this.mAuthorityStatus = 51;
}
} else {
this.mAuthorityStatus = 51;
}
return this.mAuthorityStatus;
}
public int init(Context context, String str, int i, String str2) {
this.mAlgorithmId = i;
this.mAlgorithmIdLicenseName = str2;
return initWithAlgorithmId(context, str);
}
}