Skip to content

Commit d447e2d

Browse files
committed
update target sdk version to 34
1 parent c5caebf commit d447e2d

15 files changed

+130
-118
lines changed

bither-android/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<uses-permission android:name="android.permission.BLUETOOTH" />
2121
<uses-permission android:name="android.permission.RECORD_AUDIO" />
2222
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
23+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
2324

2425
<!-- -->
2526
<uses-permission android:name="android.permission.GET_TASKS" />
@@ -461,6 +462,7 @@
461462

462463
<service
463464
android:name="net.bither.service.BlockchainService"
465+
android:foregroundServiceType="dataSync"
464466
android:exported="false" />
465467

466468
<receiver

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void onCreate() {
8989
androidDb.construct();
9090
AndroidImplAbstractApp appAndroid = new AndroidImplAbstractApp();
9191
appAndroid.construct();
92-
AbstractApp.notificationService.removeAddressLoadCompleteState();
9392
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll()
9493
.permitDiskReads().permitDiskWrites().penaltyLog().build());
9594
Threading.throwOnLockCycles();

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ private void initActivity() {
229229
BitherApplication.startBlockchainService();
230230
if (!AppSharedPreference.getInstance().getDownloadSpvFinish()) {
231231
initView();
232+
checkWarmDataReady();
232233
dowloadSpvBlock();
233234
configureWarmWait();
234235
} else {
@@ -486,7 +487,6 @@ private void gotoActivity(BitherjSettings.AppMode appMode) {
486487

487488
}
488489
startActivity(intent);
489-
490490
}
491491

492492
private static class ShowHideView {
@@ -599,18 +599,24 @@ public void onAnimationRepeat(Animator animation) {
599599
};
600600

601601
private void checkWarmDataReady() {
602+
if (receiverRegistered) {
603+
return;
604+
}
602605
receiverRegistered = true;
603-
registerReceiver(warmDataReadyReceiver, new IntentFilter(BroadcastUtil
604-
.ACTION_DOWLOAD_SPV_BLOCK));
606+
registerReceiver(warmDataReadyReceiver, new IntentFilter(BroadcastUtil.ACTION_DOWLOAD_SPV_BLOCK));
605607
}
606608

607609
@Override
608610
protected void onDestroy() {
611+
unregisterWarmDataReadyReceiver();
612+
super.onDestroy();
613+
}
614+
615+
private void unregisterWarmDataReadyReceiver() {
609616
if (receiverRegistered) {
610617
unregisterReceiver(warmDataReadyReceiver);
611618
receiverRegistered = false;
612619
}
613-
super.onDestroy();
614620
}
615621

616622
private final OnClickListener warmRetryClick = new OnClickListener() {
@@ -619,6 +625,7 @@ protected void onDestroy() {
619625
public void onClick(View v) {
620626
llWarmExtraError.setVisibility(View.GONE);
621627
llWarmExtraWaiting.setVisibility(View.VISIBLE);
628+
checkWarmDataReady();
622629
dowloadSpvBlock();
623630
}
624631
};
@@ -628,9 +635,8 @@ public void onClick(View v) {
628635
@Override
629636
public void onReceive(Context context, Intent intent) {
630637
LogUtil.d("broadcase", intent.getAction());
631-
boolean completed = intent.getBooleanExtra(BroadcastUtil
632-
.ACTION_DOWLOAD_SPV_BLOCK_STATE, false);
633-
BroadcastUtil.removeBroadcastGetSpvBlockCompelte();
638+
boolean completed = intent.getBooleanExtra(BroadcastUtil.ACTION_DOWLOAD_SPV_BLOCK_STATE, false);
639+
unregisterWarmDataReadyReceiver();
634640
if (AppSharedPreference.getInstance().getDownloadSpvFinish() && completed) {
635641
llWarmExtraError.setVisibility(View.GONE);
636642
llWarmExtraWaiting.setVisibility(View.VISIBLE);
@@ -659,7 +665,6 @@ private void configureWarmWait() {
659665
new WrapLayoutParamsForAnimator(vWarmExtra).setLayoutWeight(1);
660666
new WrapLayoutParamsForAnimator(rlCold).setLayoutWeight(0);
661667
new WrapLayoutParamsForAnimator(vColdBg).setLayoutWeight(0);
662-
checkWarmDataReady();
663668
}
664669

665670
private void configureColdWait() {

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

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public class NotificationAndroidImpl implements NotificationService {
5555
@Override
5656
public void sendBroadcastSyncSPVFinished(boolean isFinished) {
5757
if (isFinished) {
58-
AbstractApp.bitherjSetting.setBitherjDoneSyncFromSpv(isFinished);
58+
AbstractApp.bitherjSetting.setBitherjDoneSyncFromSpv(true);
5959
final Intent broadcast = new Intent(ACTION_SYNC_FROM_SPV_FINISHED);
60-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
60+
sendBroadcast(broadcast);
6161
}
6262
}
6363

@@ -66,17 +66,10 @@ public void sendBroadcastGetSpvBlockComplete(boolean isComplete) {
6666
BroadcastUtil.sendBroadcastGetSpvBlockComplete(isComplete);
6767
}
6868

69-
@Override
70-
public void removeBroadcastSyncSPVFinished() {
71-
BitherApplication.mContext.removeStickyBroadcast(new Intent(
72-
ACTION_SYNC_FROM_SPV_FINISHED));
73-
}
74-
7569
@Override
7670
public void sendLastBlockChange() {
7771
Intent broadcast = new Intent(ACTION_SYNC_LAST_BLOCK_CHANGE);
78-
broadcast.setPackage(BitherApplication.mContext.getPackageName());
79-
BitherApplication.mContext.sendBroadcast(broadcast);
72+
sendBroadcast(broadcast);
8073
}
8174

8275
@Override
@@ -88,8 +81,7 @@ public void notificatTx(String address, Tx tx, Tx.TxNotificationType txNotificat
8881
broadcast.putExtra(MESSAGE_TX, tx.getTxHash());
8982
}
9083
broadcast.putExtra(MESSAGE_TX_NOTIFICATION_TYPE, txNotificationType.getValue());
91-
broadcast.setPackage(BitherApplication.mContext.getPackageName());
92-
BitherApplication.mContext.sendBroadcast(broadcast);
84+
sendBroadcast(broadcast);
9385
log.debug("address " + address
9486
+ " balance updated " + deltaBalance
9587
+ (tx != null ? " tx " + Utils.hashToString(tx.getTxHash()) : "")
@@ -100,73 +92,54 @@ public void notificatTx(String address, Tx tx, Tx.TxNotificationType txNotificat
10092
@Override
10193
public void sendBroadcastPeerState(final int numPeers) {
10294
final Intent broadcast = new Intent(ACTION_PEER_STATE);
103-
10495
broadcast.putExtra(ACTION_PEER_STATE_NUM_PEERS, numPeers);
105-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
106-
}
107-
108-
@Override
109-
public void removeBroadcastPeerState() {
110-
BitherApplication.mContext.removeStickyBroadcast(new Intent(
111-
ACTION_PEER_STATE));
96+
sendBroadcast(broadcast);
11297
}
11398

11499
@Override
115100
public void sendBroadcastAddressLoadCompleteState() {
116101
final Intent broadcast = new Intent(ACTION_ADDRESS_LOAD_COMPLETE_STATE);
117-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
118-
}
119-
120-
@Override
121-
public void removeAddressLoadCompleteState() {
122-
BitherApplication.mContext.removeStickyBroadcast(new Intent(ACTION_ADDRESS_LOAD_COMPLETE_STATE));
102+
sendBroadcast(broadcast);
123103
}
124104

125105
@Override
126106
public void sendConnectedChangeBroadcast(String connectedChangeBroadcast, boolean isConnected) {
127107
Intent intent = new Intent(connectedChangeBroadcast);
128108
intent.putExtra(connectedChangeBroadcast, isConnected);
129-
intent.setPackage(BitherApplication.mContext.getPackageName());
130-
BitherApplication.mContext.sendBroadcast(intent);
109+
sendBroadcast(intent);
131110
}
132111

133112
@Override
134113
public void sendBroadcastProgressState(double value, long unsyncBlockNumber) {
135114
final Intent broadcast = new Intent(ACTION_SYNC_BLOCK_AND_WALLET_STATE);
136115
broadcast.putExtra(ACTION_PROGRESS_INFO, value);
137116
broadcast.putExtra(ACTION_UNSYNC_BLOCK_NUMBER_INFO, unsyncBlockNumber);
138-
broadcast.setPackage(BitherApplication.mContext.getPackageName());
139-
BitherApplication.mContext.sendBroadcast(broadcast);
140-
}
141-
142-
@Override
143-
public void removeProgressState() {
144-
BitherApplication.mContext.removeStickyBroadcast(new Intent
145-
(ACTION_SYNC_BLOCK_AND_WALLET_STATE));
117+
sendBroadcast(broadcast);
146118
}
147119

148120
@Override
149121
public void sendBroadcastAddressTxLoading(String address) {
150122
final Intent broadcast = new Intent(ACTION_ADDRESS_TX_LOADING_STATE);
151123
broadcast.putExtra(ACTION_ADDRESS_TX_LOADING_INFO, address);
152-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
153-
}
154-
155-
@Override
156-
public void removeAddressTxLoading() {
157-
BitherApplication.mContext.removeStickyBroadcast(new Intent(ACTION_ADDRESS_TX_LOADING_STATE));
124+
sendBroadcast(broadcast);
158125
}
159126

160127
@Override
161128
public void sendBroadcastAddressTxLoadError() {
162129
final Intent broadcast = new Intent(ACTION_ADDRESS_TX_LOADING_STATE);
163130
broadcast.putExtra(ACTION_ADDRESS_TX_LOAD_ERROR_INFO, true);
164-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
131+
sendBroadcast(broadcast);
165132
}
166133

167134
@Override
168135
public void sendMinerFeeChange() {
169136
final Intent broadcast = new Intent(ACTION_MINER_FEE_CHANGE);
170-
BitherApplication.mContext.sendStickyBroadcast(broadcast);
137+
sendBroadcast(broadcast);
171138
}
139+
140+
static public void sendBroadcast(Intent intent) {
141+
intent.setPackage(BitherApplication.mContext.getPackageName());
142+
BitherApplication.mContext.sendBroadcast(intent);
143+
}
144+
172145
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ public class HotActivity extends BaseFragmentActivity {
104104
private final MinerFeeBroadcastReceiver minerFeeBroadcastReceiver = new MinerFeeBroadcastReceiver();
105105

106106
protected void onCreate(Bundle savedInstanceState) {
107-
AbstractApp.notificationService.removeProgressState();
108-
AbstractApp.notificationService.removeAddressTxLoading();
109107
initAppState();
110108
super.onCreate(savedInstanceState);
111109
BitherApplication.hotActivity = this;
@@ -142,14 +140,12 @@ public void run() {
142140
}
143141

144142
private void registerReceiver() {
145-
registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl
146-
.ACTION_SYNC_BLOCK_AND_WALLET_STATE));
143+
registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_SYNC_BLOCK_AND_WALLET_STATE));
147144
IntentFilter intentFilter = new IntentFilter();
148145
intentFilter.addAction(NotificationAndroidImpl.ACTION_SYNC_LAST_BLOCK_CHANGE);
149146
intentFilter.addAction(NotificationAndroidImpl.ACTION_ADDRESS_BALANCE);
150147
registerReceiver(txAndBlockBroadcastReceiver, intentFilter);
151-
registerReceiver(addressIsLoadedReceiver,
152-
new IntentFilter(NotificationAndroidImpl.ACTION_ADDRESS_LOAD_COMPLETE_STATE));
148+
registerReceiver(addressIsLoadedReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_ADDRESS_LOAD_COMPLETE_STATE));
153149
registerReceiver(addressIsLoadingReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_ADDRESS_TX_LOADING_STATE));
154150
registerReceiver(peerConnectedChangeReceiver, new IntentFilter(ConnectedChangeBroadcast));
155151
registerReceiver(minerFeeBroadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_MINER_FEE_CHANGE));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ protected void onCreate(Bundle savedInstanceState) {
141141
super.onCreate(savedInstanceState);
142142
overridePendingTransition(R.anim.slide_in_right, 0);
143143
setContentView(R.layout.activity_hot_advance_options);
144-
AbstractApp.notificationService.removeAddressTxLoading();
145144
initView();
146145
registerReceiver();
147146
}
@@ -242,7 +241,7 @@ public void onReceive(Context context, Intent intent) {
242241
private View.OnClickListener signHashClick = new View.OnClickListener() {
243242
@Override
244243
public void onClick(View v) {
245-
new DialogSignMessageSelectType(HotAdvanceActivity.this,false, true).show();
244+
new DialogSignMessageSelectType(HotAdvanceActivity.this, true, true).show();
246245
}
247246
};
248247

bither-android/src/net/bither/fragment/hot/BlockListFragment.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.Context;
2222
import android.content.Intent;
2323
import android.content.IntentFilter;
24+
import android.os.Build;
2425
import android.os.Bundle;
2526
import android.support.v4.app.ListFragment;
2627
import android.support.v4.app.LoaderManager;
@@ -110,8 +111,11 @@ public void onCreate(final Bundle savedInstanceState) {
110111
public void onResume() {
111112
super.onResume();
112113
if (!isRegister) {
113-
activity.registerReceiver(tickReceiver, new IntentFilter(
114-
Intent.ACTION_TIME_TICK));
114+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
115+
activity.registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK), Context.RECEIVER_NOT_EXPORTED);
116+
} else {
117+
activity.registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
118+
}
115119
isRegister = true;
116120
}
117121
loaderManager.initLoader(ID_TRANSACTION_LOADER, null,
@@ -319,16 +323,17 @@ private BlockLoader(final Context context) {
319323
@Override
320324
protected void onStartLoading() {
321325
super.onStartLoading();
322-
323-
context.registerReceiver(broadcastReceiver, new IntentFilter(
324-
NotificationAndroidImpl.ACTION_SYNC_LAST_BLOCK_CHANGE));
326+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
327+
context.registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_SYNC_LAST_BLOCK_CHANGE), Context.RECEIVER_NOT_EXPORTED);
328+
} else {
329+
context.registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_SYNC_LAST_BLOCK_CHANGE));
330+
}
325331
forceLoad();
326332
}
327333

328334
@Override
329335
protected void onStopLoading() {
330336
context.unregisterReceiver(broadcastReceiver);
331-
332337
super.onStopLoading();
333338
}
334339

bither-android/src/net/bither/fragment/hot/PeerListFragment.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.content.Intent;
2323
import android.content.IntentFilter;
2424
import android.graphics.Typeface;
25+
import android.os.Build;
2526
import android.os.Bundle;
2627
import android.os.Handler;
2728
import android.support.v4.app.ListFragment;
@@ -45,6 +46,7 @@
4546
import org.slf4j.LoggerFactory;
4647

4748
import java.net.InetAddress;
49+
import java.util.ArrayList;
4850
import java.util.Collections;
4951
import java.util.Comparator;
5052
import java.util.List;
@@ -224,15 +226,16 @@ private PeerLoader(final Context context) {
224226
@Override
225227
protected void onStartLoading() {
226228
super.onStartLoading();
227-
228-
context.registerReceiver(broadcastReceiver, new IntentFilter(
229-
NotificationAndroidImpl.ACTION_PEER_STATE));
229+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
230+
context.registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_PEER_STATE), Context.RECEIVER_NOT_EXPORTED);
231+
} else {
232+
context.registerReceiver(broadcastReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_PEER_STATE));
233+
}
230234
}
231235

232236
@Override
233237
protected void onStopLoading() {
234238
context.unregisterReceiver(broadcastReceiver);
235-
236239
super.onStopLoading();
237240
}
238241

@@ -276,8 +279,9 @@ public void onLoaderReset(final Loader<List<Peer>> loader) {
276279
};
277280

278281
private void refreshPeer() {
279-
if (peerCacheList != null) {
280-
Collections.sort(peerCacheList, new Comparator<Peer>() {
282+
if (peerCacheList != null && peerCacheList.size() > 0) {
283+
ArrayList<Peer> peers = new ArrayList<>(peerCacheList);
284+
Collections.sort(peers, new Comparator<Peer>() {
281285
@Override
282286
public int compare(Peer lhs, Peer rhs) {
283287
if (lhs.getClientVersion() == 0 && rhs.getClientVersion() > 0) {
@@ -292,7 +296,7 @@ public int compare(Peer lhs, Peer rhs) {
292296

293297
}
294298
});
295-
for (final Peer peer : peerCacheList) {
299+
for (final Peer peer : peers) {
296300
adapter.add(peer);
297301
}
298302
}

0 commit comments

Comments
 (0)