Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5522099e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE when there's no forgot password button."

parents 394323bc c4d9980a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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
+3 −2
Original line number Diff line number Diff line
@@ -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"
+2 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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>

+13 −5
Original line number Diff line number Diff line
@@ -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);
        }
    }

Loading