Created a new activity in settings App.
This activity displays a WifiDppQrCodeGeneratorFragment after unlocking. This will be used by the new "Share Wi-Fi" button in quick settings InternetDialog. Bug: 294487249 Test: atest com.android.settings.wifi.dpp.WifiDppConfiguratorAuthActivityTest Change-Id: I58b61f597db67082f23a1acb4fae5a4556238584
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import static android.content.Intent.ACTION_CLOSE_SYSTEM_DIALOGS;
|
||||
import static android.content.Intent.FLAG_RECEIVER_FOREGROUND;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedActivity;
|
||||
|
||||
/**
|
||||
* Sharing a Wi-Fi network by QR code after unlocking. Used by {@code InternetDialog} in QS.
|
||||
*/
|
||||
public class WifiDppConfiguratorAuthActivity extends InstrumentedActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// This is a transparent activity, disable the dim.
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
Intent authIntent = getSystemService(KeyguardManager.class)
|
||||
.createConfirmDeviceCredentialIntent(
|
||||
getText(R.string.wifi_dpp_lockscreen_title), null, getUserId());
|
||||
if (authIntent == null) {
|
||||
startQrCodeActivity();
|
||||
finish();
|
||||
} else {
|
||||
registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
this::onAuthResult).launch(authIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void onAuthResult(ActivityResult result) {
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
startQrCodeActivity();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void startQrCodeActivity() {
|
||||
// Close quick settings shade
|
||||
sendBroadcast(
|
||||
new Intent(ACTION_CLOSE_SYSTEM_DIALOGS).setFlags(FLAG_RECEIVER_FOREGROUND));
|
||||
Intent qrCodeIntent = new Intent();
|
||||
qrCodeIntent.setAction(
|
||||
WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
qrCodeIntent.putExtras(getIntent());
|
||||
startActivity(qrCodeIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user