Skip to content

Commit

Permalink
Update service handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Apr 23, 2024
1 parent 00dc7bc commit 9abc000
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 57 deletions.
10 changes: 5 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<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.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<!-- Note: this permission is used to display the active WalletConnect Notification. This is a courtesy to the user to inform them a WalletConnect channel is active -->
<!-- This is pegged to class WalletConnectV2Service which has no data connection, the data connection is only active when the AlphaWallet app is open -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

<uses-feature
Expand Down Expand Up @@ -122,10 +121,11 @@
android:name=".ui.SplashActivity"
android:theme="@style/AppTheme.NoActionBar.Splash" />

<!-- Note: this service is used to display the active WalletConnect Notification. This is a courtesy to the user to inform them a WalletConnect channel is active -->
<service
android:name=".service.WalletConnectV2Service"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:foregroundServiceType="specialUse"
android:exported="false">
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
createNotificationChannel();
}
Notification notification = createNotification();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
{
startForeground(startId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
startForeground(startId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ private void initializeSettings()
.withListener(this::onClearBrowserCacheClicked)
.build();

tokenScript = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_tokenscript)
.withTitle(R.string.title_tokenscript)
.withListener(this::onTokenScriptClicked)
.build();

//TODO Change Icon
tokenScriptManagement = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_tokenscript_manage)
Expand Down Expand Up @@ -191,10 +185,6 @@ private void addSettingsToLayout()
advancedSettingsLayout.addView(nodeStatus);
advancedSettingsLayout.addView(console);
advancedSettingsLayout.addView(clearBrowserCache);

if (!checkWritePermission() && EthereumNetworkRepository.extraChains() == null)
advancedSettingsLayout.addView(tokenScript);

advancedSettingsLayout.addView(tokenScriptManagement);
advancedSettingsLayout.addView(fullScreenSettings);
advancedSettingsLayout.addView(refreshTokenDatabase);
Expand Down Expand Up @@ -300,11 +290,6 @@ private void showResetResult(boolean resetResult)
}
}

private void onTokenScriptClicked()
{
showXMLOverrideDialog();
}

private void onTokenScriptManagementClicked()
{
Intent intent = new Intent(this, TokenScriptManagementActivity.class);
Expand All @@ -323,40 +308,6 @@ private void onAnalyticsClicked()
startActivity(intent);
}

private void showXMLOverrideDialog()
{
AWalletConfirmationDialog cDialog = new AWalletConfirmationDialog(this);
cDialog.setTitle(R.string.enable_xml_override_dir);
cDialog.setSmallText(R.string.explain_xml_override);
cDialog.setMediumText(R.string.ask_user_about_xml_override);
cDialog.setPrimaryButtonText(R.string.dialog_ok);
cDialog.setPrimaryButtonListener(v ->
{
//ask for OS permission and write directory
askWritePermission();
cDialog.dismiss();
});
cDialog.setSecondaryButtonText(R.string.dialog_cancel_back);
cDialog.setSecondaryButtonListener(v ->
{
cDialog.dismiss();
});
cDialog.show();
}

private void askWritePermission()
{
final String[] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
Timber.w("Folder write permission is not granted. Requesting permission");
ActivityCompat.requestPermissions(this, permissions, HomeActivity.RC_ASSET_EXTERNAL_WRITE_PERM);
}

private boolean checkWritePermission()
{
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void dialogConfirmDelete(WalletConnectSessionItem session)
@Override
public void onSessionDisconnected()
{
//runOnUiThread(() -> awWalletConnectClient.updateNotification());
runOnUiThread(() -> awWalletConnectClient.updateNotification(null));
}
}));
cDialog.setSecondaryButtonText(R.string.action_cancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public void onSessionProposalRejected()
@Override
public void onSessionDisconnected()
{
runOnUiThread(() -> awWalletConnectClient.updateNotification(null));
finish();
}
}

0 comments on commit 9abc000

Please sign in to comment.