Skip to content

Commit 705f583

Browse files
committed
modify sync data
1 parent cd8749c commit 705f583

14 files changed

+149
-288
lines changed

bither-android/AndroidManifest.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.INTERNET" />
88
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
99
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
10+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1011
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
1112
android:maxSdkVersion="32" />
1213
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
@@ -19,8 +20,6 @@
1920
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2021
<uses-permission android:name="android.permission.BLUETOOTH" />
2122
<uses-permission android:name="android.permission.RECORD_AUDIO" />
22-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
23-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
2423

2524
<!-- -->
2625
<uses-permission android:name="android.permission.GET_TASKS" />
@@ -460,11 +459,6 @@
460459
</intent-filter>
461460
</activity>
462461

463-
<service
464-
android:name="net.bither.service.BlockchainService"
465-
android:foregroundServiceType="dataSync"
466-
android:exported="false" />
467-
468462
<receiver
469463
android:name="net.bither.receiver.AutosyncReceiver"
470464
android:exported="false">

bither-android/src/net/bither/BitherApplication.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
import android.app.ActivityManager;
2121
import android.app.Application;
2222
import android.content.Context;
23-
import android.content.Intent;
2423
import android.database.sqlite.SQLiteOpenHelper;
25-
import android.os.Build;
2624
import android.os.StrictMode;
2725
import android.support.multidex.MultiDex;
2826

2927
import net.bither.activity.cold.ColdActivity;
3028
import net.bither.activity.hot.HotActivity;
31-
import net.bither.bitherj.AbstractApp;
3229
import net.bither.bitherj.BitherjSettings;
3330
import net.bither.bitherj.core.AddressManager;
34-
import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
3531
import net.bither.bitherj.utils.Threading;
3632
import net.bither.db.AddressDatabaseHelper;
3733
import net.bither.db.AndroidDbImpl;
@@ -108,14 +104,9 @@ public static BitherApplication getBitherApplication() {
108104
}
109105

110106
public static void startBlockchainService() {
111-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
112-
mContext.startForegroundService(new Intent(mContext, BlockchainService.class));
113-
} else {
114-
mContext.startService(new Intent(mContext, BlockchainService.class));
115-
}
107+
BlockchainService.getInstance().onStart();
116108
}
117109

118-
119110
public static boolean canReloadTx() {
120111
if (reloadTxTime == -1) {
121112
return true;

bither-android/src/net/bither/ChooseModeActivity.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import android.content.Intent;
2626
import android.content.IntentFilter;
2727
import android.graphics.Typeface;
28-
import android.os.Build;
2928
import android.os.Bundle;
3029
import android.os.Handler;
3130
import android.text.Spannable;
@@ -283,7 +282,7 @@ public void onClick(View v) {
283282
new Runnable() {
284283
@Override
285284
public void run() {
286-
stopService(new Intent(ChooseModeActivity.this, BlockchainService.class));
285+
BlockchainService.getInstance().onStop();
287286
runOnUiThread(new Runnable() {
288287
@Override
289288
public void run() {
@@ -327,7 +326,7 @@ public void onClick(View v) {
327326
new Runnable() {
328327
@Override
329328
public void run() {
330-
stopService(new Intent(ChooseModeActivity.this, BlockchainService.class));
329+
BlockchainService.getInstance().onStop();
331330
runOnUiThread(new Runnable() {
332331
@Override
333332
public void run() {
@@ -700,14 +699,7 @@ private SpannableString getUpgradeString() {
700699
}
701700

702701
private void dowloadSpvBlock() {
703-
Intent intent = new Intent(
704-
BlockchainService.ACTION_BEGIN_DOWLOAD_SPV_BLOCK, null,
705-
BitherApplication.mContext, BlockchainService.class);
706-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
707-
BitherApplication.mContext.startForegroundService(intent);
708-
} else {
709-
BitherApplication.mContext.startService(intent);
710-
}
702+
BlockchainService.getInstance().downloadSpvBlock();
711703
}
712704

713705
@Override

bither-android/src/net/bither/activity/hot/HotActivity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@
1616

1717
package net.bither.activity.hot;
1818

19+
import android.Manifest;
1920
import android.app.NotificationManager;
2021
import android.content.BroadcastReceiver;
2122
import android.content.Context;
2223
import android.content.Intent;
2324
import android.content.IntentFilter;
25+
import android.content.pm.PackageManager;
26+
import android.os.Build;
2427
import android.os.Bundle;
2528
import android.os.Handler;
2629
import android.os.Looper;
30+
import android.support.annotation.RequiresApi;
31+
import android.support.v4.app.ActivityCompat;
2732
import android.support.v4.app.Fragment;
33+
import android.support.v4.content.ContextCompat;
2834
import android.support.v4.view.ViewPager;
2935
import android.support.v4.view.ViewPager.OnPageChangeListener;
3036
import android.view.View;
@@ -103,6 +109,8 @@ public class HotActivity extends BaseFragmentActivity {
103109
private final PeerConnectedChangeReceiver peerConnectedChangeReceiver = new PeerConnectedChangeReceiver();
104110
private final MinerFeeBroadcastReceiver minerFeeBroadcastReceiver = new MinerFeeBroadcastReceiver();
105111

112+
private static final int REQUEST_NOTIFICATION_PERMISSION = 100;
113+
106114
protected void onCreate(Bundle savedInstanceState) {
107115
initAppState();
108116
super.onCreate(savedInstanceState);
@@ -137,6 +145,16 @@ public void run() {
137145
pbAlert.setVisibility(View.VISIBLE);
138146
llAlert.setVisibility(View.VISIBLE);
139147
}
148+
checkNotificationPermission();
149+
150+
}
151+
152+
private void checkNotificationPermission() {
153+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
154+
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
155+
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQUEST_NOTIFICATION_PERMISSION);
156+
}
157+
}
140158
}
141159

142160
private void registerReceiver() {

bither-android/src/net/bither/activity/hot/HotAdvanceActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ public void onOptionIndexSelected(int index) {
11251125
.OnlyOpenApp);
11261126
break;
11271127
}
1128-
1128+
BlockchainService.getInstance().scheduleSync();
11291129
}
11301130
};
11311131

bither-android/src/net/bither/receiver/AutosyncReceiver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ public class AutosyncReceiver extends BroadcastReceiver {
3030

3131
@Override
3232
public void onReceive(final Context context, final Intent intent) {
33-
if (intent == null) {
33+
if (intent == null || intent.getAction() == null) {
3434
return;
3535
}
3636
LogUtil.d("receiver", intent.getAction());
3737
// make sure there is always an alarm scheduled
3838
if (!Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())
3939
|| (Utils.compareString(intent.getDataString(), "package:" + context.getPackageName()))) {
4040
if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
41-
BitherApplication.getBitherApplication()
42-
.startBlockchainService();
41+
BitherApplication.startBlockchainService();
4342
}
4443
}
4544
}

bither-android/src/net/bither/runnable/ThreadNeedService.java

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,30 @@
1616

1717
package net.bither.runnable;
1818

19-
20-
import android.content.ComponentName;
2119
import android.content.Context;
22-
import android.content.Intent;
23-
import android.content.ServiceConnection;
24-
import android.os.IBinder;
2520

2621
import net.bither.bitherj.BitherjSettings;
2722
import net.bither.preference.AppSharedPreference;
2823
import net.bither.service.BlockchainService;
29-
import net.bither.service.LocalBinder;
3024
import net.bither.ui.base.dialog.DialogProgress;
3125

3226
public abstract class ThreadNeedService extends Thread {
3327
protected DialogProgress dp;
34-
private BlockchainService service;
35-
private Context context;
36-
private boolean connected = false;
37-
private boolean needService = AppSharedPreference.getInstance()
38-
.getAppMode() == BitherjSettings.AppMode.HOT;
28+
private boolean needService = AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT;
3929

4030
public ThreadNeedService(DialogProgress dp, Context context) {
4131
this.dp = dp;
42-
this.context = context;
4332
}
4433

4534
abstract public void runWithService(BlockchainService service);
4635

4736
@Override
4837
public void run() {
4938
if (needService) {
50-
if (service != null) {
51-
runWithService(service);
52-
}
39+
runWithService(BlockchainService.getInstance());
5340
} else {
5441
runWithService(null);
5542
}
56-
if (connected) {
57-
context.unbindService(connection);
58-
}
5943
if (dp != null) {
6044
dp.setThread(null);
6145
}
@@ -67,32 +51,10 @@ public synchronized void start() {
6751
dp.show();
6852
dp.setCancelable(false);
6953
}
70-
if (needService) {
71-
connected = context.bindService(new Intent(context,
72-
BlockchainService.class), connection,
73-
Context.BIND_AUTO_CREATE);
74-
} else {
75-
if (dp != null) {
76-
dp.setThread(this);
77-
}
78-
super.start();
54+
if (dp != null) {
55+
dp.setThread(this);
7956
}
57+
super.start();
8058
}
8159

82-
private ServiceConnection connection = new ServiceConnection() {
83-
84-
@Override
85-
public void onServiceDisconnected(ComponentName name) {
86-
}
87-
88-
@Override
89-
public void onServiceConnected(ComponentName name, IBinder binder) {
90-
ThreadNeedService.this.service = ((LocalBinder) binder)
91-
.getService();
92-
if (dp != null) {
93-
dp.setThread(ThreadNeedService.this);
94-
}
95-
ThreadNeedService.super.start();
96-
}
97-
};
9860
}

0 commit comments

Comments
 (0)