lock in background (#936)

This commit is contained in:
m2049r 2024-04-05 16:03:30 +02:00 committed by GitHub
parent 451371cd92
commit 48577e46aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 150 additions and 29 deletions

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 m2049r
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.m2049r.xmrwallet;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import timber.log.Timber;
public class LockFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Timber.d("onCreateView");
final FrameLayout frame = new FrameLayout(requireContext());
frame.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return frame;
}
}

View File

@ -76,6 +76,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import timber.log.Timber;
public class LoginActivity extends BaseActivity

View File

@ -45,6 +45,7 @@ import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.navigation.NavigationView;
@ -70,6 +71,7 @@ import com.m2049r.xmrwallet.widget.Toolbar;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import timber.log.Timber;
public class WalletActivity extends BaseActivity implements WalletFragment.Listener,
@ -200,12 +202,6 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
return getWallet().getSubaddress(major, minor);
}
@Override
protected void onStart() {
super.onStart();
Timber.d("onStart()");
}
private void startWalletService() {
Bundle extras = getIntent().getExtras();
if (extras != null) {
@ -239,12 +235,6 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
}
}
@Override
protected void onStop() {
Timber.d("onStop()");
super.onStop();
}
@Override
protected void onDestroy() {
Timber.d("onDestroy()");
@ -498,12 +488,16 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
@Override
protected void onPause() {
Timber.d("onPause()");
lock();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (locked) {
unlock();
}
Timber.d("onResume()");
}
@ -1216,4 +1210,31 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
getWallet().setPocketChangeSetting(Wallet.PocketChangeSetting.from(settings));
}
@Getter
private boolean locked = false;
private void unlock() {
Helper.promptPassword(WalletActivity.this, getWalletName(), false, new Helper.PasswordAction() {
@Override
public void act(String walletName, String password, boolean fingerprintUsed) {
popFragmentStack(null);
locked = false;
Timber.d("locked: %b", isLocked());
}
@Override
public void fail(String walletName) {
finish();
}
});
}
private void lock() {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.preferred_lock), false)) {
replaceFragment(new LockFragment(), null, null);
locked = true;
}
Timber.d("locked %b", isLocked());
}
}

View File

@ -478,7 +478,6 @@ public class Helper {
.setPositiveButton(context.getString(R.string.label_ok), null)
.setNegativeButton(context.getString(R.string.label_cancel),
(dialog, id) -> {
action.fail(wallet);
Helper.hideKeyboardAlways((Activity) context);
cancelSignal.cancel();
if (passwordTask != null) {
@ -487,6 +486,7 @@ public class Helper {
}
dialog.cancel();
openDialog = null;
action.fail(wallet);
});
openDialog = alertDialogBuilder.create();

View File

@ -4,7 +4,8 @@ import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import com.m2049r.xmrwallet.BuildConfig;
import com.m2049r.xmrwallet.model.WalletManager;

View File

@ -19,7 +19,8 @@ package com.m2049r.xmrwallet.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import com.m2049r.xmrwallet.R;

View File

@ -18,8 +18,8 @@ package com.m2049r.xmrwallet.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatDelegate;
import com.m2049r.xmrwallet.R;

View File

@ -1,16 +1,9 @@
package com.m2049r.xmrwallet.util;
import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.model.NetworkType;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.service.exchange.api.ExchangeApi;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import lombok.NonNull;
import okhttp3.HttpUrl;
public class ServiceHelper {

View File

@ -19,7 +19,9 @@ package com.m2049r.xmrwallet.util;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import android.util.TypedValue;
import androidx.annotation.ColorInt;

View File

@ -445,4 +445,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -446,4 +446,6 @@
<string name="pocketchange_create_title">Erstelle schnellen Wechsel</string>
<string name="label_apply">ANWENDEN</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -447,4 +447,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -445,4 +445,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -438,9 +438,10 @@
<string name="tx_locked">Monto trabado hasta el bloque %1$d (faltan %2$d bloques ≈ %3$,.2f días)</string>
<string name="label_streetmode">Modo calle activado\nSólo se ºmostrarán transacciones nuevas</string>
<string name="pocketchange_info">Para reducir el tiempo entre pagos, Monerujo puede crear cambio de más al enviar a costo de comisiones más altas. Va a crear e intentar mantener 10 monedas del monto seleccionado.</string>
<string name="pocketchange_create_title">Crear cambio</string>
<string name="pocketchange_info">Para reducir el tiempo entre pagos, Monerujo puede crear cambio de más al enviar a costo de comisiones más altas. Va a crear e intentar mantener 10 monedas del monto seleccionado.</string>
<string name="pocketchange_create_title">Crear cambio</string>
<string name="label_apply">APLICAR</string>
<string name="label_apply">APLICAR</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -445,4 +445,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -685,4 +685,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -458,4 +458,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -436,4 +436,15 @@
</string-array>
<string name="message_qr_failed">לא הצליח ליצור QR לשיתוף!</string>
<string name="tx_locked">Transaction amount locked until block %1$d (in %2$d blocks ≈ %3$,.2f days)</string>
<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -449,4 +449,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -450,4 +450,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -450,4 +450,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -447,4 +447,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -447,4 +447,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -440,4 +440,6 @@ aqui.</string>
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -451,4 +451,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -447,4 +447,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -451,4 +451,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -448,4 +448,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -446,4 +446,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -439,4 +439,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -445,4 +445,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -451,4 +451,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -372,4 +372,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -446,4 +446,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -469,6 +469,7 @@
<string name="preferred_theme" translatable="false">preferred_theme</string>
<string name="preferred_nightmode" translatable="false">preferred_nightmode</string>
<string name="preferred_locale" translatable="false">preferred_locale</string>
<string name="preferred_lock" translatable="false">preferred_lock</string>
<string name="about_info" translatable="false">about_info</string>
<string name="privacy_info" translatable="false">privacy_info</string>
<string name="credits_info" translatable="false">credits_info</string>
@ -498,4 +499,6 @@
<string name="pocketchange_create_title">Create Change</string>
<string name="label_apply">APPLY</string>
<string name="setting_lock">Lock Wallet in Background</string>
</resources>

View File

@ -20,6 +20,10 @@
app:key="@string/preferred_theme"
app:title="@string/setting_theme"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/preferred_lock"
android:title="@string/setting_lock" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/title_info">
<Preference

View File

@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.3.0'
classpath 'com.android.tools.build:gradle:8.3.1'
}
}