Fix NPE when there's no forgot password button.
Test: manual Bug: 149887743 Change-Id: If2238aec2e618f617b7459b819303c03f009941a
This commit is contained in:
@@ -62,7 +62,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?attr/sudMarginSides"
|
||||
android:layout_marginEnd="?attr/sudMarginSides"
|
||||
android:layout_gravity="center" />
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
|
@@ -59,7 +59,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?attr/sudMarginSides"
|
||||
android:layout_marginEnd="?attr/sudMarginSides" />x
|
||||
android:layout_marginEnd="?attr/sudMarginSides" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
@@ -77,7 +77,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?attr/sudMarginSides"
|
||||
android:layout_marginEnd="?attr/sudMarginSides"
|
||||
android:layout_gravity="center" />
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -61,7 +61,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?attr/sudMarginSides"
|
||||
android:layout_marginEnd="?attr/sudMarginSides"
|
||||
android:layout_gravity="center" />
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
|
@@ -72,7 +72,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?attr/sudMarginSides"
|
||||
android:layout_marginEnd="?attr/sudMarginSides"
|
||||
android:layout_gravity="center" />
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@@ -37,6 +37,7 @@ import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
@@ -57,7 +58,7 @@ import com.android.settings.core.InstrumentedFragment;
|
||||
* Base fragment to be shared for PIN/Pattern/Password confirmation fragments.
|
||||
*/
|
||||
public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFragment {
|
||||
|
||||
public static final String TAG = ConfirmDeviceCredentialBaseFragment.class.getSimpleName();
|
||||
public static final String TITLE_TEXT = SETTINGS_PACKAGE_NAME + ".ConfirmCredentials.title";
|
||||
public static final String HEADER_TEXT = SETTINGS_PACKAGE_NAME + ".ConfirmCredentials.header";
|
||||
public static final String DETAILS_TEXT = SETTINGS_PACKAGE_NAME + ".ConfirmCredentials.details";
|
||||
@@ -78,7 +79,8 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
||||
|
||||
protected boolean mReturnCredentials = false;
|
||||
protected Button mCancelButton;
|
||||
protected Button mForgotButton;
|
||||
/** Button allowing managed profile password reset, null when is not shown. */
|
||||
@Nullable protected Button mForgotButton;
|
||||
protected int mEffectiveUserId;
|
||||
protected int mUserId;
|
||||
protected UserManager mUserManager;
|
||||
@@ -133,10 +135,18 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
||||
}
|
||||
getActivity().finish();
|
||||
});
|
||||
mForgotButton = view.findViewById(R.id.forgotButton);
|
||||
setupForgotButtonIfManagedProfile(view);
|
||||
}
|
||||
|
||||
private void setupForgotButtonIfManagedProfile(View view) {
|
||||
if (mUserManager.isManagedProfile(mUserId)
|
||||
&& mUserManager.isQuietModeEnabled(UserHandle.of(mUserId))
|
||||
&& mDevicePolicyManager.canProfileOwnerResetPasswordWhenLocked(mUserId)) {
|
||||
mForgotButton = view.findViewById(R.id.forgotButton);
|
||||
if (mForgotButton == null) {
|
||||
Log.wtf(TAG, "Forgot button not found in managed profile credential dialog");
|
||||
return;
|
||||
}
|
||||
mForgotButton.setVisibility(View.VISIBLE);
|
||||
mForgotButton.setOnClickListener(v -> {
|
||||
final Intent intent = new Intent();
|
||||
@@ -145,8 +155,6 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().finish();
|
||||
});
|
||||
} else {
|
||||
mForgotButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -267,7 +267,9 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
|
||||
mHeaderTextView.setAlpha(0f);
|
||||
mDetailsTextView.setAlpha(0f);
|
||||
mCancelButton.setAlpha(0f);
|
||||
mForgotButton.setAlpha(0f);
|
||||
if (mForgotButton != null) {
|
||||
mForgotButton.setAlpha(0f);
|
||||
}
|
||||
mPasswordEntry.setAlpha(0f);
|
||||
mErrorTextView.setAlpha(0f);
|
||||
}
|
||||
@@ -279,7 +281,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
|
||||
if (mCancelButton.getVisibility() == View.VISIBLE) {
|
||||
result.add(mCancelButton);
|
||||
}
|
||||
if (mForgotButton.getVisibility() == View.VISIBLE) {
|
||||
if (mForgotButton != null) {
|
||||
result.add(mForgotButton);
|
||||
}
|
||||
result.add(mPasswordEntry);
|
||||
|
@@ -240,7 +240,9 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
|
||||
super.prepareEnterAnimation();
|
||||
mHeaderTextView.setAlpha(0f);
|
||||
mCancelButton.setAlpha(0f);
|
||||
mForgotButton.setAlpha(0f);
|
||||
if (mForgotButton != null) {
|
||||
mForgotButton.setAlpha(0f);
|
||||
}
|
||||
mLockPatternView.setAlpha(0f);
|
||||
mDetailsTextView.setAlpha(0f);
|
||||
}
|
||||
@@ -268,7 +270,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
|
||||
if (mCancelButton.getVisibility() == View.VISIBLE) {
|
||||
result.add(new ArrayList<>(Collections.singletonList(mCancelButton)));
|
||||
}
|
||||
if (mForgotButton.getVisibility() == View.VISIBLE) {
|
||||
if (mForgotButton != null) {
|
||||
result.add(new ArrayList<>(Collections.singletonList(mForgotButton)));
|
||||
}
|
||||
LockPatternView.CellState[][] cellStates = mLockPatternView.getCellStates();
|
||||
|
Reference in New Issue
Block a user