Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#610]锁屏keyguard新增拉起键盘接口 #611

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

package org.hapjs.features;

import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;

import org.hapjs.bridge.FeatureExtension;
import org.hapjs.bridge.Request;
import org.hapjs.bridge.Response;
Expand All @@ -19,12 +21,13 @@
name = Keyguard.FEATURE_NAME,
actions = {
@ActionAnnotation(
name = Keyguard.ACTION_GET_KEYGUARD_LOCKED_STATUS,
mode = FeatureExtension.Mode.ASYNC)
name = Keyguard.ACTION_GET_KEYGUARD_LOCKED_STATUS, mode = FeatureExtension.Mode.ASYNC),
@ActionAnnotation(name = Keyguard.ACTION_REQUEST_DISMISS_KEYGUARD, mode = FeatureExtension.Mode.ASYNC)
})
public class Keyguard extends FeatureExtension {
protected static final String FEATURE_NAME = "system.keyguard";
protected static final String ACTION_GET_KEYGUARD_LOCKED_STATUS = "getKeyguardLockedStatus";
protected static final String ACTION_REQUEST_DISMISS_KEYGUARD = "requestDismissKeyguard";
protected static final String RESULT_KEY_IS_KEYGUARD_LOCKED = "isKeyguardLocked";

@Override
Expand All @@ -37,6 +40,8 @@ protected Response invokeInner(Request request) throws Exception {
String action = request.getAction();
if (ACTION_GET_KEYGUARD_LOCKED_STATUS.equals(action)) {
getKeyguardLockedStatus(request);
} else if (ACTION_REQUEST_DISMISS_KEYGUARD.equals(action)) {
requestDismissKeyguard(request);
}
return null;
}
Expand All @@ -57,4 +62,41 @@ private void getKeyguardLockedStatus(Request request) throws JSONException {
request.getCallback().callback(Response.ERROR);
}
}

private void requestDismissKeyguard(Request request) {
Activity activity = request.getNativeInterface().getActivity();
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
request.getCallback().callback(Response.ERROR);
return;
}
if (activity.getWindow() == null) {
request.getCallback().callback(Response.ERROR);
return;
}

KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager == null) {
request.getCallback().callback(Response.ERROR);
return;
}
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
@Override
public void onDismissError() {
super.onDismissError();
request.getCallback().callback(Response.ERROR);
}

@Override
public void onDismissSucceeded() {
super.onDismissSucceeded();
request.getCallback().callback(Response.SUCCESS);
}

@Override
public void onDismissCancelled() {
super.onDismissCancelled();
request.getCallback().callback(Response.CANCEL);
}
});
}
}
Loading