[Settings] Enable ActivityResultLauncher for keyguard
Enable the support of ActivityResultLauncher for keyguard. Bug: 260034791 Test: local Change-Id: I0643241d7b79ba0ac4cd2314a126f33eb6557cc0
This commit is contained in:
@@ -40,6 +40,9 @@ import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
@@ -70,6 +73,7 @@ public class ResetNetwork extends InstrumentedFragment {
|
||||
// Arbitrary to avoid conficts
|
||||
private static final int KEYGUARD_REQUEST = 55;
|
||||
|
||||
private ActivityResultLauncher mActivityResultLauncher;
|
||||
private List<SubscriptionInfo> mSubscriptions;
|
||||
|
||||
private View mContentView;
|
||||
@@ -82,6 +86,10 @@ public class ResetNetwork extends InstrumentedFragment {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getActivity().setTitle(R.string.reset_network_title);
|
||||
|
||||
mActivityResultLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> onActivityLauncherResult(result));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,20 +104,14 @@ public class ResetNetwork extends InstrumentedFragment {
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
return builder.setRequestCode(request)
|
||||
.setTitle(res.getText(R.string.reset_network_title))
|
||||
.setActivityResultLauncher(mActivityResultLauncher)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode != KEYGUARD_REQUEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void onActivityLauncherResult(ActivityResult result) {
|
||||
// If the user entered a valid keyguard trace, present the final
|
||||
// confirmation prompt; otherwise, go back to the initial state.
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
showFinalConfirmation();
|
||||
} else if (mContentView != null) {
|
||||
establishInitialState(getActiveSubscriptionInfoList());
|
||||
|
Reference in New Issue
Block a user