Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
add quick unlock and settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Jan 26, 2018
1 parent 19e70e4 commit f7f1be3
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 16 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.cyl18.opapplocktweaker"
minSdkVersion 24
targetSdkVersion 26
versionCode 6
versionName "1.5"
versionCode 7
versionName "1.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -19,9 +19,11 @@ android {

dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
provided 'de.robv.android.xposed:api:82'
compileOnly files('libs/OPFaceUnlock.jar')
compile 'org.lukhnos:nnio:0.2'
}
23 changes: 22 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyl18.opapplocktweaker">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
android:name="xposedmodule"
android:value="true" />
Expand All @@ -19,6 +21,25 @@
android:name="xposedminversion"
android:value="82" />

<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
</intent-filter>
</activity>

<activity-alias
android:name=".SettingsActivityAlias"
android:enabled="true"
android:targetActivity=".SettingsActivity"
android:label="@string/title_activity_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.cyl18.opapplocktweaker;

import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {

private AppCompatDelegate mDelegate;

@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}

public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}

public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}

@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}

@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}

@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}

@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}

@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}

@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}

@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}

@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}

@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}

public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}

private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}
74 changes: 63 additions & 11 deletions app/src/main/java/com/cyl18/opapplocktweaker/AppLockHooker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Environment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;

import java.io.File;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

Expand All @@ -31,19 +38,61 @@ public static TrackerConnector getCurrentTracker() {

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(Constants.APPLOCK_PACKAGE_NAME)) return;
if (!lpparam.packageName.equals(Constants.APPLOCK_PACKAGE)) return;


XposedHelpers.findAndHookMethod(Constants.ACTIVITY_CONFIRM_NAME, lpparam.classLoader, "onResume", new XC_MethodHook() {
XposedHelpers.findAndHookMethod(Constants.APPLOCK_ACTIVITY_CONFIRM, lpparam.classLoader, "onResume", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
hookOnStart(param);
currentApplockerActivity = (Activity) param.thisObject;

SharedPreferences preferences = getPreferences();

boolean enable_face_recognition = preferences.getBoolean("enable_face_recognition", true);
boolean enable_fast_password = preferences.getBoolean("enable_fast_password", false);

if (enable_face_recognition) {
hookOnStart();
}

if (enable_fast_password) {
hookFastPassword(preferences);
}
}
});

XposedHelpers.findAndHookMethod(Constants.ACTIVITY_CONFIRM_NAME, lpparam.classLoader, "onPause", new XC_MethodHook() {
XposedHelpers.findAndHookMethod(Constants.APPLOCK_ACTIVITY_CONFIRM, lpparam.classLoader, "onPause", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
hookOnStop();
SharedPreferences preferences = getPreferences();

boolean enable_face_recognition = preferences.getBoolean("enable_face_recognition", true);

if (enable_face_recognition)
hookOnStop();
}
});

}

private SharedPreferences getPreferences() {
File dest = new File(Environment.getExternalStorageDirectory(), Constants.SHARED_SETTINGS_FILE);
return new XSharedPreferences(dest);
}

private void hookFastPassword(SharedPreferences preferences) {
String password_length = preferences.getString("password_length", "0");
final Integer length = Integer.parseInt(password_length);
final EditText passwordEditText = (EditText) XposedHelpers.getObjectField(currentApplockerActivity, "mPasswordEntry");

passwordEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (length.equals(passwordEditText.getText().length())) {
XposedHelpers.callMethod(currentApplockerActivity, "handleNext");
return true;
}
return false;
}
});
}
Expand All @@ -52,18 +101,21 @@ private void hookOnStop() {
currentApplockerActivity.unbindService(connection);
}

private void hookOnStart(XC_MethodHook.MethodHookParam param) {
currentApplockerActivity = (Activity) param.thisObject;
private void hookOnStart() {
Intent intent = new Intent();
intent.setClassName("com.oneplus.faceunlock", "com.oneplus.faceunlock.FaceUnlockService");
intent.setClassName(Constants.FACEUNLOCK_PACKAGE, Constants.FACEUNLOCK_SERVICE);
currentApplockerActivity.bindService(intent, connection, Context.BIND_AUTO_CREATE);
currentTracker = new TrackerConnector(XposedHelpers.getObjectField(currentApplockerActivity, "mCredentialCheckResultTracker"));
currentApplockerActivity.findViewById(ONEPLUS_APPLOCK_LAYOUT_ID).setOnClickListener(new View.OnClickListener() {
currentTracker = new TrackerConnector(XposedHelpers.getObjectField(currentApplockerActivity, Constants.TRACKER));
getLayout().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FaceUnlockServiceConnector.getInstance().startFaceUnlock();
FaceUnlockServiceConnector.getInstance().stopFaceUnlock();
}
});
}

private View getLayout() {
return currentApplockerActivity.findViewById(ONEPLUS_APPLOCK_LAYOUT_ID);
}
}

9 changes: 7 additions & 2 deletions app/src/main/java/com/cyl18/opapplocktweaker/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public interface Constants {
int USER_ID = 0;
String APPLOCK_PACKAGE_NAME = "com.oneplus.applocker";
String ACTIVITY_CONFIRM_NAME = "com.oneplus.applocker.ApplockerConfirmActivity";
String APPLOCK_PACKAGE = "com.oneplus.applocker";
String APPLOCK_ACTIVITY_CONFIRM = "com.oneplus.applocker.ApplockerConfirmActivity";
String FACEUNLOCK_PACKAGE = "com.oneplus.faceunlock";
String FACEUNLOCK_SERVICE = "com.oneplus.faceunlock.FaceUnlockService";
String TRACKER = "mCredentialCheckResultTracker";
String THIS_PACKAGE = "com.cyl18.opapplocktweaker";
String SHARED_SETTINGS_FILE = "OPApplockTweakerSettings";
}
Loading

0 comments on commit f7f1be3

Please sign in to comment.