Fix NPE when there's no forgot password button.

Test: manual
Bug: 149887743
Change-Id: If2238aec2e618f617b7459b819303c03f009941a
This commit is contained in:
Pavel Grafov
2020-02-20 12:32:57 +00:00
parent 3c96925aef
commit c4d9980a5d
7 changed files with 30 additions and 14 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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();