Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
deltazefiro committed Jul 7, 2023
2 parents 5953da8 + 1b1987c commit 3195d6c
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 35 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ dependencies {
implementation "dev.rikka.shizuku:api:${shizukuVersion}"
implementation "dev.rikka.shizuku:provider:${shizukuVersion}"

def appCenterSdkVersion = '5.0.1'
def appCenterSdkVersion = '5.0.2'
appcenterImplementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
appcenterImplementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
appcenterImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"

implementation 'com.github.Dimezis:BlurView:version-2.0.3'
implementation 'com.github.getActivity:XXPermissions:16.8'
implementation 'com.github.getActivity:XToast:8.9'
implementation 'io.github.iamr0s:Dhizuku-API:2.4'
implementation 'com.github.getActivity:XXPermissions:18.2'
implementation 'com.github.getActivity:EasyWindow:10.2'
implementation 'com.github.heruoxin.Delegated-Scopes-Manager:client:master-SNAPSHOT'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.android.material:material:1.9.0'
implementation "androidx.biometric:biometric:1.1.0"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@
</activity>
<activity
android:name=".ui.SwitchFileHiderActivity"
android:exported="true" />
android:exported="false" />
<activity
android:name=".ui.SwitchAppHiderActivity"
android:exported="true" />
android:exported="false" />
<activity
android:name=".ui.SetHideFilesActivity"
android:exported="true" />
android:exported="false" />
<activity
android:name=".ui.SettingsActivity"
android:exported="true" />
android:exported="false" />
<activity
android:name=".ui.SetHideAppActivity"
android:exported="true" />
android:exported="false" />
<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: 5 additions & 0 deletions app/src/main/java/deltazero/amarok/AmarokApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.app.Application;

import com.rosan.dhizuku.api.Dhizuku;

public class AmarokApp extends Application {

@Override
Expand All @@ -10,5 +12,8 @@ public void onCreate() {

// Start PanicButton service
QuickHideService.startService(this);

// init dhizuku
Dhizuku.init();
}
}
94 changes: 94 additions & 0 deletions app/src/main/java/deltazero/amarok/AppHider/DhizukuHider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package deltazero.amarok.AppHider;

import static android.app.admin.DevicePolicyManager.DELEGATION_PACKAGE_ACCESS;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import com.rosan.dhizuku.api.Dhizuku;
import com.rosan.dhizuku.api.DhizukuRequestPermissionListener;

import java.util.Arrays;
import java.util.Set;

import deltazero.amarok.R;

public class DhizukuHider extends AppHiderBase {

private final DevicePolicyManager devicePolicyManager;

public DhizukuHider(Context context) {
super(context);
devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
}

@Override
public void hide(Set<String> pkgNames) {
setDelegatedScopes();
for (var pkgName : pkgNames) {
devicePolicyManager.setApplicationHidden(null, pkgName, true);
}
}

@Override
public void unhide(Set<String> pkgNames) {
setDelegatedScopes();
for (var pkgName : pkgNames) {
devicePolicyManager.setApplicationHidden(null, pkgName, false);
}
}

@Override
public CheckAvailabilityResult checkAvailability() {
if (!Dhizuku.init()) {
Log.w("DhizukuHider", "Dhizuku not init.");
return new CheckAvailabilityResult(CheckAvailabilityResult.Result.UNAVAILABLE, R.string.dhizuku_not_init);
}

if (Dhizuku.getVersionCode() < 5) {
Log.w("DhizukuHider", "Unsupported Dhizuku version: pre v5.x");
return new CheckAvailabilityResult(CheckAvailabilityResult.Result.UNAVAILABLE, R.string.dhizuku_pre_v5);
}

return Dhizuku.isPermissionGranted()
? new CheckAvailabilityResult(CheckAvailabilityResult.Result.AVAILABLE)
: new CheckAvailabilityResult(CheckAvailabilityResult.Result.REQ_PERM);
}

@Override
public void active(OnActivateCallbackListener onActivateCallbackListener) {
CheckAvailabilityResult r = checkAvailability();
switch (r.result) {
case UNAVAILABLE ->
onActivateCallbackListener.onActivateCallback(this.getClass(), false, r.msgResID);
case AVAILABLE ->
onActivateCallbackListener.onActivateCallback(this.getClass(), true, 0);
case REQ_PERM -> Dhizuku.requestPermission(new DhizukuRequestPermissionListener() {
@Override
public void onRequestPermission(int grantResult) {
if (grantResult == PackageManager.PERMISSION_GRANTED) {
Log.d("DhizukuHider", "Permission granted.");
onActivateCallbackListener.onActivateCallback(DhizukuHider.class, true, 0);
} else {
Log.d("DhizukuHider", "Permission denied.");
onActivateCallbackListener.onActivateCallback(DhizukuHider.class, false, R.string.dhizuku_permission_denied);
}
}
});
}
}

@Override
public String getName() {
return "Dhizuku";
}

private void setDelegatedScopes() {
if (Arrays.asList(Dhizuku.getDelegatedScopes())
.contains(DELEGATION_PACKAGE_ACCESS))
return;
Dhizuku.setDelegatedScopes(new String[]{DELEGATION_PACKAGE_ACCESS});
}
}
33 changes: 19 additions & 14 deletions app/src/main/java/deltazero/amarok/PrefMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Set;

import deltazero.amarok.AppHider.AppHiderBase;
import deltazero.amarok.AppHider.DhizukuHider;
import deltazero.amarok.AppHider.DsmAppHider;
import deltazero.amarok.AppHider.NoneAppHider;
import deltazero.amarok.AppHider.RootAppHider;
Expand Down Expand Up @@ -58,26 +59,30 @@ public void setHideApps(Set<String> pkgNames) {
}

public AppHiderBase getAppHider() {
switch (mPrefs.getInt("appHiderMode", 0)) {
case 1:
return new RootAppHider(context);
case 2:
return new DsmAppHider(context);
case 3:
return new ShizukuHider(context);
default:
return new NoneAppHider(context);
}
return switch (mPrefs.getInt("appHiderMode", 0)) {
case 0 -> new NoneAppHider(context);
case 1 -> new RootAppHider(context);
case 2 -> new DsmAppHider(context);
case 3 -> new ShizukuHider(context);
case 4 -> new DhizukuHider(context);
default -> throw new IndexOutOfBoundsException();
};
}

public void setAppHiderMode(Class<? extends AppHiderBase> mode) {
int modeCode = 0;
if (mode == RootAppHider.class)
int modeCode;
if (mode == NoneAppHider.class)
modeCode = 0;
else if (mode == RootAppHider.class)
modeCode = 1;
if (mode == DsmAppHider.class)
else if (mode == DsmAppHider.class)
modeCode = 2;
if (mode == ShizukuHider.class)
else if (mode == ShizukuHider.class)
modeCode = 3;
else if (mode == DhizukuHider.class)
modeCode = 4;
else
throw new IndexOutOfBoundsException();
mPrefEditor.putInt("appHiderMode", modeCode);
mPrefEditor.apply();
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/deltazero/amarok/QuickHideService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.xtoast.XToast;
import com.hjq.xtoast.draggable.SpringDraggable;
import com.hjq.window.EasyWindow;
import com.hjq.window.draggable.SpringDraggable;

import deltazero.amarok.ui.MainActivity;

public class QuickHideService extends LifecycleService {

private MutableLiveData<Boolean> isProcessing;
private XToast<?> panicButton;
private EasyWindow<?> panicButton;
private Hider hider;
private ImageView ivPanicButton;

Expand Down Expand Up @@ -87,13 +87,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
isServiceRunning = true;

// Init panic button
panicButton = new XToast<>(getApplication())
panicButton = new EasyWindow<>(getApplication())
.setContentView(R.layout.dialog_panic_button)
.setGravity(Gravity.END | Gravity.BOTTOM)
.setYOffset(300)
.setDraggable(new SpringDraggable())
.setOnClickListener(R.id.dialog_iv_panic_button,
(XToast.OnClickListener<ImageView>) (xToast, view) -> hider.hide());
(EasyWindow.OnClickListener<ImageView>) (xToast, view) -> hider.hide());

ivPanicButton = panicButton.findViewById(R.id.dialog_iv_panic_button);
ivPanicButton.setColorFilter(getColor(R.color.light_grey),
Expand Down
10 changes: 9 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,13 @@ public void onClick() {
unlockAndRun(() -> {
Log.i(TAG, "Toggled tile.");
if (prefMgr.getIsHidden()) {
hider.unhide();
if (prefMgr.getAmarokPassword() == null) {
// Avoid jump back to Amarok even without password
hider.unhide();
} else {
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();
}
}
Loading

0 comments on commit 3195d6c

Please sign in to comment.