Skip to content

Commit

Permalink
fix rhymelph#58 rhymelph#65 release v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyme committed Nov 4, 2022
1 parent ef198f1 commit 5a761ae
Show file tree
Hide file tree
Showing 43 changed files with 629 additions and 258 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0
* add silent install, fix google play release issues.
## 0.3.9
* fixed download file not exist error.
## 0.3.8+2
* fixed download file not exist error.
## 0.3.8+1
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Android and IOS upgrade plugin.
## Getting Started

### 1. Use Plugin:
add this code in `pubspec.yaml`
- add this code in `pubspec.yaml`

```yaml
dependencies:
Expand Down Expand Up @@ -103,7 +103,11 @@ dependencies:
> make sure your application had this permission and request dynamic permission.
```xml
<!--(if you want to upload google store,can not add this permission)-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!--(if you want to use silent install,need to add this permission,and app is system app-->
<uses-permission android:name="android.permission.INSTALL_PACKAGES" tools:ignore="ProtectedPermissions"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
```
Expand Down Expand Up @@ -182,6 +186,15 @@ enum RUpgradeFlavor {
bool isSuccess=await RUpgrade.installByPath(path);
}
```
- install type
```dart
/// [RUpgrade.upgradeWithId]、[RUpgrade.upgrade]、[RUpgrade.install]、[RUpgrade.installByPath]
enum RUpgradeInstallType {
normal,//normal install
silent,//silent install
none,// not install
}
```

#### 5. Pause Download
```dart
Expand Down
15 changes: 15 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Android和IOS的升级应用插件==Flutter应用升级插件
- [] 修改通知栏显示的信息
- [] `Android`热更新
- [] `Android`增量升级
- [] `Android`普通安装,静默安装
- [] `IOS`根据APPID跳转AppStore升级
- [] `IOS`根据APPID获取AppStore当前上架版本

Expand Down Expand Up @@ -104,9 +105,14 @@ dependencies:

> 注意,在Android应用中,请确保`AndroidManifest.xml`中声明以下权限,并在6.0系统上进行动态授权,不然会调用升级方法将抛出权限异常
```xml
<!--(如果需要上架到google store ,不能添加这个权限 , 也无法使用应用内更新功能)-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!--(静默安装需要添加这个权限,并且需要系统应用-->
<uses-permission android:name="android.permission.INSTALL_PACKAGES" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
```

#### 1.添加升级下载进度监听
Expand Down Expand Up @@ -183,6 +189,15 @@ enum RUpgradeFlavor {
bool isSuccess=await RUpgrade.installByPath(path);
}
```
- 新增安装类型
```dart
/// [RUpgrade.upgradeWithId]、[RUpgrade.upgrade]、[RUpgrade.install]、[RUpgrade.installByPath]
enum RUpgradeInstallType {
normal,//普通安装
silent,//静默安装
none,// 不进行安装
}
```

#### 5. 暂停下载
```dart
Expand Down
18 changes: 9 additions & 9 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.r_upgrade">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
package="com.example.r_upgrade">

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:usesCleartextTraffic="true">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!-- <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />-->
<application android:usesCleartextTraffic="true">
<service android:name="com.example.r_upgrade.common.UpgradeService">

</service>
Expand All @@ -18,7 +18,7 @@
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
android:resource="@xml/provider_paths" />
</provider>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.example.r_upgrade;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

import com.example.r_upgrade.common.HotUpgradeManager;
import com.example.r_upgrade.common.StoragePermissions;
import com.example.r_upgrade.common.UpgradeManager;
import com.example.r_upgrade.common.manager.UpgradeManager;
import com.example.r_upgrade.common.UpgradeService;
import com.example.r_upgrade.method.RUpgradeMethodCallHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public interface PermissionsRegistry {
void addListener(PluginRegistry.RequestPermissionsResultListener handler);
}

interface ResultCallback {
public interface ResultCallback {
void onResult(String errorCode, String errorDescription);
}

private static final int STORAGE_REQUEST_ID = 9790;
private boolean ongoing = false;

void requestPermissions(
public void requestPermissions(
Activity activity,
PermissionsRegistry permissionsRegistry,
final ResultCallback callback) {
Expand Down Expand Up @@ -60,7 +60,7 @@ private boolean hasWritePermission(Activity activity) {
}

@VisibleForTesting
static final class StorageRequestPermissionsListener
public static final class StorageRequestPermissionsListener
implements PluginRegistry.RequestPermissionsResultListener {

// There's no way to unregister permission listeners in the v1 embedding, so we'll be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import androidx.core.app.NotificationManagerCompat;

import com.example.r_upgrade.R;
import com.example.r_upgrade.common.manager.UpgradeManager;

public class UpgradeNotification {
public static final String TAG = "r_upgrade.Notification";

private static String CHANNEL_NAME;

static void createNotification(Context context, int id, String title,boolean indeterminate, Double percent, String contentText, int status) {
public static void createNotification(Context context, int id, String title,boolean indeterminate, Double percent, String contentText, int status) {
if (CHANNEL_NAME == null) {
try {
CHANNEL_NAME = context.getPackageName() + "_notification";
Expand Down Expand Up @@ -112,8 +113,6 @@ static void createNotification(Context context, int id, String title,boolean ind
notificationManager.createNotificationChannel(createNotificationChannel());
}
compat.notify(id, notification);

// notificationManager.notify(id, notification);
}

private static int getPendingIntentFlag() {
Expand All @@ -124,7 +123,7 @@ private static int getPendingIntentFlag() {
return pendingFlag;
}

static void removeNotification(Context context, long id) {
public static void removeNotification(Context context, long id) {
NotificationManagerCompat compat = NotificationManagerCompat.from(context);
compat.cancel((int) id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum UpgradeNotificationStyle {
none;


String getNotificationStyleString(Context context, double speech, double planTime) {
public String getNotificationStyleString(Context context, double speech, double planTime) {
String speechString = context.getResources().getString(R.string.r_upgrade_download_speech, speech);
String planTimeString = context.getResources().getString(R.string.r_upgrade_download_planTime, planTime);
switch (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Map<String, Object> queryById(long id) {
}


Integer queryStatusById(int id) {
public Integer queryStatusById(int id) {
SQLiteDatabase readableDatabase = getReadableDatabase();
Cursor cursor = readableDatabase.rawQuery("select * from " + VERSION_MANAGER + " where " + ID + "=?", new String[]{String.valueOf(id)});
boolean canMoveNext = cursor.moveToNext();
Expand All @@ -139,7 +139,7 @@ Integer queryStatusById(int id) {


//创建记录
long createRecord(Context context, String url, String apk_name, String header, int status, int upgradeFlavor) {
public long createRecord(Context context, String url, String apk_name, String header, int status, int upgradeFlavor) {
String versionName = "";
int versionCode = 0;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.RandomAccessFile;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -40,17 +39,17 @@
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;

import static com.example.r_upgrade.common.UpgradeManager.DOWNLOAD_STATUS;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_APK_NAME;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_CURRENT_LENGTH;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_ID;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_MAX_LENGTH;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_PACKAGE;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_PATH;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_PERCENT;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_PLAN_TIME;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_SPEED;
import static com.example.r_upgrade.common.UpgradeManager.PARAMS_STATUS;
import static com.example.r_upgrade.common.manager.UpgradeManager.DOWNLOAD_STATUS;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_APK_NAME;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_CURRENT_LENGTH;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_ID;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_MAX_LENGTH;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_PACKAGE;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_PATH;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_PERCENT;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_PLAN_TIME;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_SPEED;
import static com.example.r_upgrade.common.manager.UpgradeManager.PARAMS_STATUS;

public class UpgradeService extends Service {
public static final String DOWNLOAD_ID = "download_id";
Expand Down Expand Up @@ -139,6 +138,9 @@ public void onLost(Network network) {
}

private void handleNetworkChange(boolean isConnected) {
if (runnable == null || runnable.isFinish) {
return;
}
if (isConnected) {
RUpgradeLogger.get().d(TAG, "onReceive: 当前网络正在连接");
if (isFirst) {
Expand All @@ -153,6 +155,7 @@ private void handleNetworkChange(boolean isConnected) {
isFirst = false;
return;
}
runnable.handlerDownloadFinish();
runnable.pause(-1);
isFirst = false;
RUpgradeLogger.get().d(TAG, "onReceive: 当前网络已断开");
Expand Down Expand Up @@ -219,6 +222,8 @@ private static class UpgradeRunnable implements Runnable {

private boolean isNewDownload;

private boolean isFinish;

UpgradeRunnable(boolean isReStart, Long id, String url, Map<String, Object> header, String apkName, UpgradeService upgradeService, UpgradeSQLite sqLite) {
this.id = id;
this.url = url;
Expand All @@ -227,12 +232,22 @@ private static class UpgradeRunnable implements Runnable {
this.upgradeService = upgradeService;
this.sqLite = sqLite;
this.isReStart = isReStart;
this.isFinish = false;
}

/**
* cancel timer
*/
private void cancelTimer() {
if (timer != null) {
timer.cancel();
}
}

private void cancel(int id) {
if (isFinish) return;
if (this.id == id) {
timer.cancel();
cancelTimer();
if (httpsURLConnection != null) {
httpsURLConnection.disconnect();
}
Expand All @@ -248,6 +263,8 @@ private void cancel(int id) {
}

private void pause(int id) {
if (isFinish) return;

if (id == -1 || this.id == id) {
if (httpsURLConnection != null) {
httpsURLConnection.disconnect();
Expand Down Expand Up @@ -381,9 +398,7 @@ private void handlerDownloadRunning() {

private void handlerDownloadCancel() {
RUpgradeLogger.get().d(TAG, "handlerDownloadCancel: ");
if (timer != null) {
timer.cancel();
}
cancelTimer();
Intent intent = new Intent();
intent.setAction(DOWNLOAD_STATUS);
intent.putExtra(PARAMS_ID, id);
Expand All @@ -397,9 +412,7 @@ private void handlerDownloadCancel() {

private void handlerDownloadPause() {
RUpgradeLogger.get().d(TAG, "handlerDownloadPause: downloadFile:" + downloadFile);
if (timer != null) {
timer.cancel();
}
cancelTimer();
Intent intent = new Intent();
intent.setAction(DOWNLOAD_STATUS);
intent.putExtra(PARAMS_ID, id);
Expand All @@ -419,9 +432,7 @@ private void handlerDownloadPause() {

private void handlerDownloadFinish() {
RUpgradeLogger.get().d(TAG, "handlerDownloadFinish: finish");
if (timer != null) {
timer.cancel();
}
cancelTimer();
Intent intent = new Intent();
intent.setAction(DOWNLOAD_STATUS);
intent.putExtra(PARAMS_ID, id);
Expand All @@ -432,6 +443,7 @@ private void handlerDownloadFinish() {
upgradeService.sendBroadcast(intent);
sqLite.update(id, null, null, DownloadStatus.STATUS_SUCCESSFUL.getValue());
lastCurrentLength = 0;
isFinish = true;
}

private void handlerDownloadFailure() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.r_upgrade.common.install;

import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;

public abstract class BaseInstallFactory extends ContextWrapper {

public BaseInstallFactory(Context base) {
super(base);
}

public abstract boolean install(Uri uri);
}
Loading

0 comments on commit 5a761ae

Please sign in to comment.