diff --git a/packages/SystemUI/res/drawable/fingerprint_dialog_bg.xml b/packages/SystemUI/res/drawable/fingerprint_dialog_bg.xml
new file mode 100644
index 0000000000000..4a77af9114412
--- /dev/null
+++ b/packages/SystemUI/res/drawable/fingerprint_dialog_bg.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/fingerprint_icon.xml b/packages/SystemUI/res/drawable/fingerprint_icon.xml
new file mode 100644
index 0000000000000..76a86ae42da28
--- /dev/null
+++ b/packages/SystemUI/res/drawable/fingerprint_icon.xml
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/fingerprint_dialog.xml b/packages/SystemUI/res/layout/fingerprint_dialog.xml
new file mode 100644
index 0000000000000..e5f62b3f73137
--- /dev/null
+++ b/packages/SystemUI/res/layout/fingerprint_dialog.xml
@@ -0,0 +1,163 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml
index 0f4c3b8b9977b..4fcfdf7558f9f 100644
--- a/packages/SystemUI/res/values/colors.xml
+++ b/packages/SystemUI/res/values/colors.xml
@@ -156,6 +156,14 @@
#ffffffff
+
#ff4285f4
#fff7f7f7
+
+
+ #f4ffffff
+ #ff424242
+ #80000000
+ #ff5722
+
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 887d3cb70ecac..8e2ad9aea1f36 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -889,4 +889,7 @@
8dp
4dp
14sp
+
+ 44dp
+ 60dp
diff --git a/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogImpl.java b/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogImpl.java
index 8b6f95ca4e14f..1b785a2141671 100644
--- a/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogImpl.java
@@ -16,17 +16,75 @@
package com.android.systemui.fingerprint;
+import android.content.Context;
import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintDialog;
import android.hardware.fingerprint.IFingerprintDialogReceiver;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.RemoteException;
import android.util.Log;
+import android.view.WindowManager;
+import com.android.internal.os.SomeArgs;
import com.android.systemui.SystemUI;
import com.android.systemui.statusbar.CommandQueue;
public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Callbacks {
private static final String TAG = "FingerprintDialogImpl";
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = true;
+
+ protected static final int MSG_SHOW_DIALOG = 1;
+ protected static final int MSG_FINGERPRINT_AUTHENTICATED = 2;
+ protected static final int MSG_FINGERPRINT_HELP = 3;
+ protected static final int MSG_FINGERPRINT_ERROR = 4;
+ protected static final int MSG_HIDE_DIALOG = 5;
+ protected static final int MSG_BUTTON_NEGATIVE = 6;
+ protected static final int MSG_USER_CANCELED = 7;
+ protected static final int MSG_BUTTON_POSITIVE = 8;
+ protected static final int MSG_CLEAR_MESSAGE = 9;
+
+
+ private FingerprintDialogView mDialogView;
+ private WindowManager mWindowManager;
+ private IFingerprintDialogReceiver mReceiver;
+ private boolean mDialogShowing;
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch(msg.what) {
+ case MSG_SHOW_DIALOG:
+ handleShowDialog((SomeArgs) msg.obj);
+ break;
+ case MSG_FINGERPRINT_AUTHENTICATED:
+ handleFingerprintAuthenticated();
+ break;
+ case MSG_FINGERPRINT_HELP:
+ handleFingerprintHelp((String) msg.obj);
+ break;
+ case MSG_FINGERPRINT_ERROR:
+ handleFingerprintError((String) msg.obj);
+ break;
+ case MSG_HIDE_DIALOG:
+ handleHideDialog((Boolean) msg.obj);
+ break;
+ case MSG_BUTTON_NEGATIVE:
+ handleButtonNegative();
+ break;
+ case MSG_USER_CANCELED:
+ handleUserCanceled();
+ break;
+ case MSG_BUTTON_POSITIVE:
+ handleButtonPositive();
+ break;
+ case MSG_CLEAR_MESSAGE:
+ handleClearMessage();
+ break;
+ }
+ }
+ };
@Override
public void start() {
@@ -34,30 +92,129 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
return;
}
getComponent(CommandQueue.class).addCallbacks(this);
+ mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
+ mDialogView = new FingerprintDialogView(mContext, mHandler);
}
@Override
public void showFingerprintDialog(Bundle bundle, IFingerprintDialogReceiver receiver) {
- if (DEBUG) Log.d(TAG, "show fingerprint dialog");
+ if (DEBUG) Log.d(TAG, "showFingerprintDialog");
+ // Remove these messages as they are part of the previous client
+ mHandler.removeMessages(MSG_FINGERPRINT_ERROR);
+ mHandler.removeMessages(MSG_FINGERPRINT_HELP);
+ mHandler.removeMessages(MSG_FINGERPRINT_AUTHENTICATED);
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = bundle;
+ args.arg2 = receiver;
+ mHandler.obtainMessage(MSG_SHOW_DIALOG, args).sendToTarget();
}
@Override
public void onFingerprintAuthenticated() {
if (DEBUG) Log.d(TAG, "onFingerprintAuthenticated");
+ mHandler.obtainMessage(MSG_FINGERPRINT_AUTHENTICATED).sendToTarget();
}
@Override
public void onFingerprintHelp(String message) {
if (DEBUG) Log.d(TAG, "onFingerprintHelp: " + message);
+ mHandler.obtainMessage(MSG_FINGERPRINT_HELP, message).sendToTarget();
}
@Override
public void onFingerprintError(String error) {
if (DEBUG) Log.d(TAG, "onFingerprintError: " + error);
+ mHandler.obtainMessage(MSG_FINGERPRINT_ERROR, error).sendToTarget();
}
@Override
public void hideFingerprintDialog() {
if (DEBUG) Log.d(TAG, "hideFingerprintDialog");
+ mHandler.obtainMessage(MSG_HIDE_DIALOG, false /* userCanceled */).sendToTarget();
+ }
+
+ private void handleShowDialog(SomeArgs args) {
+ if (DEBUG) Log.d(TAG, "handleShowDialog");
+ if (mDialogShowing) {
+ Log.w(TAG, "Dialog already showing");
+ return;
+ }
+ mReceiver = (IFingerprintDialogReceiver) args.arg2;
+ mDialogView.setBundle((Bundle)args.arg1);
+ mWindowManager.addView(mDialogView, mDialogView.getLayoutParams());
+ mDialogShowing = true;
+ }
+
+ private void handleFingerprintAuthenticated() {
+ if (DEBUG) Log.d(TAG, "handleFingerprintAuthenticated");
+ handleHideDialog(false /* userCanceled */);
+ }
+
+ private void handleFingerprintHelp(String message) {
+ if (DEBUG) Log.d(TAG, "handleFingerprintHelp: " + message);
+ mDialogView.showHelpMessage(message);
+ }
+
+ private void handleFingerprintError(String error) {
+ if (DEBUG) Log.d(TAG, "handleFingerprintError: " + error);
+ if (!mDialogShowing) {
+ if (DEBUG) Log.d(TAG, "Dialog already dismissed");
+ return;
+ }
+ mDialogView.showErrorMessage(error);
+ }
+
+ private void handleHideDialog(boolean userCanceled) {
+ if (DEBUG) Log.d(TAG, "handleHideDialog");
+ if (!mDialogShowing) {
+ // This can happen if there's a race and we get called from both
+ // onAuthenticated and onError, etc.
+ Log.w(TAG, "Dialog already dismissed, userCanceled: " + userCanceled);
+ return;
+ }
+ if (userCanceled) {
+ try {
+ mReceiver.onDialogDismissed(FingerprintDialog.DISMISSED_REASON_USER_CANCEL);
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException when hiding dialog", e);
+ }
+ }
+ mReceiver = null;
+ mWindowManager.removeView(mDialogView);
+ mDialogShowing = false;
+ }
+
+ private void handleButtonNegative() {
+ if (mReceiver == null) {
+ Log.e(TAG, "Receiver is null");
+ return;
+ }
+ try {
+ mReceiver.onDialogDismissed(FingerprintDialog.DISMISSED_REASON_NEGATIVE);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception when handling negative button", e);
+ }
+ handleHideDialog(false /* userCanceled */);
+ }
+
+ private void handleButtonPositive() {
+ if (mReceiver == null) {
+ Log.e(TAG, "Receiver is null");
+ return;
+ }
+ try {
+ mReceiver.onDialogDismissed(FingerprintDialog.DISMISSED_REASON_POSITIVE);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception when handling positive button", e);
+ }
+ handleHideDialog(false /* userCanceled */);
+ }
+
+ private void handleClearMessage() {
+ mDialogView.clearMessage();
+ }
+
+ private void handleUserCanceled() {
+ handleHideDialog(true /* userCanceled */);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogView.java b/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogView.java
new file mode 100644
index 0000000000000..d4afa84a8d6f3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/fingerprint/FingerprintDialogView.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.fingerprint;
+
+import android.animation.Animator;
+import android.app.ActivityManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
+import android.hardware.fingerprint.FingerprintDialog;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.util.DisplayMetrics;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewPropertyAnimator;
+import android.view.WindowManager;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Interpolator;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.systemui.R;
+import com.android.systemui.shared.system.ActivityManagerWrapper;
+import com.android.systemui.shared.system.PackageManagerWrapper;
+
+/**
+ * This class loads the view for the system-provided dialog. The view consists of:
+ * Application Icon, Title, Subtitle, Description, Fingerprint Icon, Error/Help message area,
+ * and positive/negative buttons.
+ */
+public class FingerprintDialogView extends LinearLayout {
+
+ private static final String TAG = "FingerprintDialogView";
+
+ private static final int ANIMATION_VERTICAL_OFFSET_DP = 96;
+ private static final int ANIMATION_DURATION = 250; // ms
+
+ private final IBinder mWindowToken = new Binder();
+ private final WindowManager mWindowManager;
+ private final ActivityManagerWrapper mActivityManagerWrapper;
+ private final PackageManagerWrapper mPackageManageWrapper;
+ private final Interpolator mLinearOutSlowIn;
+ private final Interpolator mFastOutLinearIn;
+
+ private ViewGroup mLayout;
+ private final TextView mErrorText;
+ private Handler mHandler;
+ private Bundle mBundle;
+ private final float mDensity;
+ private final LinearLayout mDialog;
+
+ public FingerprintDialogView(Context context, Handler handler) {
+ super(context);
+ mHandler = handler;
+ mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ mActivityManagerWrapper = ActivityManagerWrapper.getInstance();
+ mPackageManageWrapper = PackageManagerWrapper.getInstance();
+ mLinearOutSlowIn = AnimationUtils
+ .loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
+ mFastOutLinearIn = AnimationUtils
+ .loadInterpolator(getContext(), android.R.interpolator.fast_out_linear_in);
+
+ // Create the dialog
+ LayoutInflater factory = LayoutInflater.from(getContext());
+ mLayout = (ViewGroup) factory.inflate(R.layout.fingerprint_dialog, this, false);
+ addView(mLayout);
+
+ mDialog = mLayout.findViewById(R.id.dialog);
+ DisplayMetrics metrics = new DisplayMetrics();
+ mWindowManager.getDefaultDisplay().getMetrics(metrics);
+ mDensity = metrics.density;
+
+ mErrorText = mLayout.findViewById(R.id.error);
+
+ mLayout.setOnKeyListener(new View.OnKeyListener() {
+ boolean downPressed = false;
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (keyCode != KeyEvent.KEYCODE_BACK) {
+ return false;
+ }
+ if (event.getAction() == KeyEvent.ACTION_DOWN && downPressed == false) {
+ downPressed = true;
+ } else if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ downPressed = false;
+ } else if (event.getAction() == KeyEvent.ACTION_UP && downPressed == true) {
+ downPressed = false;
+ mHandler.obtainMessage(FingerprintDialogImpl.MSG_USER_CANCELED).sendToTarget();
+ }
+ return true;
+ }
+ });
+
+ final View space = mLayout.findViewById(R.id.space);
+ final Button negative = mLayout.findViewById(R.id.button2);
+ final Button positive = mLayout.findViewById(R.id.button1);
+
+ space.setClickable(true);
+ space.setOnTouchListener((View view, MotionEvent event) -> {
+ mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG, true /* userCanceled*/)
+ .sendToTarget();
+ return true;
+ });
+
+ negative.setOnClickListener((View v) -> {
+ mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_NEGATIVE).sendToTarget();
+ });
+
+ positive.setOnClickListener((View v) -> {
+ mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_POSITIVE).sendToTarget();
+ });
+
+ mLayout.setFocusableInTouchMode(true);
+ mLayout.requestFocus();
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ final TextView title = mLayout.findViewById(R.id.title);
+ final TextView subtitle = mLayout.findViewById(R.id.subtitle);
+ final TextView description = mLayout.findViewById(R.id.description);
+ final Button negative = mLayout.findViewById(R.id.button2);
+ final ImageView image = mLayout.findViewById(R.id.icon);
+ final Button positive = mLayout.findViewById(R.id.button1);
+ final ImageView fingerprint_icon = mLayout.findViewById(R.id.fingerprint_icon);
+
+ title.setText(mBundle.getCharSequence(FingerprintDialog.KEY_TITLE));
+ title.setSelected(true);
+ subtitle.setText(mBundle.getCharSequence(FingerprintDialog.KEY_SUBTITLE));
+ description.setText(mBundle.getCharSequence(FingerprintDialog.KEY_DESCRIPTION));
+ negative.setText(mBundle.getCharSequence(FingerprintDialog.KEY_NEGATIVE_TEXT));
+ image.setImageDrawable(getAppIcon());
+
+ final CharSequence positiveText =
+ mBundle.getCharSequence(FingerprintDialog.KEY_POSITIVE_TEXT);
+ positive.setText(positiveText); // needs to be set for marquee to work
+ if (positiveText != null) {
+ positive.setVisibility(View.VISIBLE);
+ } else {
+ positive.setVisibility(View.GONE);
+ }
+
+ // Dim the background and slide the dialog up
+ mDialog.setTranslationY(ANIMATION_VERTICAL_OFFSET_DP * mDensity);
+ mLayout.setAlpha(0f);
+ postOnAnimation(new Runnable() {
+ @Override
+ public void run() {
+ mLayout.animate()
+ .alpha(1f)
+ .setDuration(ANIMATION_DURATION)
+ .setInterpolator(mLinearOutSlowIn)
+ .withLayer()
+ .start();
+ mDialog.animate()
+ .translationY(0)
+ .setDuration(ANIMATION_DURATION)
+ .setInterpolator(mLinearOutSlowIn)
+ .withLayer()
+ .start();
+ }
+ });
+ }
+
+ public void setBundle(Bundle bundle) {
+ mBundle = bundle;
+ }
+
+ protected void clearMessage() {
+ mErrorText.setVisibility(View.INVISIBLE);
+ }
+
+ private void showMessage(String message) {
+ mHandler.removeMessages(FingerprintDialogImpl.MSG_CLEAR_MESSAGE);
+ mErrorText.setText(message);
+ mErrorText.setVisibility(View.VISIBLE);
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_CLEAR_MESSAGE),
+ FingerprintDialog.HIDE_DIALOG_DELAY);
+ }
+
+ public void showHelpMessage(String message) {
+ showMessage(message);
+ }
+
+ public void showErrorMessage(String error) {
+ showMessage(error);
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG,
+ false /* userCanceled */), FingerprintDialog.HIDE_DIALOG_DELAY);
+ }
+
+ private Drawable getAppIcon() {
+ final ActivityManager.RunningTaskInfo taskInfo = mActivityManagerWrapper.getRunningTask();
+ final ComponentName cn = taskInfo.topActivity;
+ final int userId = mActivityManagerWrapper.getCurrentUserId();
+ final ActivityInfo activityInfo = mPackageManageWrapper.getActivityInfo(cn, userId);
+ return mActivityManagerWrapper.getBadgedActivityIcon(activityInfo, userId);
+ }
+
+ public WindowManager.LayoutParams getLayoutParams() {
+ final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+ PixelFormat.TRANSLUCENT);
+ lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
+ lp.setTitle("FingerprintDialogView");
+ lp.token = mWindowToken;
+ return lp;
+ }
+}