Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
muxiannian committed Oct 25, 2019
2 parents 3d040c5 + e8319e0 commit 990dc39
Show file tree
Hide file tree
Showing 31 changed files with 394 additions and 123 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
+ **提供强制更新,不更新则无法使用APP,同时可以根据后台返回受影响的版本号,可控制多个版本同时被强制更新。**
+ **通知栏图片自定义**
+ **新增文件MD5校验,防止安装文件被恶意替换(2019-10-22 18:48:39添加)**
+ **新增静默下载更新的方式,实现进入App直接后台下载,下载完成后弹出安装页面(静默安装需要Root权限,而且体验很不好,不做支持)(2019-10-25 18:09:05添加)。**

### 新版本说明
+ 2019-10-25 18:09:05更新新版,版本号为:v2.0.2
+ 新增静默下载更新的方式
+ 新增获取是否有新版本更新的事件回调
+ 优化下载状态中的文案显示逻辑
+ 修复多次调用checkUpdate多次弹窗的bug

+ 2019-10-22 18:53:42更新新版,版本号为:v2.0.1
+ 新版新增文件的MD5校验
+ 新版新增对文件下载进度的监听
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import android.widget.TextView;
import android.widget.Toast;

import com.cretin.www.cretinautoupdatelibrary.activity.RootActivity;
import com.cretin.www.cretinautoupdatelibrary.activity.UpdateType2Activity;
import com.cretin.www.cretinautoupdatelibrary.utils.RootActivity;
import com.cretin.www.cretinautoupdatelibrary.interfaces.AppDownloadListener;
import com.cretin.www.cretinautoupdatelibrary.interfaces.MD5CheckListener;
import com.cretin.www.cretinautoupdatelibrary.utils.ResUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.io.File;

import static com.cretin.www.cretinautoupdatelibrary.activity.RootActivity.permission;
import static com.cretin.www.cretinautoupdatelibrary.utils.RootActivity.permission;
import static com.cretin.www.cretinautoupdatelibrary.utils.AppUtils.getAppLocalPath;

public class MD5HelperActivity extends AppCompatActivity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.cretin.www.autoupdateproject.adapter.RecyclerviewAdapter;
import com.cretin.www.autoupdateproject.model.ListModel;
import com.cretin.www.cretinautoupdatelibrary.interfaces.AppUpdateInfoListener;
import com.cretin.www.cretinautoupdatelibrary.interfaces.ForceExitCallBack;
import com.cretin.www.cretinautoupdatelibrary.model.DownloadInfo;
import com.cretin.www.cretinautoupdatelibrary.model.TypeConfig;
Expand Down Expand Up @@ -92,6 +93,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
//获取文件MD5检验码工具
startActivity(new Intent(this, MD5HelperActivity.class));
break;
case R.id.action_05:
//带提示的更新
AppUpdateUtils.getInstance().getUpdateConfig().setUiThemeType(TypeConfig.UI_THEME_A);//类型为自定义样式类型
AppUpdateUtils.getInstance().getUpdateConfig().setDataSourceType(TypeConfig.DATA_SOURCE_TYPE_JSON); //使用本地json提供数据
AppUpdateUtils.getInstance().addAppUpdateInfoListener(new AppUpdateInfoListener() {
@Override
public void isLatestVersion(boolean isLatest) {
if(isLatest){
Toast.makeText(MainActivity.this, "已是最新版本", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, "发现新版本,将会提示更新", Toast.LENGTH_SHORT).show();
}
}
}).checkUpdate(recyclerviewAdapter.jsonDataNoUpdate);
break;
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.blankj.utilcode.util.SpanUtils;
import com.cretin.www.autoupdateproject.R;
import com.cretin.www.autoupdateproject.model.ListModel;
import com.cretin.www.cretinautoupdatelibrary.interfaces.AppDownloadListener;
import com.cretin.www.cretinautoupdatelibrary.interfaces.AppUpdateInfoListener;
import com.cretin.www.cretinautoupdatelibrary.interfaces.MD5CheckListener;
import com.cretin.www.cretinautoupdatelibrary.model.DownloadInfo;
import com.cretin.www.cretinautoupdatelibrary.model.TypeConfig;
Expand All @@ -28,6 +30,7 @@ public class RecyclerviewAdapter extends RecyclerView.Adapter<RecyclerviewAdapte
private List<ListModel> data;
public String jsonDataForce = "{\"versionCode\": 25,\"isForceUpdate\": 1,\"preBaselineCode\": 24,\"versionName\": \"v2.3.1\",\"downurl\": \"http://jokesimg.cretinzp.com/apk/app-release_231_jiagu_sign.apk\",\"updateLog\": \"1、优化细节和体验,更加稳定\n2、引入大量优质用户\r\n3、修复已知bug\n4、风格修改\",\"size\": \"31338250\",\"hasAffectCodes\": \"1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24\"}";
public String jsonDataUnForce = "{\"versionCode\": 25,\"isForceUpdate\": 0,\"preBaselineCode\": 24,\"versionName\": \"v2.3.1\",\"downurl\": \"http://jokesimg.cretinzp.com/apk/app-release_231_jiagu_sign.apk\",\"updateLog\": \"1、优化细节和体验,更加稳定\n2、引入大量优质用户\r\n3、修复已知bug\n4、风格修改\",\"size\": \"31338250\",\"hasAffectCodes\": \"1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24\"}";
public String jsonDataNoUpdate = "{\"versionCode\": 1,\"isForceUpdate\": 0,\"preBaselineCode\": 0,\"versionName\": \"v1.0.0\",\"downurl\": \"http://jokesimg.cretinzp.com/apk/app-release_231_jiagu_sign.apk\",\"updateLog\": \"1、优化细节和体验,更加稳定\n2、引入大量优质用户\r\n3、修复已知bug\n4、风格修改\",\"size\": \"31338250\",\"hasAffectCodes\": \"\"}";

public RecyclerviewAdapter(Context context, List<ListModel> data) {
this.context = context;
Expand All @@ -54,7 +57,10 @@ public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
.setForegroundColor(ResUtils.getColor(R.color.colorAccent))
.append("是否开启文件MD5检验:")
.append((data.get(position).getSourceTypeVaule() != TypeConfig.DATA_SOURCE_TYPE_MODEL ?
"根据接口返回或者配置的JSON,当前是关闭" : data.get(position).isCheckFileMD5() ? "开启" : "关闭") + "")
"根据接口返回或者配置的JSON,当前是关闭" : data.get(position).isCheckFileMD5() ? "开启" : "关闭") + "\n")
.setForegroundColor(ResUtils.getColor(R.color.colorAccent))
.append("是否开启后台静默下载:")
.append((data.get(position).isAutoUpdateBackground() ? "开启" : "关闭"))
.setForegroundColor(ResUtils.getColor(R.color.colorAccent))
.create();
holder.tv_theme.setText(spannableStringBuilder);
Expand Down Expand Up @@ -86,6 +92,13 @@ public void onClick(View v) {
sourceTypeChange(data.get(position));
}
});

holder.tv_update_background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateBackground(data.get(position));
}
});
}

//修改数据来源
Expand Down Expand Up @@ -115,6 +128,13 @@ private void force(ListModel listModel) {
Toast.makeText(context, "强制更新状态切换成功", Toast.LENGTH_SHORT).show();
}

//修改静默下载的状态
private void updateBackground(ListModel listModel) {
listModel.setAutoUpdateBackground(!listModel.isAutoUpdateBackground());
notifyDataSetChanged();
Toast.makeText(context, "静默下载状态切换成功", Toast.LENGTH_SHORT).show();
}

//开始更新
private void update(ListModel listModel) {
if (listModel.getSourceTypeVaule() == TypeConfig.DATA_SOURCE_TYPE_JSON) {
Expand All @@ -124,6 +144,14 @@ private void update(ListModel listModel) {
//因为接口未使用文件加密校验 所以在这里关闭
AppUpdateUtils.getInstance().getUpdateConfig().setNeedFileMD5Check(false);
AppUpdateUtils.getInstance().getUpdateConfig().setDataSourceType(listModel.getSourceTypeVaule());
//开启或者关闭后台静默下载功能
AppUpdateUtils.getInstance().getUpdateConfig().setAutoDownloadBackground(listModel.isAutoUpdateBackground());
if (listModel.isAutoUpdateBackground()) {
//开启静默下载的时候推荐关闭通知栏进度提示
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(false);
} else {
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(true);
}
AppUpdateUtils.getInstance().checkUpdate(jsonData);
} else if (listModel.getSourceTypeVaule() == TypeConfig.DATA_SOURCE_TYPE_MODEL) {
DownloadInfo info = new DownloadInfo().setApkUrl("http://jokesimg.cretinzp.com/apk/app-release_231_jiagu_sign.apk")
Expand All @@ -137,9 +165,53 @@ private void update(ListModel listModel) {
//打开文件MD5校验
AppUpdateUtils.getInstance().getUpdateConfig().setNeedFileMD5Check(true);
AppUpdateUtils.getInstance().getUpdateConfig().setDataSourceType(listModel.getSourceTypeVaule());

//开启或者关闭后台静默下载功能
AppUpdateUtils.getInstance().getUpdateConfig().setAutoDownloadBackground(listModel.isAutoUpdateBackground());
if (listModel.isAutoUpdateBackground()) {
//开启静默下载的时候推荐关闭通知栏进度提示
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(false);
} else {
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(true);
}
//因为这里打开了MD5的校验 我在这里添加一个MD5检验监听监听
AppUpdateUtils.getInstance()
.addAppUpdateInfoListener(new AppUpdateInfoListener() {
@Override
public void isLatestVersion(boolean isLatest) {
Log.e("HHHHHHHHHHHHHHH", "isLatest:" + isLatest);
}
})
.addAppDownloadListener(new AppDownloadListener() {
@Override
public void downloading(int progress) {
Log.e("HHHHHHHHHHHHHHH", "progress:" + progress);
}

@Override
public void downloadFail(String msg) {
Log.e("HHHHHHHHHHHHHHH", "msg:" + msg);
}

@Override
public void downloadComplete(String path) {
Log.e("HHHHHHHHHHHHHHH", "path:" + path);
}

@Override
public void downloadStart() {
Log.e("HHHHHHHHHHHHHHH", "start");
}

@Override
public void reDownload() {

}

@Override
public void pause() {

}
})
.addMd5CheckListener(new MD5CheckListener() {
@Override
public void fileMd5CheckFail(String originMD5, String localMD5) {
Expand All @@ -158,6 +230,14 @@ public void fileMd5CheckSuccess() {
//因为接口未使用文件加密校验 所以在这里关闭
AppUpdateUtils.getInstance().getUpdateConfig().setNeedFileMD5Check(false);
AppUpdateUtils.getInstance().getUpdateConfig().setDataSourceType(listModel.getSourceTypeVaule());
//开启或者关闭后台静默下载功能
AppUpdateUtils.getInstance().getUpdateConfig().setAutoDownloadBackground(listModel.isAutoUpdateBackground());
if (listModel.isAutoUpdateBackground()) {
//开启静默下载的时候推荐关闭通知栏进度提示
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(false);
} else {
AppUpdateUtils.getInstance().getUpdateConfig().setShowNotification(true);
}
AppUpdateUtils.getInstance().checkUpdate();
}
}
Expand All @@ -174,6 +254,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tv_force;
private TextView tv_source_type;
private TextView tv_index;
private TextView tv_update_background;

public ViewHolder(View itemView) {
super(itemView);
Expand All @@ -182,6 +263,7 @@ public ViewHolder(View itemView) {
tv_force = itemView.findViewById(R.id.tv_force);
tv_source_type = itemView.findViewById(R.id.tv_source_type);
tv_index = itemView.findViewById(R.id.tv_index);
tv_update_background = itemView.findViewById(R.id.tv_update_background);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void onCreate() {
.setUiThemeType(TypeConfig.UI_THEME_AUTO)//配置UI的样式,一种有12种样式可供选择
.setRequestHeaders(null)//当dataSourceType为DATA_SOURCE_TYPE_URL时,设置请求的请求头
.setRequestParams(null)//当dataSourceType为DATA_SOURCE_TYPE_URL时,设置请求的请求参数
.setAutoDownloadBackground(false)//是否需要后台静默下载,如果设置为true,则调用checkUpdate方法之后会直接下载安装,不会弹出更新页面。当你选择UI样式为TypeConfig.UI_THEME_CUSTOM,静默安装失效,您需要在自定义的Activity中自主实现静默下载,使用这种方式的时候建议setShowNotification(false),这样基本上用户就会对下载无感知了
.setCustomActivityClass(CustomActivity.class)//如果你选择的UI样式为TypeConfig.UI_THEME_CUSTOM,那么你需要自定义一个Activity继承自RootActivity,并参照demo实现功能,在此处填写自定义Activity的class
.setNeedFileMD5Check(false)//是否需要进行文件的MD5检验,如果开启需要提供文件本身正确的MD5校验码,DEMO中提供了获取文件MD5检验码的工具页面,也提供了加密工具类Md5Utils
.setModelClass(new UpdateModel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public class ListModel {
private int uiTypeValue;
private int sourceTypeVaule;
private boolean isCheckFileMD5;
private boolean isAutoUpdateBackground;

public boolean isAutoUpdateBackground() {
return isAutoUpdateBackground;
}

public void setAutoUpdateBackground(boolean autoUpdateBackground) {
isAutoUpdateBackground = autoUpdateBackground;
}

public boolean isCheckFileMD5() {
return isCheckFileMD5;
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/layout/item_recyclerview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
android:paddingTop="16dp">

<TextView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/tv_theme"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -18,6 +17,7 @@
android:textColor="#4a4a4a"
android:textSize="15sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />


Expand All @@ -35,6 +35,20 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_theme" />

<TextView
android:id="@+id/tv_update_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:background="@drawable/shape_btn"
android:textColor="#4a4a4a"
android:text="切换静默下载状态"
android:textSize="14sp"
app:layout_constraintLeft_toRightOf="@+id/tv_update"
app:layout_constraintTop_toBottomOf="@+id/tv_theme" />

<TextView
android:id="@+id/tv_force"
android:layout_width="wrap_content"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/menu_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
android:id="@+id/action_04"
android:title="获取文件MD5校验码"
app:showAsAction="withText" />
<item
android:id="@+id/action_05"
android:title="带提示的检查更新"
app:showAsAction="withText" />
</menu>
11 changes: 6 additions & 5 deletions cretinautoupdatelibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true">
<activity android:name=".activity.UpdateBackgroundActivity"></activity>
<activity
android:name=".activity.UpdateType12Activity"
android:theme="@style/DialogActivityTheme"/>
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".activity.UpdateType11Activity"
android:theme="@style/DialogActivityTheme"/>
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".activity.UpdateType10Activity"
android:theme="@style/DialogActivityTheme"/>
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".activity.UpdateType9Activity"
android:theme="@style/DialogActivityTheme"/>
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".activity.UpdateType8Activity"
android:theme="@style/DialogActivityTheme"/>
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".activity.UpdateType7Activity"
android:theme="@style/DialogActivityTheme" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.cretin.www.cretinautoupdatelibrary.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;

import com.cretin.www.cretinautoupdatelibrary.interfaces.AppDownloadListener;
import com.cretin.www.cretinautoupdatelibrary.model.DownloadInfo;
import com.cretin.www.cretinautoupdatelibrary.utils.RootActivity;

public class UpdateBackgroundActivity extends RootActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setGravity(Gravity.LEFT | Gravity.TOP);
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.x = 0;
attributes.y = 0;
attributes.height = 1;
attributes.width = 1;

download();
finish();
}

@Override
public AppDownloadListener obtainDownloadListener() {
return null;
}

/**
* 启动Activity
*
* @param context
* @param info
*/
public static void launch(Context context, DownloadInfo info) {
launchActivity(context, info, UpdateBackgroundActivity.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cretin.www.cretinautoupdatelibrary.interfaces.AppDownloadListener;
import com.cretin.www.cretinautoupdatelibrary.model.DownloadInfo;
import com.cretin.www.cretinautoupdatelibrary.utils.ResUtils;
import com.cretin.www.cretinautoupdatelibrary.utils.RootActivity;

public class UpdateType10Activity extends RootActivity {

Expand Down Expand Up @@ -109,9 +110,7 @@ public void pause() {
* @param info
*/
public static void launch(Context context, DownloadInfo info) {
Intent intent = new Intent(context, UpdateType10Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("info", info);
context.startActivity(intent);
launchActivity(context, info, UpdateType10Activity.class);
}

}
Loading

0 comments on commit 990dc39

Please sign in to comment.