Fix toast is covered by PIN code screen after wrong pin
The error toast is displayed when user input wrong PIN code three times, but at that moment the SIM PUK code input page in SystemUI pop up and covers the toast, so the user can't seen the error message. Adjust the toast window layer, let the the toast pop up over the SIM pin code input page. Bug: 74056527 Change-Id: I569a2fc2adac15c4713b4c95e9720335bd4df88a
This commit is contained in:
committed by
Yoshiaki Maruoka
parent
b0e99e1472
commit
754930bc50
@@ -20,7 +20,9 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.PixelFormat;
|
||||||
import android.os.AsyncResult;
|
import android.os.AsyncResult;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -30,9 +32,11 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
@@ -40,6 +44,7 @@ import android.widget.TabHost.OnTabChangeListener;
|
|||||||
import android.widget.TabHost.TabContentFactory;
|
import android.widget.TabHost.TabContentFactory;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -118,6 +123,9 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
||||||
private static final int MSG_SIM_STATE_CHANGED = 102;
|
private static final int MSG_SIM_STATE_CHANGED = 102;
|
||||||
|
|
||||||
|
// @see android.widget.Toast$TN
|
||||||
|
private static final long LONG_DURATION_TIMEOUT = 7000;
|
||||||
|
|
||||||
// For replies from IccCard interface
|
// For replies from IccCard interface
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
@@ -461,8 +469,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
if (exception instanceof CommandException) {
|
if (exception instanceof CommandException) {
|
||||||
CommandException.Error err = ((CommandException)(exception)).getCommandError();
|
CommandException.Error err = ((CommandException)(exception)).getCommandError();
|
||||||
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
||||||
Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
|
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
} else {
|
||||||
if (mToState) {
|
if (mToState) {
|
||||||
Toast.makeText(getContext(), mRes.getString
|
Toast.makeText(getContext(), mRes.getString
|
||||||
@@ -478,11 +485,56 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
resetDialogState();
|
resetDialogState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createCustomTextToast(CharSequence errorMessage) {
|
||||||
|
// Cannot overlay Toast on PUK unlock screen.
|
||||||
|
// The window type of Toast is set by NotificationManagerService.
|
||||||
|
// It can't be overwritten by LayoutParams.type.
|
||||||
|
// Ovarlay a custom window with LayoutParams (TYPE_STATUS_BAR_PANEL) on PUK unlock screen.
|
||||||
|
View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
||||||
|
.inflate(com.android.internal.R.layout.transient_notification, null);
|
||||||
|
TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
|
||||||
|
tv.setText(errorMessage);
|
||||||
|
|
||||||
|
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
|
||||||
|
final Configuration config = v.getContext().getResources().getConfiguration();
|
||||||
|
final int gravity = Gravity.getAbsoluteGravity(
|
||||||
|
getContext().getResources().getInteger(
|
||||||
|
com.android.internal.R.integer.config_toastDefaultGravity),
|
||||||
|
config.getLayoutDirection());
|
||||||
|
params.gravity = gravity;
|
||||||
|
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
|
||||||
|
params.horizontalWeight = 1.0f;
|
||||||
|
}
|
||||||
|
if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
|
||||||
|
params.verticalWeight = 1.0f;
|
||||||
|
}
|
||||||
|
params.y = getContext().getResources().getDimensionPixelSize(
|
||||||
|
com.android.internal.R.dimen.toast_y_offset);
|
||||||
|
|
||||||
|
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||||
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||||
|
params.format = PixelFormat.TRANSLUCENT;
|
||||||
|
params.windowAnimations = com.android.internal.R.style.Animation_Toast;
|
||||||
|
params.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
|
||||||
|
params.setTitle(errorMessage);
|
||||||
|
params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||||
|
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||||
|
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||||
|
|
||||||
|
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
wm.addView(v, params);
|
||||||
|
|
||||||
|
mHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
wm.removeViewImmediate(v);
|
||||||
|
}
|
||||||
|
}, LONG_DURATION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
private void iccPinChanged(boolean success, int attemptsRemaining) {
|
private void iccPinChanged(boolean success, int attemptsRemaining) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
|
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
||||||
Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getContext(), mRes.getString(R.string.sim_change_succeeded),
|
Toast.makeText(getContext(), mRes.getString(R.string.sim_change_succeeded),
|
||||||
Toast.LENGTH_SHORT)
|
Toast.LENGTH_SHORT)
|
||||||
|
Reference in New Issue
Block a user