Skip to content

Commit

Permalink
fix: Require password when unhide with tile (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltazefiro committed Jul 6, 2023
1 parent 49bd343 commit db74d73
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<activity
android:name=".ui.SetHideAppActivity"
android:exported="true" />
<activity
android:name=".ui.SecurityAuthForQuickHideActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@style/Theme.Amarok.Transparent" />

<service
android:name=".QuickSettingService"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/deltazero/amarok/QuickSettingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ServiceLifecycleDispatcher;

import deltazero.amarok.ui.SecurityAuthForQuickHideActivity;

public class QuickSettingService extends TileService implements LifecycleOwner {

private static final String TAG = "TileService";
Expand Down Expand Up @@ -113,7 +115,8 @@ public void onClick() {
unlockAndRun(() -> {
Log.i(TAG, "Toggled tile.");
if (prefMgr.getIsHidden()) {
hider.unhide();
startActivityAndCollapse(new Intent(this, SecurityAuthForQuickHideActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
hider.hide();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package deltazero.amarok.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import deltazero.amarok.Hider;
import deltazero.amarok.R;
import deltazero.amarok.utils.SecurityAuth;

/**
* An empty & transparent activity with a SecurityAuth dialog only.
* If the SecurityAuth is passed, unhide files and apps. Otherwise, finish the activity.
*/
public class SecurityAuthForQuickHideActivity extends AppCompatActivity {

private SecurityAuth securityAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);

securityAuth = new SecurityAuth(this, succeed -> {
if (succeed)
new Hider(this).unhide();
finish();
});
}

@Override
protected void onStart() {
super.onStart();
Log.i("SecurityAuth", "Start SecurityAuthForQuickHideActivity");
securityAuth.authenticate();
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/deltazero/amarok/utils/SecurityAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ public interface SecurityAuthCallback {
private SecurityAuthCallback callback;
private FragmentActivity activity;
private PrefMgr prefMgr;
private PasswordAuthFragment passwordAuthFragment;

public SecurityAuth(FragmentActivity activity, SecurityAuthCallback callback) {
this.callback = callback;
this.activity = activity;
prefMgr = new PrefMgr(activity);
if (passwordAuthFragment == null)
passwordAuthFragment = new PasswordAuthFragment();
}

public void authenticate() {
if (passwordAuthFragment.isAdded())
passwordAuthFragment.dismiss();
if (prefMgr.getAmarokPassword() != null) {
if (prefMgr.getEnableAmarokBiometricAuth()) biometricAuthenticate();
else passwordAuthenticate();
Expand All @@ -35,7 +40,7 @@ public void authenticate() {

private void passwordAuthenticate() {
assert prefMgr.getAmarokPassword() != null;
new PasswordAuthFragment()
passwordAuthFragment
.setOnVerifiedCallback(succeed -> callback.onSecurityAuthCallback(succeed))
.show(activity.getSupportFragmentManager(), null);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>
9 changes: 9 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
<!-- <item name="android:textColorPrimary">@color/black</item>-->
<!-- <item name="android:textColorSecondary">@color/grey</item>-->
</style>

<style name="Theme.Amarok.Transparent" parent="Theme.Amarok">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

0 comments on commit db74d73

Please sign in to comment.