Skip to content

Commit

Permalink
App lock pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Sep 4, 2024
1 parent 7a4653d commit 1f57f46
Show file tree
Hide file tree
Showing 19 changed files with 821 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public static final class LaunchOtherAppPkgSetting {
public static final int IGNORE = -1;
}

public static final class LockMethod {
public static final int SYSTEM = 0;
public static final int PATTERN = 1;
public static final int PIN = 2;
}

private final IActivityStackSupervisor supervisor;

public ActivityStackSupervisor(IActivityStackSupervisor supervisor) {
Expand Down Expand Up @@ -207,4 +213,24 @@ public void addPkgToLaunchOtherAppAllowList(Pkg pkg, Pkg pkgToAdd) {
public List<Pkg> getLaunchOtherAppAllowListOrNull(Pkg callerPkg) {
return supervisor.getLaunchOtherAppAllowListOrNull(callerPkg);
}

@SneakyThrows
public void setLockMethod(int method) {
supervisor.setLockMethod(method);
}

@SneakyThrows
public void setLockPattern(String pattern) {
supervisor.setLockPattern(pattern);
}

@SneakyThrows
public String getLockPattern() {
return supervisor.getLockPattern();
}

@SneakyThrows
public int getLockMethod() {
return supervisor.getLockMethod();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ interface IActivityStackSupervisor {
void removePkgFromLaunchOtherAppAllowList(in Pkg pkg, in Pkg pkgToRemove);
void addPkgToLaunchOtherAppAllowList(in Pkg pkg, in Pkg pkgToAdd);
List<Pkg> getLaunchOtherAppAllowListOrNull(in Pkg callerPkg);

int getLockMethod();
void setLockMethod(int method);
void setLockPattern(String pattern);
String getLockPattern();
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public static class Default implements github.tornaco.android.thanos.core.app.ac
{
return null;
}
@Override public int getLockMethod() throws android.os.RemoteException
{
return 0;
}
@Override public void setLockMethod(int method) throws android.os.RemoteException
{
}
@Override public void setLockPattern(java.lang.String pattern) throws android.os.RemoteException
{
}
@Override public java.lang.String getLockPattern() throws android.os.RemoteException
{
return null;
}
@Override
public android.os.IBinder asBinder() {
return null;
Expand Down Expand Up @@ -688,6 +702,40 @@ public static github.tornaco.android.thanos.core.app.activity.IActivityStackSupe
reply.writeTypedList(_result);
return true;
}
case TRANSACTION_getLockMethod:
{
data.enforceInterface(descriptor);
int _result = this.getLockMethod();
reply.writeNoException();
reply.writeInt(_result);
return true;
}
case TRANSACTION_setLockMethod:
{
data.enforceInterface(descriptor);
int _arg0;
_arg0 = data.readInt();
this.setLockMethod(_arg0);
reply.writeNoException();
return true;
}
case TRANSACTION_setLockPattern:
{
data.enforceInterface(descriptor);
java.lang.String _arg0;
_arg0 = data.readString();
this.setLockPattern(_arg0);
reply.writeNoException();
return true;
}
case TRANSACTION_getLockPattern:
{
data.enforceInterface(descriptor);
java.lang.String _result = this.getLockPattern();
reply.writeNoException();
reply.writeString(_result);
return true;
}
default:
{
return super.onTransact(code, data, reply, flags);
Expand Down Expand Up @@ -1656,6 +1704,84 @@ public java.lang.String getInterfaceDescriptor()
}
return _result;
}
@Override public int getLockMethod() throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
int _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
boolean _status = mRemote.transact(Stub.TRANSACTION_getLockMethod, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
return getDefaultImpl().getLockMethod();
}
_reply.readException();
_result = _reply.readInt();
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
@Override public void setLockMethod(int method) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeInt(method);
boolean _status = mRemote.transact(Stub.TRANSACTION_setLockMethod, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
getDefaultImpl().setLockMethod(method);
return;
}
_reply.readException();
}
finally {
_reply.recycle();
_data.recycle();
}
}
@Override public void setLockPattern(java.lang.String pattern) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeString(pattern);
boolean _status = mRemote.transact(Stub.TRANSACTION_setLockPattern, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
getDefaultImpl().setLockPattern(pattern);
return;
}
_reply.readException();
}
finally {
_reply.recycle();
_data.recycle();
}
}
@Override public java.lang.String getLockPattern() throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
java.lang.String _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
boolean _status = mRemote.transact(Stub.TRANSACTION_getLockPattern, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
return getDefaultImpl().getLockPattern();
}
_reply.readException();
_result = _reply.readString();
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
public static github.tornaco.android.thanos.core.app.activity.IActivityStackSupervisor sDefaultImpl;
}
static final int TRANSACTION_checkActivity = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
Expand Down Expand Up @@ -1701,6 +1827,10 @@ public java.lang.String getInterfaceDescriptor()
static final int TRANSACTION_removePkgFromLaunchOtherAppAllowList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 40);
static final int TRANSACTION_addPkgToLaunchOtherAppAllowList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 41);
static final int TRANSACTION_getLaunchOtherAppAllowListOrNull = (android.os.IBinder.FIRST_CALL_TRANSACTION + 42);
static final int TRANSACTION_getLockMethod = (android.os.IBinder.FIRST_CALL_TRANSACTION + 43);
static final int TRANSACTION_setLockMethod = (android.os.IBinder.FIRST_CALL_TRANSACTION + 44);
static final int TRANSACTION_setLockPattern = (android.os.IBinder.FIRST_CALL_TRANSACTION + 45);
static final int TRANSACTION_getLockPattern = (android.os.IBinder.FIRST_CALL_TRANSACTION + 46);
public static boolean setDefaultImpl(github.tornaco.android.thanos.core.app.activity.IActivityStackSupervisor impl) {
// Only one user of this interface can use this function
// at a time. This is a heuristic to detect if two different
Expand Down Expand Up @@ -1764,4 +1894,8 @@ public static github.tornaco.android.thanos.core.app.activity.IActivityStackSupe
public void removePkgFromLaunchOtherAppAllowList(github.tornaco.android.thanos.core.pm.Pkg pkg, github.tornaco.android.thanos.core.pm.Pkg pkgToRemove) throws android.os.RemoteException;
public void addPkgToLaunchOtherAppAllowList(github.tornaco.android.thanos.core.pm.Pkg pkg, github.tornaco.android.thanos.core.pm.Pkg pkgToAdd) throws android.os.RemoteException;
public java.util.List<github.tornaco.android.thanos.core.pm.Pkg> getLaunchOtherAppAllowListOrNull(github.tornaco.android.thanos.core.pm.Pkg callerPkg) throws android.os.RemoteException;
public int getLockMethod() throws android.os.RemoteException;
public void setLockMethod(int method) throws android.os.RemoteException;
public void setLockPattern(java.lang.String pattern) throws android.os.RemoteException;
public java.lang.String getLockPattern() throws android.os.RemoteException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
<string name="module_locker_summary_white_list_components">白名单中的组件不会被锁定</string>
<string name="module_locker_title_white_list_components">组件白名单</string>

<string name="module_locker_title_verify_method">验证方式</string>
<string name="module_locker_title_verify_system">跟随系统</string>
<string name="module_locker_title_verify_custom_pattern">自定义图案</string>
<string name="module_locker_title_verify_custom_pin">自定义PIN</string>
<string name="module_locker_title_verify_custom_pattern_settings">设置图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_warn">请牢记密码,密码设置后不可找回</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_1">请绘制图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_2">请再次绘制图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_mismatch">图案不一致</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_set_complete">图案已设置</string>

<string name="module_locker_biometric_not_set_dialog_title">设置密码</string>
<string name="module_locker_biometric_not_set_dialog_message">启用应用锁之前,请前往系统安全设置,完成人脸、指纹、PIN或者图案密码设置</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
<string name="module_locker_summary_white_list_components">白名单中的组件不会被锁定</string>
<string name="module_locker_title_white_list_components">组件白名单</string>

<string name="module_locker_title_verify_method">验证方式</string>
<string name="module_locker_title_verify_system">跟随系统</string>
<string name="module_locker_title_verify_custom_pattern">自定义图案</string>
<string name="module_locker_title_verify_custom_pin">自定义PIN</string>
<string name="module_locker_title_verify_custom_pattern_settings">设置图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_warn">请牢记密码,密码设置后不可找回</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_1">请绘制图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_2">请再次绘制图案</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_mismatch">图案不一致</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_set_complete">图案已设置</string>

<string name="module_locker_biometric_not_set_dialog_title">设置密码</string>
<string name="module_locker_biometric_not_set_dialog_message">启用应用锁之前,请前往系统安全设置,完成人脸、指纹、PIN或者图案密码设置</string>

Expand Down
22 changes: 22 additions & 0 deletions android/android_framework/res/src/main/res/values/app_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,32 @@
<string name="module_locker_summary_re_verify_on_app_switch">When an already unlocked app goes to the background, the app will be re-locked.</string>
<string name="module_locker_summary_white_list_components">Activity in Allow list will not be locked</string>
<string name="module_locker_title_white_list_components">Allowed components</string>
<string name="module_locker_title_verify_method">Verify method</string>
<string name="module_locker_title_verify_system">Follow System</string>
<string name="module_locker_title_verify_custom_pattern">Custom Pattern</string>
<string name="module_locker_title_verify_custom_pin">Custom PIN</string>
<string name="module_locker_title_verify_custom_pattern_settings">Pattern settings</string>
<string name="module_locker_title_verify_custom_pattern_settings_warn">Please remember your password. Once set, the password cannot be recovered.</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_1">Draw pattern</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_2">Draw pattern again</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_mismatch">Two patterns do not match.</string>
<string name="module_locker_title_verify_custom_pattern_settings_draw_set_complete">Patterns has been set</string>

<string name="module_locker_biometric_not_set_dialog_title">Set a password</string>
<string name="module_locker_biometric_not_set_dialog_message">Before enabling the app lock, please go to the system security settings and complete the setup of face recognition, fingerprint, PIN, or pattern password.</string>

<string-array name="module_locker_verify_method_entries">
<item>@string/module_locker_title_verify_system</item>
<item>@string/module_locker_title_verify_custom_pattern</item>
<item>@string/module_locker_title_verify_custom_pin</item>
</string-array>

<string-array name="module_locker_verify_method_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

<string-array name="module_ops2_app_ops_summaries" tools:ignore="InconsistentArrays">
<item>""</item>
<item>""</item>
Expand Down
2 changes: 1 addition & 1 deletion android/internal/Thanox-Internal
3 changes: 3 additions & 0 deletions android/modules/module_locker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<activity
android:name=".ui.setup.WhiteListComponentViewerActivity"
android:excludeFromRecents="false" />
<activity
android:name="github.tornaco.practice.honeycomb.locker.ui.verify.PatternSettingsActivity"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package github.tornaco.practice.honeycomb.locker.ui.setup;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.preference.DropDownPreference;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;

Expand All @@ -11,6 +13,7 @@
import github.tornaco.android.thanos.core.app.ThanosManager;
import github.tornaco.android.thanos.core.app.activity.ActivityStackSupervisor;
import github.tornaco.practice.honeycomb.locker.R;
import github.tornaco.practice.honeycomb.locker.ui.verify.PatternSettingsActivity;

public class SettingsFragment extends BasePreferenceFragmentCompat {

Expand All @@ -30,10 +33,11 @@ public void onResume() {
}

private void bindPreferences() {
ThanosManager thanos = ThanosManager.from(getContext());

SwitchPreferenceCompat reVerifyScreenOff = (SwitchPreferenceCompat) findPreference(getString(R.string.module_locker_key_re_verify_on_screen_off));
SwitchPreferenceCompat reVerifyAppSwitch = (SwitchPreferenceCompat) findPreference(getString(R.string.module_locker_key_re_verify_on_app_switch));
SwitchPreferenceCompat reVerifyTaskRemoved = (SwitchPreferenceCompat) findPreference(getString(R.string.module_locker_key_re_verify_on_task_removed));
SwitchPreferenceCompat reVerifyScreenOff = findPreference(getString(R.string.module_locker_key_re_verify_on_screen_off));
SwitchPreferenceCompat reVerifyAppSwitch = findPreference(getString(R.string.module_locker_key_re_verify_on_app_switch));
SwitchPreferenceCompat reVerifyTaskRemoved = findPreference(getString(R.string.module_locker_key_re_verify_on_task_removed));

ActivityStackSupervisor supervisor = ThanosManager.from(getContext()).getActivityStackSupervisor();

Expand All @@ -59,5 +63,26 @@ private void bindPreferences() {
WhiteListComponentViewerActivity.Starter.INSTANCE.start(requireActivity());
return true;
});

Preference patternSettingsPref = findPreference(getString(R.string.module_locker_key_verify_method_custom_pattern));
if (TextUtils.isEmpty(thanos.getActivityStackSupervisor().getLockPattern())) {
patternSettingsPref.setSummary(github.tornaco.android.thanos.module.common.R.string.common_text_value_not_set);
} else {
patternSettingsPref.setSummary("******");
}
patternSettingsPref.setOnPreferenceClickListener(preference -> {
PatternSettingsActivity.start(requireContext());
return true;
});

DropDownPreference methodPref = findPreference(getString(R.string.module_locker_key_verify_method));
int currentMethod = thanos.getActivityStackSupervisor().getLockMethod();
methodPref.setValue(String.valueOf(currentMethod));
methodPref.setOnPreferenceChangeListener((preference, newValue) -> {
int method = Integer.parseInt(String.valueOf(newValue));
thanos.getActivityStackSupervisor().setLockMethod(method);
return true;
});

}
}
Loading

0 comments on commit 1f57f46

Please sign in to comment.