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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 19, 2018
2 parents 912360b + 80dbf65 commit 7415c69
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
*.apk
app/debug/output.json
app/release/output.json
.idea/*
.idea/*
!.travis.yml
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: android
android:
components:
- build-tools-26.0.2
- android-26
- extra
- sys-img-armeabi-v7a-android-24

before_script:
- echo no | android create avd --force -n test -t android-24 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# OnePlus Applock Tweaker
一加应用锁 Xposed 修改插件
第一次写 Android, 如果你有想法, 可以提交 Pull Request!

[![Build Status](https://travis-ci.org/Cyl18/OnePlus-5T-Applock-Tweaker.svg?branch=dev)](https://travis-ci.org/Cyl18/OnePlus-5T-Applock-Tweaker)

An Xposed module which appends face unlock method to OnePlus Applocker.

Licensed under WTFPL.
19 changes: 11 additions & 8 deletions app/src/main/java/com/cyl18/opapplocktweaker/AppLockHooker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@
*/

public class AppLockHooker implements IXposedHookLoadPackage {
private static final int ONEPLUS_APPLOCK_LAYOUT_ID = 2131558403;
private static ServiceConnection connection = new MyServiceConnection();
private static Activity currentApplockerActivity;
private static TrackerConnector currentTracker;
private ServiceConnection connection;
private Activity currentApplockerActivity;
private TrackerHandler currentTracker;

public static Activity getCurrentApplockerActivity() {
public Activity getCurrentApplockerActivity() {
return currentApplockerActivity;
}

public static TrackerConnector getCurrentTracker() {
public TrackerHandler getCurrentTracker() {
return currentTracker;
}

public AppLockHooker() {
connection = new MyServiceConnection(this);
}

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(Constants.APPLOCK_PACKAGE)) return;
Expand Down Expand Up @@ -256,7 +259,7 @@ private void hookFaceUnlockStart() {
Intent intent = new Intent();
intent.setClassName(Constants.FACEUNLOCK_PACKAGE, Constants.FACEUNLOCK_SERVICE);
currentApplockerActivity.bindService(intent, connection, Context.BIND_AUTO_CREATE);
currentTracker = new TrackerConnector(XposedHelpers.getObjectField(currentApplockerActivity, Constants.TRACKER));
currentTracker = new TrackerHandler(XposedHelpers.getObjectField(currentApplockerActivity, Constants.TRACKER));
getLayout().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -267,7 +270,7 @@ public void onClick(View view) {
}

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

public String getUnlockPackageName() {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/cyl18/opapplocktweaker/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public interface Constants {
int USER_ID = 0;
int ONEPLUS_APPLOCK_LAYOUT_ID = 2131558403;

String APPLOCK_PACKAGE = "com.oneplus.applocker";
String APPLOCK_ACTIVITY_CONFIRM = "com.oneplus.applocker.ApplockerConfirmActivity";
String APPLOCK_ACTIVITY_CONFIRM_COMPLEX = "com.oneplus.applocker.ApplockerConfirmComplexPassword";
Expand All @@ -10,7 +12,7 @@ public interface Constants {
String FACEUNLOCK_PACKAGE = "com.oneplus.faceunlock";
String FACEUNLOCK_SERVICE = "com.oneplus.faceunlock.FaceUnlockService";
String TRACKER = "mCredentialCheckResultTracker";
String THIS_PACKAGE = "com.cyl18.opapplocktweaker";
String APP_PACKAGE = "com.cyl18.opapplocktweaker";
String SHARED_SETTINGS_FILE = "OPApplockTweakerSettings";
String APPLOCK_CHOOSE_PASSWORD = "com.oneplus.applocker.ChooseLockSettingsHelper";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public class FaceUnlockServiceConnector {
private static FaceUnlockServiceConnector instance;
private boolean started = false;
private IBinder currentBinder;
private AppLockHooker hooker;

public static FaceUnlockServiceConnector getInstance() {
return instance;
}

public FaceUnlockServiceConnector() {
public FaceUnlockServiceConnector(AppLockHooker hooker) {
instance = this;
this.hooker = hooker;
}

public void startFaceUnlock(IBinder binder) {
Expand Down Expand Up @@ -64,13 +66,13 @@ public void stopFaceUnlock(boolean force) {
}

if (!force)
if (!AppLockHooker.getCurrentTracker().getResult() &&
if (!hooker.getCurrentTracker().getResult() &&
isScreenOn())
startFaceUnlock();
}

private boolean isScreenOn() {
DisplayManager dm = (DisplayManager) AppLockHooker.getCurrentApplockerActivity().getSystemService(Context.DISPLAY_SERVICE);
DisplayManager dm = (DisplayManager) hooker.getCurrentApplockerActivity().getSystemService(Context.DISPLAY_SERVICE);
if (dm == null)
return false;
Display[] displays = dm.getDisplays();
Expand All @@ -92,7 +94,7 @@ public void onBeginRecognize(int i) throws RemoteException {
@Override
public void onCompared(int faceId, int userId, int result, int compareTimeMillis, int score) throws RemoteException {
if (result != RESULT_SUCCESSFUL) return;
Object activity = AppLockHooker.getCurrentApplockerActivity();
Object activity = hooker.getCurrentApplockerActivity();
try {
XposedHelpers.callMethod(activity, "onAuthenticated");
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import android.os.IBinder;

public class MyServiceConnection implements ServiceConnection {
private static FaceUnlockServiceConnector faceUnlockServiceConnector = new FaceUnlockServiceConnector();
private static FaceUnlockServiceConnector faceUnlockServiceConnector;

public MyServiceConnection(AppLockHooker hooker) {
faceUnlockServiceConnector = new FaceUnlockServiceConnector(hooker);
}

@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Expand Down
48 changes: 15 additions & 33 deletions app/src/main/java/com/cyl18/opapplocktweaker/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.MenuItem;

import org.lukhnos.nnio.file.Files;
import org.lukhnos.nnio.file.Path;
import org.lukhnos.nnio.file.Paths;

import java.io.File;
Expand Down Expand Up @@ -67,8 +68,6 @@ public boolean onPreferenceChange(Preference preference, Object value) {
? listPreference.getEntries()[index]
: null);

} else if (preference instanceof CheckBoxPreference) {
// do nothing
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
Expand Down Expand Up @@ -103,10 +102,10 @@ private static void bindPreferenceSummaryToValue(Preference preference) {
// Trigger the listener immediately with the preference's
// current value.
if (preference instanceof EditTextPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), "")
);
}


Expand All @@ -121,15 +120,8 @@ protected void onCreate(Bundle savedInstanceState) {
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.

} else {

// No explanation needed, we can request the permission.

ActivityCompat.requestPermissions(this,
Expand All @@ -147,10 +139,8 @@ protected void onCreate(Bundle savedInstanceState) {
*/
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
// Show the Up button in the action bar.
if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
}

/**
Expand Down Expand Up @@ -250,16 +240,16 @@ private String getApplicationName(ApplicationInfo applicationInfo, PackageManage
@Override
public void onPause() {
super.onPause();
// bad code here.
// bad code here. // good code appended. ---by Lasm_Gratel

File prefsDir = new File(getActivity().getApplicationInfo().dataDir, "shared_prefs");
File source = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
File dest = new File(Environment.getExternalStorageDirectory(), Constants.SHARED_SETTINGS_FILE);
Path prefsPath = Paths.get(getActivity().getApplicationInfo().dataDir, "shared_prefs");
Path sourcePath = prefsPath.resolve(getPreferenceManager().getSharedPreferencesName() + ".xml");
Path destPath = Paths.get(Environment.getExternalStorageDirectory().getAbsolutePath(), Constants.SHARED_SETTINGS_FILE);

if (source.exists()) {
if (dest.exists()) dest.delete();
if (Files.exists(prefsPath)) {
try {
Files.copy(Paths.get(source.toURI()), Paths.get(dest.toURI()));
Files.deleteIfExists(destPath);
Files.copy(sourcePath, destPath);
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -275,13 +265,5 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return super.onOptionsItemSelected(item);
}


}

/**
* This fragment shows notification preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Created by Cyl18 on 1/25/2018.
*/

public class TrackerConnector {
public class TrackerHandler {
private final Object tracker;

public TrackerConnector(Object tracker) {
public TrackerHandler(Object tracker) {
this.tracker = tracker;
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

<!-- Example General settings -->
<string name="pref_header_general">General</string>
<string name="enable_face_recognition_summary">For fast unlock</string>
<string name="enable_face_recognition_summary">For fast unlock. (WARNING: HIGH SECURITY RISKS!)</string>
<string name="enable_face_recognition">Enable face recognition</string>
<string name="enable_fast_password_summary">Quick unlock needs to know the exact length of your password</string>
<string name="enable_fast_password_summary">Quick unlock needs the exact length of your password to be active.</string>
<string name="enable_fast_password">Enable quick unlock</string>
<string name="password_length">Password length</string>
<string name="hide_icon">Hide icon</string>
<string name="replace_password">Replace applock password</string>
<string name="replace_password">Applock password replacement</string>
<string name="password">Password</string>
<string name="apps_to_replace">Apps to replace</string>
<string name="only_replace_selected_apps">Only replaces selected apps</string>
<string name="disable_fingerprint">Disable fingerprint</string>
<string name="enable_replace_password_summary">Use password below instead of system password, please use the same password type as the system\'s</string>
<string name="enable_replace_password_summary">Use password below instead of system password, please use the same password type as system configured.</string>


</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xmx1536m
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
Empty file modified gradlew
100644 → 100755
Empty file.
Empty file modified gradlew.bat
100644 → 100755
Empty file.

0 comments on commit 7415c69

Please sign in to comment.