55import android .content .Intent ;
66import android .content .ServiceConnection ;
77import android .content .SharedPreferences ;
8+ import android .os .Bundle ;
89import android .os .Environment ;
10+ import android .text .Editable ;
11+ import android .text .TextWatcher ;
912import android .view .KeyEvent ;
1013import android .view .View ;
1114import android .widget .EditText ;
1417
1518import de .robv .android .xposed .IXposedHookLoadPackage ;
1619import de .robv .android .xposed .XC_MethodHook ;
17- import de .robv .android .xposed .XC_MethodReplacement ;
1820import de .robv .android .xposed .XSharedPreferences ;
1921import de .robv .android .xposed .XposedHelpers ;
2022import de .robv .android .xposed .callbacks .XC_LoadPackage ;
@@ -41,8 +43,6 @@ public static TrackerConnector getCurrentTracker() {
4143 public void handleLoadPackage (XC_LoadPackage .LoadPackageParam lpparam ) throws Throwable {
4244 if (!lpparam .packageName .equals (Constants .APPLOCK_PACKAGE )) return ;
4345
44- SharedPreferences globalPref = getPreferences ();
45- boolean enableReplacePassword = globalPref .getBoolean ("enable_replace_password" , true );
4646
4747 // hook face recognition
4848 XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM , lpparam .classLoader , "onResume" , new XC_MethodHook () {
@@ -70,21 +70,27 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
7070 });
7171
7272 // hook complex password
73- XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_COMPLEX , lpparam .classLoader , "onResume" , new XC_MethodHook () {
73+ XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_COMPLEX , lpparam .classLoader , "onCreate" , Bundle . class , new XC_MethodHook () {
7474 @ Override
7575 protected void afterHookedMethod (MethodHookParam param ) throws Throwable {
7676 currentApplockerActivity = (Activity ) param .thisObject ;
7777
7878 SharedPreferences preferences = getPreferences ();
7979 boolean enable_fast_password = preferences .getBoolean ("enable_fast_password" , false );
80+ boolean enableReplacePassword = preferences .getBoolean ("enable_replace_password" , true );
8081
81- if (enable_fast_password )
82+ boolean shouldReplace = shouldReplace (preferences , getUnlockPackageName ());
83+
84+ if (enable_fast_password && !shouldReplace )
8285 hookFastPassword (preferences );
86+ if (shouldReplace && enableReplacePassword ) {
87+ hookReplacePasswordComplex (preferences );
88+ }
8389 }
8490 });
8591
8692 // hook pin
87- XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_PASSWORD , lpparam .classLoader , "onResume" , new XC_MethodHook () {
93+ XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_PASSWORD , lpparam .classLoader , "onCreate" , Bundle . class , new XC_MethodHook () {
8894 @ Override
8995 protected void afterHookedMethod (MethodHookParam param ) throws Throwable {
9096 currentApplockerActivity = (Activity ) param .thisObject ;
@@ -98,31 +104,106 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
98104
99105 SharedPreferences preferences = getPreferences ();
100106 boolean enable_fast_password = preferences .getBoolean ("enable_fast_password" , false );
107+ boolean enableReplacePassword = preferences .getBoolean ("enable_replace_password" , true );
101108
102109 String password_length = preferences .getString ("password_length" , "0" );
103110 final Integer length = Integer .parseInt (password_length );
111+ boolean shouldReplace = shouldReplace (preferences , getUnlockPackageName ());
104112
105- if (enable_fast_password )
113+ if (enable_fast_password && ! shouldReplace )
106114 onPINInput (length , thisObject );
115+ if (shouldReplace && enableReplacePassword ) {
116+ hookReplacePasswordPin (preferences , thisObject );
117+ }
107118 }
108119 });
109120
110121 // hook custom password
111- if (enableReplacePassword ) {
112- XposedHelpers .findAndHookMethod (Constants .APPLOCK_CHOOSE_PASSWORD , lpparam .classLoader , "launchConfirmationActivity" ,
113- int .class , CharSequence .class , CharSequence .class , CharSequence .class , boolean .class , boolean .class , boolean .class , long .class , boolean .class , String .class , int .class , int .class , new XC_MethodReplacement () {
114- @ Override
115- protected Object replaceHookedMethod (MethodHookParam param ) throws Throwable {
116122
117- return true ;
118- }
123+ XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_PASSWORD , lpparam .classLoader , "handleNext" , new XC_MethodHook () {
124+ @ Override
125+ protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
126+ SharedPreferences pref = getPreferences ();
127+ boolean replace = pref .getBoolean ("enable_replace_password" , true );
128+ if (replace )
129+ hookReplacePassword (param , true );
130+ }
131+ });
132+
133+ XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM_COMPLEX , lpparam .classLoader , "handleNext" , new XC_MethodHook () {
134+ @ Override
135+ protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
136+ SharedPreferences pref = getPreferences ();
137+ boolean replace = pref .getBoolean ("enable_replace_password" , true );
138+ if (replace )
139+ hookReplacePassword (param , false );
140+ }
141+ });
142+
119143
120- });
144+ // hook fingerprint
145+
146+ XposedHelpers .findAndHookMethod (Constants .APPLOCK_ACTIVITY_CONFIRM , lpparam .classLoader , "registerFingerprint" , new XC_MethodHook () {
147+ @ Override
148+ protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
149+ if (getPreferences ().getBoolean ("disable_fingerprint" , false ))
150+ param .setResult (null );
151+ }
152+ });
153+
154+ }
155+
156+ private void hookReplacePasswordPin (SharedPreferences preferences , Object thisObject ) {
157+
158+ if (preferences .getString ("password" , "" ).equals (((String ) XposedHelpers .callMethod (thisObject , "getText" )))) {
159+ XposedHelpers .callMethod (currentApplockerActivity , "onAuthenticated" );
121160 }
161+ }
122162
163+ private void hookReplacePasswordComplex (final SharedPreferences preferences ) {
164+ final EditText passwordEditText = (EditText ) XposedHelpers .getObjectField (currentApplockerActivity , "mPasswordEntry" );
123165
166+ passwordEditText .addTextChangedListener (new TextWatcher () {
167+ @ Override
168+ public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
169+ }
170+
171+ @ Override
172+ public void onTextChanged (CharSequence s , int start , int before , int count ) {
173+ }
174+
175+ @ Override
176+ public void afterTextChanged (Editable s ) {
177+ if (preferences .getString ("password" , "" ).equals (passwordEditText .getText ().toString ())) {
178+ XposedHelpers .callMethod (currentApplockerActivity , "onAuthenticated" );
179+ }
180+ }
181+ });
182+
183+ }
184+
185+ private void hookReplacePassword (XC_MethodHook .MethodHookParam param , boolean isPin ) {
186+ if (shouldReplace (getPreferences (), getUnlockPackageName ())) {
187+ if (isPin ) {
188+ Object mPasswordTextViewForPin = XposedHelpers .getObjectField (currentApplockerActivity , "mPasswordTextViewForPin" );
189+ if (mPasswordTextViewForPin != null ) {
190+ XposedHelpers .callMethod (mPasswordTextViewForPin , "reset" , true );
191+ XposedHelpers .callMethod (mPasswordTextViewForPin , "setEnabled" , true );
192+ }
193+ Object mPasswordEntry = XposedHelpers .getObjectField (currentApplockerActivity , "mPasswordEntry" );
194+ if (mPasswordEntry != null )
195+ XposedHelpers .callMethod (mPasswordEntry , "setText" , true );
196+ }
197+ Object mPasswordEntryInputDisabler = XposedHelpers .getObjectField (currentApplockerActivity , "mPasswordEntryInputDisabler" );
198+ if (mPasswordEntryInputDisabler != null )
199+ XposedHelpers .callMethod (mPasswordEntryInputDisabler , "setInputEnabled" , true );
200+ param .setResult (null );
201+ }
124202 }
125203
204+ private boolean shouldReplace (SharedPreferences preferences , String packageName ) {
205+ return !preferences .getBoolean ("enable_only_replace_selected" , false ) || preferences .getBoolean (packageName , false );
206+ }
126207
127208 private void hookFastPassword (SharedPreferences preferences ) {
128209 String password_length = preferences .getString ("password_length" , "0" );
@@ -142,7 +223,6 @@ public boolean onKey(View view, int i, KeyEvent keyEvent) {
142223 }
143224
144225 private void onPINInput (Integer length , Object thisObject ) {
145-
146226 if (length .equals (((String ) XposedHelpers .callMethod (thisObject , "getText" )).length ())) {
147227 XposedHelpers .callMethod (currentApplockerActivity , "handleNext" );
148228 }
@@ -175,5 +255,9 @@ public void onClick(View view) {
175255 private View getLayout () {
176256 return currentApplockerActivity .findViewById (ONEPLUS_APPLOCK_LAYOUT_ID );
177257 }
258+
259+ public String getUnlockPackageName () {
260+ return ((String ) XposedHelpers .getObjectField (currentApplockerActivity , "mPackageName" ));
261+ }
178262}
179263
0 commit comments