Add NetworkRequestDialogActivity
Framwork will call this activity to start network requesting process. This activity is simple activity contained NetworkRequestDialogFragment and any other dialog generated in this process, aka NetworkRequestTimeoutDialog. Bug: 117399926 Test: RunSettingsRoboTests Change-Id: Ib1df28d12427ed3bd7d4b88ec10e52357564c797
This commit is contained in:
@@ -2585,6 +2585,18 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".wifi.NetworkRequestDialogActivity"
|
||||||
|
android:theme="@style/Transparent"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:permission="android.permission.NETWORK_SETTINGS">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.android.settings.wifi.NETWORK_REQUEST" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".sim.SimDialogActivity"
|
<activity android:name=".sim.SimDialogActivity"
|
||||||
android:theme="@style/Theme.AlertDialog"
|
android:theme="@style/Theme.AlertDialog"
|
||||||
android:label="@string/sim_settings_title"
|
android:label="@string/sim_settings_title"
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When other applications request to have a wifi connection, framework will bring up this activity
|
||||||
|
* to let user select which wifi ap wanna to connect. This activity is just a door for framework
|
||||||
|
* call, and main functional process is at {@code NetworkRequestDialogFragment}.
|
||||||
|
*/
|
||||||
|
public class NetworkRequestDialogActivity extends FragmentActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
final NetworkRequestDialogFragment fragment = NetworkRequestDialogFragment.newInstance();
|
||||||
|
fragment.show(getSupportFragmentManager(), "NetworkRequestDialogFragment");
|
||||||
|
}
|
||||||
|
}
|
@@ -28,9 +28,11 @@ import android.net.wifi.WifiManager.NetworkRequestMatchCallback;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.preference.internal.PreferenceImageView;
|
import androidx.preference.internal.PreferenceImageView;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -38,11 +40,13 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -74,7 +78,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
|
|
||||||
final TextView title = customTitle.findViewById(R.id.network_request_title_text);
|
final TextView title = customTitle.findViewById(R.id.network_request_title_text);
|
||||||
title.setText(R.string.network_connection_request_dialog_title);
|
title.setText(R.string.network_connection_request_dialog_title);
|
||||||
final ProgressBar progressBar = customTitle.findViewById(R.id.network_request_title_progress);
|
final ProgressBar progressBar = customTitle.findViewById(
|
||||||
|
R.id.network_request_title_progress);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
// Prepares adapter.
|
// Prepares adapter.
|
||||||
@@ -84,8 +89,14 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setCustomTitle(customTitle)
|
.setCustomTitle(customTitle)
|
||||||
.setAdapter(mDialogAdapter, this)
|
.setAdapter(mDialogAdapter, this)
|
||||||
.setPositiveButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
.setPositiveButton(R.string.cancel, (dialog, which) -> getActivity().finish());
|
||||||
return builder.create();
|
|
||||||
|
// Clicking list item is to connect wifi ap.
|
||||||
|
final AlertDialog dialog = builder.create();
|
||||||
|
dialog.getListView()
|
||||||
|
.setOnItemClickListener(
|
||||||
|
(parent, view, position, id) -> this.onClick(dialog, position));
|
||||||
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -117,6 +128,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel(@NonNull DialogInterface dialog) {
|
||||||
|
super.onCancel(dialog);
|
||||||
|
// Finishes activity when user clicks back key or outside of dialog.
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@@ -188,7 +206,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = mInflater.inflate(mResourceId, parent, false);
|
view = mInflater.inflate(mResourceId, parent, false);
|
||||||
|
|
||||||
final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider);
|
final View divider = view.findViewById(
|
||||||
|
com.android.settingslib.R.id.two_target_divider);
|
||||||
divider.setVisibility(View.GONE);
|
divider.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,8 +226,10 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
final PreferenceImageView imageView = view.findViewById(android.R.id.icon);
|
final PreferenceImageView imageView = view.findViewById(android.R.id.icon);
|
||||||
final int level = accessPoint.getLevel();
|
final int level = accessPoint.getLevel();
|
||||||
if (imageView != null) {
|
if (imageView != null) {
|
||||||
final Drawable drawable = getContext().getDrawable(Utils.getWifiIconResource(level));
|
final Drawable drawable = getContext().getDrawable(
|
||||||
drawable.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal));
|
Utils.getWifiIconResource(level));
|
||||||
|
drawable.setTintList(
|
||||||
|
Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal));
|
||||||
imageView.setImageDrawable(drawable);
|
imageView.setImageDrawable(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {
|
||||||
|
ShadowAlertDialogCompat.class,
|
||||||
|
SettingsShadowResourcesImpl.class
|
||||||
|
})
|
||||||
|
public class NetworkRequestDialogActivityTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void LaunchActivity_shouldShowNetworkRequestDialog() {
|
||||||
|
NetworkRequestDialogActivity activity = Robolectric
|
||||||
|
.setupActivity(NetworkRequestDialogActivity.class);
|
||||||
|
|
||||||
|
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
|
||||||
|
assertThat(alertDialog.isShowing()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user