Skip to content

Commit

Permalink
Merge pull request #88 from PAXSTORE/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Apollolight authored Jul 18, 2024
2 parents 15d45b9 + a083238 commit fb26df2
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gradle:
Add the dependency

```
implementation 'com.whatspos.sdk:paxstore-3rd-app-android-sdk:9.3.0'
implementation 'com.whatspos.sdk:paxstore-3rd-app-android-sdk:9.4.1'
```

##### Tips: In the near future, our platform will only support applications integrated with sdk version v8.7.0 or higher. Please upgrade the sdk to the latest version as soon as possible
Expand Down
10 changes: 5 additions & 5 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.pax.android.demoapp"
minSdkVersion 19
targetSdkVersion 31
versionCode 1030
versionName "9.3.0"
versionCode 1041
versionName "9.4.1"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand Down Expand Up @@ -48,7 +48,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.slf4j:slf4j-android:1.7.25'

implementation 'com.whatspos.sdk:paxstore-3rd-app-android-sdk:9.3.0'
implementation 'com.whatspos.sdk:paxstore-3rd-app-android-sdk:9.4.1'

//to download below imports, please add this to root build.gradle repositories >> maven { url 'https://jitpack.io' }
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
Expand All @@ -59,7 +59,7 @@ dependencies {

// implementation project(':sdk')
// implementation 'org.slf4j:slf4j-api:1.7.12'
// implementation 'com.squareup.okhttp3:okhttp:3.10.0'
// implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
// implementation 'com.squareup.okhttp3:okhttp:4.12.0'
// implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'

}
7 changes: 6 additions & 1 deletion demo/src/main/java/com/pax/android/demoapp/APIFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class APIFragment extends Fragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

List<Long> idList = new ArrayList<>();
private TextView versionTV;
private LinearLayout openClientlayout;
private Switch tradingStateSwitch;
Expand Down Expand Up @@ -123,6 +123,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

checkUpdate = (LinearLayout) view.findViewById(R.id.check_update);
lvGetLastSuccess = (LinearLayout) view.findViewById(R.id.lv_get_last_success);



lvRetrieveData = (LinearLayout) view.findViewById(R.id.lv_retrieve_data);
lvChildRetrieve = (LinearLayout) view.findViewById(R.id.lv_childs_retrieve);
mImgRetrieve = (ImageView) view.findViewById(R.id.img_retrieve_data);
Expand Down Expand Up @@ -157,9 +160,11 @@ public void onClick(View view) {
@Override
public void onClick(View v) {
StoreSdk.getInstance().openDownloadListPage(getActivity().getPackageName(), getActivity().getApplicationContext());

}
});


checkUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected void onHandleIntent(@Nullable Intent intent) {
try {
Log.i(TAG, "call sdk API to download parameter");
downloadResult = StoreSdk.getInstance().paramApi().downloadParamToPath(getApplication().getPackageName(), com.pax.android.demoapp.BuildConfig.VERSION_CODE, saveFilePath);
Log.i(TAG, downloadResult.toString());
} catch (NotInitException e) {
Log.e(TAG, "e:" + e);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@

</LinearLayout>

///

<LinearLayout
android:visibility="gone"
android:id="@+id/lv_childs_retrieve"
Expand Down
2 changes: 1 addition & 1 deletion docs/DownloadIntegration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PAXSTORE Downloading Parameter Integration

By integrating with this function, admin can dilivery parameters to the application.
By integrating with this function, admin can delivery parameters to the application.

### 1: Below two steps can save like 15 hours in average( Do not skip this!!!)
1. Check the appKey and appSecret that are the same with the web, and check again, and again, three times should be fine.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ org.gradle.jvmargs=-Xmx1024m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

version=9.3.0
version=9.4.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-6.7.1-all.zip
8 changes: 4 additions & 4 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'


api 'com.whatspos.sdk:paxstore-3rd-app-java-sdk:9.3.0'
api 'com.whatspos.sdk:paxstore-3rd-app-java-sdk:9.4.1'
api 'com.whatspos.sdk:paxstore-3rd-app-android-cloud-msg-sdk:9.2.0'



// test
implementation 'commons-io:commons-io:2.7'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
// implementation 'commons-io:commons-io:2.7'
// implementation 'com.squareup.okhttp3:okhttp:4.12.0'
// implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
// api files('libs\\app-java-sdk-8.4.2.1.jar')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DownloadParamReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if ((intent != null && intent.getLongExtra(ParamService.TERMINAL_SEND_TIME, -1L) > 0)
|| getVerCodeByPackageName(context, STORE_PACKAGENAME) >= 200) {
Log.d("DownloadParamReceiver", "Ignore this broadcast, since STORE client will send Intent to ParamService");
Log.w("DownloadParamReceiver", "Ignore this broadcast, since STORE client will send Intent to ParamService");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,131 @@
package com.pax.market.android.app.sdk;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.pax.market.android.app.sdk.util.NetWorkUtils;
import com.pax.market.android.app.sdk.util.PreferencesUtils;
import com.pax.market.api.sdk.java.api.param.ParamApi;
import com.pax.market.api.sdk.java.base.constant.ResultCode;
import com.pax.market.api.sdk.java.base.dto.DownloadResultObject;
import com.pax.market.api.sdk.java.base.dto.InnerDownloadResultObject;
import com.pax.market.api.sdk.java.base.dto.LastFailObject;
import com.pax.market.api.sdk.java.base.dto.SdkObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class ParamApiStrategy extends ParamApi {

private static final String TAG = ParamApiStrategy.class.getSimpleName();
private static final String LAST_DOWNLOAD = "lastDownload";
private static final String KEY_DOWNLOADED_LIST = "downloadedIdList";
private Context context;


public ParamApiStrategy(Context context, String baseUrl, String appKey, String appSecret, String terminalSN) {
super(baseUrl, appKey, appSecret, terminalSN);
this.context = context;
}

public DownloadResultObject downloadParamToPathWithSHA256Check(String packageName, int versionCode, String saveFilePath) {
return downloadParams(packageName, versionCode, saveFilePath, true);
return downloadParams(packageName, versionCode, saveFilePath, true, false);
}

public DownloadResultObject downloadParamToPath(String packageName, int versionCode, String saveFilePath) {
return downloadParams(packageName, versionCode, saveFilePath, false);
return downloadParams(packageName, versionCode, saveFilePath, false, false);
}

public DownloadResultObject downloadParamsSHA256(String packageName, int versionCode, String saveFilePath) {
return downloadParams(packageName, versionCode, saveFilePath, true, true);
}

public DownloadResultObject downloadParam(String packageName, int versionCode, String saveFilePath) {
return downloadParams(packageName, versionCode, saveFilePath, false, true);
}

public DownloadResultObject downloadParams(String packageName, int versionCode, String saveFilePath, boolean verifySHA) {
public DownloadResultObject downloadParams(String packageName, int versionCode, String saveFilePath,
boolean verifySHA, boolean needApplyResult) {

boolean mobileNetAvailable = NetWorkUtils.isMobileNetAvailable(context);
LastFailObject failTask = PreferencesUtils.getObject(context, LAST_DOWNLOAD, LastFailObject.class);
InnerDownloadResultObject downloadResultObject = null;

List<Long> downloadedList = needApplyResult ? getIdListFromPrefs() : null;
if (verifySHA) {
downloadResultObject = super.downloadParamsWithShaCheck(packageName,
versionCode, saveFilePath, failTask, mobileNetAvailable);
versionCode, saveFilePath, failTask, mobileNetAvailable, needApplyResult, downloadedList);
} else {
downloadResultObject = super.downloadParamToPath(packageName,
versionCode, saveFilePath, failTask, mobileNetAvailable);
versionCode, saveFilePath, failTask, mobileNetAvailable, needApplyResult, downloadedList);
}


if (downloadResultObject.getBusinessCode() == ResultCode.SDK_DOWNLOAD_IOEXCEPTION.getCode()) {
// save one download IOException record
PreferencesUtils.putObject(context, LAST_DOWNLOAD, downloadResultObject.getLastFailObject());
} else {
PreferencesUtils.remove(context, LAST_DOWNLOAD);
}

if (needApplyResult) {
Log.i(TAG, "need apply result");
saveIdListToPrefs(downloadResultObject.getActionList());
}
return mapToDownloadResult(saveFilePath, downloadResultObject);
}

private ArrayList<Long> getIdListFromPrefs() {
String json = PreferencesUtils.getString(context, KEY_DOWNLOADED_LIST, null);
if (json != null) {
Gson gson = new Gson();
Type listType = new TypeToken<ArrayList<Long>>(){}.getType();
return gson.fromJson(json, listType);
}
return null;
}

private void saveIdListToPrefs(List<Long> downloadedList) {
Gson gson = new Gson();
String json = gson.toJson(downloadedList);
PreferencesUtils.putString(context, KEY_DOWNLOADED_LIST, json);
}


public DownloadResultObject downloadLastSuccessParamToPath(String saveFilePath, String paramTemplateName) {

InnerDownloadResultObject downloadResultObject = super.downloadLastSuccessParmToPath(saveFilePath, paramTemplateName);

return mapToDownloadResult(saveFilePath, downloadResultObject);
}


public DownloadResultObject downloadLastSuccessParamToPath(String saveFilePath) {
return downloadLastSuccessParamToPath(saveFilePath, null);
}

public SdkObject syncApplySuccessResult(List<Long> actionIdList) {
removeIdList(actionIdList); // 无Regardless of whether the update result is successful or not, the local record will be deleted. If the update fails, the process will be restarted from start to finish. The document tells the customer that if the update result fails, they need to ensure that the update result is successful, otherwise they will repeatedly download the parameters
return updateApplyResult(actionIdList, ACT_STATUS_SUCCESS, CODE_NONE_ERROR, REMARKS_CODE_PARAM_APPLIED);
}

public SdkObject syncApplyFailureResult(List<Long> actionIdList, String remarks) {
removeIdList(actionIdList);// Regardless of whether the update result is successful or not, the local record will be deleted. If the update fails, the process will be restarted from start to finish.
return updateApplyResult(actionIdList, ACT_STATUS_FAILED, ERROR_CODE_PARAM_APPLY_FAILED, remarks);
}

private void removeIdList(List<Long> actionIdList) {
ArrayList<Long> idListFromPrefs = getIdListFromPrefs();
if (idListFromPrefs!= null) {
idListFromPrefs.removeAll(actionIdList);
}
if (idListFromPrefs != null && !idListFromPrefs.isEmpty()) {
saveIdListToPrefs(idListFromPrefs);
} else {
PreferencesUtils.remove(context, KEY_DOWNLOADED_LIST);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void onHandleIntent(Intent intent) {
return;
}
// STORE client versionCode>=200
Log.i("ParamService", "intent received");
Log.w("ParamService", "intent received");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(DelayService.getCallingIntent(getApplicationContext()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private SdkObject checkPermission(String neededPermission) {
permissionRequested = true;
}
}
} // 如果没有申请任何permission, 那么直接往下走, 返回checkFail
} // return fail if no permission
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "e");
}
Expand Down

0 comments on commit fb26df2

Please sign in to comment.