Fix NPE when there's no forgot password button.
Test: manual Bug: 149887743 Change-Id: If2238aec2e618f617b7459b819303c03f009941a
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user