Snap for 5147358 from abc37ee8c0 to qt-release

Change-Id: Ieb5ecfc54f61534605c020f103822b541e815423
This commit is contained in:
android-build-team Robot
2018-11-25 04:04:15 +00:00
18 changed files with 853 additions and 27 deletions

View File

@@ -3018,6 +3018,9 @@
<action android:name="android.content.action.SETTINGS_HOMEPAGE_DATA"/>
</intent-filter>
</provider>
<activity
android:name=".wifi.dpp.WifiDppConfiguratorActivity"/>
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_wifi_signal_4"
android:layout_gravity="center"/>
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:text="left"
style="?android:attr/borderlessButtonStyle"/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="right"/>
</LinearLayout>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/wifi_dpp_fragment_header"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="320dp"
android:layout_height="426dp"
android:layout_gravity="center"/>
<ImageView
android:id="@+id/decorate_view"
android:layout_width="320dp"
android:layout_height="426dp"
android:layout_gravity="center"/>
</FrameLayout>
<TextView android:id="@+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<include layout="@layout/wifi_dpp_fragment_footer"
android:gravity="center|bottom"/>
</LinearLayout>

View File

@@ -2050,6 +2050,10 @@
<string name="wifi_ip_settings">IP settings</string>
<!-- Label for the spinner to show Wifi MAC randomization [CHAR LIMIT=25] -->
<string name="wifi_privacy_settings">Privacy</string>
<!-- Title for the fragment to add a device into the wifi network [CHAR LIMIT=50] -->
<string name="wifi_dpp_add_device_to_network">Add a device to this network</string>
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=120] -->
<string name="wifi_dpp_center_qr_code">Center the device\u2019s QR code below to add device to \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
<!-- Label for the check box to share a network with other users on the same device -->
<string name="wifi_shared">Share with other device users</string>
<!-- Hint for unchanged fields -->

View File

@@ -16,7 +16,7 @@
package com.android.settings.datetime.timezone.model;
import libcore.util.CountryTimeZones;
import libcore.timezone.CountryTimeZones;
import java.util.Collections;
import java.util.List;

View File

@@ -18,9 +18,9 @@ package com.android.settings.datetime.timezone.model;
import androidx.annotation.VisibleForTesting;
import androidx.collection.ArraySet;
import libcore.util.CountryTimeZones;
import libcore.util.CountryZonesFinder;
import libcore.util.TimeZoneFinder;
import libcore.timezone.CountryTimeZones;
import libcore.timezone.CountryZonesFinder;
import libcore.timezone.TimeZoneFinder;
import java.lang.ref.WeakReference;
import java.util.Collections;

View File

@@ -19,9 +19,18 @@ package com.android.settings.wifi;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.NetworkRequestUserSelectionCallback;
import android.net.wifi.WifiManager.NetworkRequestMatchCallback;
import android.os.Handler;
import android.os.Message;
import android.widget.BaseAdapter;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.internal.PreferenceImageView;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -32,20 +41,23 @@ import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.Utils;
import com.android.settingslib.wifi.AccessPoint;
import java.util.ArrayList;
import java.util.List;
public class NetworkRequestDialogFragment extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener {
DialogInterface.OnClickListener, NetworkRequestMatchCallback {
/** Message sent to us to stop scanning wifi and pop up timeout dialog. */
private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0;
/** Delayed time to stop scanning wifi. */
private static final int DELAY_TIME_STOP_SCAN_MS = 30*1000;
private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000;
private List<AccessPoint> mAccessPointList;
private AccessPointAdapter mDialogAdapter;
private NetworkRequestUserSelectionCallback mUserSelectionCallback;
public static NetworkRequestDialogFragment newInstance() {
NetworkRequestDialogFragment dialogFragment = new NetworkRequestDialogFragment();
@@ -54,28 +66,29 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getContext();
final Context context = getContext();
// Prepares title.
LayoutInflater inflater = LayoutInflater.from(context);
View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null);
final LayoutInflater inflater = LayoutInflater.from(context);
final View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null);
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);
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);
// Prepares adapter.
AccessPointAdapter adapter = new AccessPointAdapter(context,
mDialogAdapter = new AccessPointAdapter(context,
R.layout.preference_access_point, getAccessPointList());
AlertDialog.Builder builder = new AlertDialog.Builder(context)
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCustomTitle(customTitle)
.setAdapter(adapter, this)
.setAdapter(mDialogAdapter, this)
.setPositiveButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
return builder.create();
}
@NonNull
List<AccessPoint> getAccessPointList() {
// Initials list for adapter, in case of display crashing.
if (mAccessPointList == null) {
@@ -84,8 +97,24 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
return mAccessPointList;
}
private BaseAdapter getDialogAdapter() {
return mDialogAdapter;
}
@Override
public void onClick(DialogInterface dialog, int which) {
final List<AccessPoint> accessPointList = getAccessPointList();
if (accessPointList.size() == 0) {
return; // Invalid values.
}
if (mUserSelectionCallback == null) {
return; // Callback is missing or not ready.
}
if (which < accessPointList.size()) {
WifiConfiguration wifiConfig = accessPointList.get(which).getConfig();
mUserSelectionCallback.select(wifiConfig);
}
}
@Override
@@ -93,19 +122,27 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
super.onPause();
mHandler.removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST);
final WifiManager wifiManager = getContext().getApplicationContext()
.getSystemService(WifiManager.class);
if (wifiManager != null) {
wifiManager.unregisterNetworkRequestMatchCallback(this);
}
}
@Override
public void onResume() {
super.onResume();
// TODO(b/117399926): Starts to scan current WiFi.
final WifiManager wifiManager = getContext().getApplicationContext()
.getSystemService(WifiManager.class);
if (wifiManager != null) {
wifiManager.registerNetworkRequestMatchCallback(this, mHandler);
}
// Sets time-out to stop scanning.
mHandler.sendEmptyMessageDelayed(MESSAGE_STOP_SCAN_WIFI_LIST, DELAY_TIME_STOP_SCAN_MS);
}
private Handler mHandler = new Handler() {
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -121,8 +158,12 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
};
protected void stopScanningAndPopTimeoutDialog() {
// Dismisses current dialog.
dismiss();
NetworkRequestTimeoutDialogFragment fragment = NetworkRequestTimeoutDialogFragment.newInstance();
// Throws new timeout dialog.
final NetworkRequestTimeoutDialogFragment fragment = NetworkRequestTimeoutDialogFragment
.newInstance();
fragment.show(getActivity().getSupportFragmentManager(), null);
}
@@ -146,14 +187,108 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = mInflater.inflate(mResourceId, parent, false);
final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider);
divider.setVisibility(View.GONE);
}
// TODO: Sets correct information to list item.
final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider);
divider.setVisibility(View.GONE);
final AccessPoint accessPoint = getItem(position);
final TextView titleView = view.findViewById(android.R.id.title);
if (titleView != null) {
titleView.setText(accessPoint.getSsidStr());
}
final TextView summary = view.findViewById(android.R.id.summary);
if (summary != null) {
summary.setText(accessPoint.getSettingsSummary());
}
final PreferenceImageView imageView = view.findViewById(android.R.id.icon);
final int level = accessPoint.getLevel();
if (imageView != null) {
final Drawable drawable = getContext().getDrawable(Utils.getWifiIconResource(level));
drawable.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal));
imageView.setImageDrawable(drawable);
}
return view;
}
}
}
@Override
public void onAbort() {
// TODO(b/117399926): We should have a UI notify user here.
}
@Override
public void onUserSelectionCallbackRegistration(
NetworkRequestUserSelectionCallback userSelectionCallback) {
mUserSelectionCallback = userSelectionCallback;
}
@Override
public void onMatch(List<ScanResult> scanResults) {
// TODO(b/119846365): Checks if we could escalate the converting effort.
// Converts ScanResult to WifiConfiguration.
List<WifiConfiguration> wifiConfigurations = null;
final WifiManager wifiManager = getContext().getApplicationContext()
.getSystemService(WifiManager.class);
if (wifiManager != null) {
wifiConfigurations = wifiManager.getAllMatchingWifiConfigs(scanResults);
}
setUpAccessPointList(wifiConfigurations);
if (getDialogAdapter() != null) {
getDialogAdapter().notifyDataSetChanged();
}
}
@Override
public void onUserSelectionConnectSuccess(WifiConfiguration wificonfiguration) {
if (getDialogAdapter() != null) {
updateAccessPointListItem(wificonfiguration);
getDialogAdapter().notifyDataSetChanged();
}
}
@Override
public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) {
if (mDialogAdapter != null) {
updateAccessPointListItem(wificonfiguration);
getDialogAdapter().notifyDataSetChanged();
}
}
private void updateAccessPointListItem(WifiConfiguration wificonfiguration) {
if (wificonfiguration == null) {
return;
}
final List<AccessPoint> accessPointList = getAccessPointList();
final int accessPointListSize = accessPointList.size();
for (int i = 0; i < accessPointListSize; i++) {
AccessPoint accessPoint = accessPointList.get(i);
// It is the same AccessPoint SSID, and should be replaced to update latest properties.
if (accessPoint.matches(wificonfiguration)) {
accessPointList.set(i, new AccessPoint(getContext(), wificonfiguration));
break;
}
}
}
private void setUpAccessPointList(List<WifiConfiguration> wifiConfigurations) {
// Grants for zero size input, since maybe current wifi is off or somethings are wrong.
if (wifiConfigurations == null) {
return;
}
final List<AccessPoint> accessPointList = getAccessPointList();
accessPointList.clear();
for (WifiConfiguration config : wifiConfigurations) {
accessPointList.add(new AccessPoint(getContext(), config));
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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.dpp;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedActivity;
import com.android.settings.R;
public class WifiDppConfiguratorActivity extends InstrumentedActivity {
private static final String TAG = "WifiDppConfiguratorActivity";
private FragmentManager mFragmentManager;
private FragmentTransaction mFragmentTransaction;
public static final String EXTRA_LAUNCH_MODE =
"com.android.settings.wifi.dpp.EXTRA_LAUNCH_MODE";
public static final String EXTRA_SSID = "com.android.settings.wifi.dpp.EXTRA_SSID";
public enum LaunchMode {
LAUNCH_MODE_QR_CODE_SCANNER(1),
LAUNCH_MODE_QR_CODE_GENERATOR(2),
LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK(3),
LAUNCH_MODE_NOT_DEFINED(-1);
private int mMode;
LaunchMode(int mode) {
this.mMode = mode;
}
public int getMode() {
return mMode;
}
}
@Override
public int getMetricsCategory() {
//TODO:Should we use a new metrics category for Wi-Fi DPP?
return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wifi_dpp_activity);
// Hide action bar
ActionBar action = getActionBar();
if (action != null) {
action.hide();
}
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = getSupportFragmentManager().beginTransaction();
final int launchMode = getIntent().getIntExtra(EXTRA_LAUNCH_MODE,
LaunchMode.LAUNCH_MODE_NOT_DEFINED.getMode());
if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode()) {
WifiDppQrCodeScannerFragment scanFragment = new WifiDppQrCodeScannerFragment();
mFragmentTransaction.add(R.id.fragment_container, scanFragment);
mFragmentTransaction.commit();
} else {
Log.e(TAG, "Launch with an invalid mode extra");
setResult(Activity.RESULT_CANCELED);
finish();
}
}
}

View File

@@ -0,0 +1,107 @@
/*
* 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.dpp;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.R;
public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
private TextView mTitle;
private TextView mDescription;
private SurfaceView mPreviewView;
private TextView mErrorMessage; //optional, view used to surface connectivity errors to the user
private Button mButtonLeft;
private Button mButtonRight;
abstract protected int getLayout();
@Override
public int getMetricsCategory() {
//TODO:Should we use a new metrics category for Wi-Fi DPP?
return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
}
@Override
public final void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public final View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(getLayout(), container, false);
initView(view);
return view;
}
private void initView(View view) {
mTitle = view.findViewById(R.id.title);
mDescription = view.findViewById(R.id.description);
mPreviewView = view.findViewById(R.id.preview_view);
mErrorMessage = view.findViewById(R.id.error_message);
mButtonLeft = view.findViewById(R.id.button_left);
mButtonRight = view.findViewById(R.id.button_right);
}
protected void setTitle(String title) {
mTitle.setText(title);
}
protected void setDescription(String description) {
mDescription.setText(description);
}
protected void setErrorMessage(String errorMessage) {
if (mErrorMessage != null) {
mErrorMessage.setText(errorMessage);
}
}
protected void setLeftButtonText(String text) {
mButtonLeft.setText(text);
}
protected void setRightButtonText(String text) {
mButtonRight.setText(text);
}
protected void hideLeftButton() {
mButtonLeft.setVisibility(View.INVISIBLE);
}
protected void hideRightButton() {
mButtonRight.setVisibility(View.INVISIBLE);
}
protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
mButtonLeft.setOnClickListener(listener);
}
protected void setRightButtonOnClickListener(View.OnClickListener listener) {
mButtonRight.setOnClickListener(listener);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.dpp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.settings.R;
public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment {
@Override
protected int getLayout() {
return R.layout.wifi_dpp_qrcode_scanner_fragment;
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated (savedInstanceState);
setTitle(getString(R.string.wifi_dpp_add_device_to_network));
String ssid = "";
Intent intent = getActivity().getIntent();
if (intent != null)
ssid = intent.getStringExtra(WifiDppConfiguratorActivity.EXTRA_SSID);
String description = getString(R.string.wifi_dpp_center_qr_code, ssid);
setDescription(description);
hideRightButton();
setLeftButtonText(getString(android.R.string.cancel));
setLeftButtonOnClickListener((view) -> {
getActivity().setResult(Activity.RESULT_CANCELED);
getActivity().finish();});
}
}

View File

@@ -27,7 +27,7 @@ import com.android.settings.datetime.timezone.BaseTimeZoneAdapter.AdapterItem;
import com.android.settings.datetime.timezone.model.TimeZoneData;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import libcore.util.CountryZonesFinder;
import libcore.timezone.CountryZonesFinder;
import org.junit.Before;
import org.junit.Test;

View File

@@ -34,7 +34,7 @@ import com.android.settings.datetime.timezone.RegionSearchPicker.RegionItem;
import com.android.settings.datetime.timezone.model.TimeZoneData;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import libcore.util.CountryZonesFinder;
import libcore.timezone.CountryZonesFinder;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -23,9 +23,9 @@ import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import libcore.util.CountryTimeZones;
import libcore.util.CountryTimeZones.TimeZoneMapping;
import libcore.util.CountryZonesFinder;
import libcore.timezone.CountryTimeZones;
import libcore.timezone.CountryTimeZones.TimeZoneMapping;
import libcore.timezone.CountryZonesFinder;
import org.junit.Before;
import org.junit.Test;

View File

@@ -17,18 +17,34 @@
package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.DialogInterface;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.NetworkRequestUserSelectionCallback;
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settingslib.wifi.AccessPoint;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.robolectric.shadows.ShadowLooper;
@@ -37,13 +53,17 @@ import org.robolectric.shadows.ShadowLooper;
@Config(shadows = {SettingsShadowResourcesImpl.class, ShadowAlertDialogCompat.class})
public class NetworkRequestDialogFragmentTest {
final String KEY_SSID = "key_ssid";
private FragmentActivity mActivity;
private NetworkRequestDialogFragment networkRequestDialogFragment;
private Context mContext;
@Before
public void setUp() {
mActivity = Robolectric.setupActivity(FragmentActivity.class);
networkRequestDialogFragment = spy(NetworkRequestDialogFragment.newInstance());
mContext = spy(RuntimeEnvironment.application);
}
@Test
@@ -88,4 +108,137 @@ public class NetworkRequestDialogFragmentTest {
bCalledStopAndPop = true;
}
}
@Test
public void onResume_shouldRegisterCallback() {
when(networkRequestDialogFragment.getContext()).thenReturn(mContext);
Context applicationContext = spy(RuntimeEnvironment.application.getApplicationContext());
when(mContext.getApplicationContext()).thenReturn(applicationContext);
WifiManager wifiManager = mock(WifiManager.class);
when(applicationContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(wifiManager);
networkRequestDialogFragment.onResume();
verify(wifiManager).registerNetworkRequestMatchCallback(any(), any());
}
@Test
public void onPause_shouldUnRegisterCallback() {
when(networkRequestDialogFragment.getContext()).thenReturn(mContext);
Context applicationContext = spy(RuntimeEnvironment.application.getApplicationContext());
when(mContext.getApplicationContext()).thenReturn(applicationContext);
WifiManager wifiManager = mock(WifiManager.class);
when(applicationContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(wifiManager);
networkRequestDialogFragment.onPause();
verify(wifiManager).unregisterNetworkRequestMatchCallback(networkRequestDialogFragment);
}
@Test
public void updateAccessPointList_onUserSelectionConnectSuccess_updateCorrectly() {
List<AccessPoint> accessPointList = spy(new ArrayList<>());
Bundle bundle = new Bundle();
bundle.putString(KEY_SSID, "Test AP 1");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 2");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 3");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 4");
accessPointList.add(new AccessPoint(mContext, bundle));
when(networkRequestDialogFragment.getAccessPointList()).thenReturn(accessPointList);
networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null);
// Test if config would update list.
WifiConfiguration config = new WifiConfiguration();
config.SSID = "Test AP 3";
networkRequestDialogFragment.onUserSelectionConnectSuccess(config);
AccessPoint verifyAccessPoint = new AccessPoint(mContext, config);
verify(accessPointList, times(1)).set(2, verifyAccessPoint);
}
@Test
public void updateAccessPointList_onUserSelectionConnectFailure_updateCorrectly() {
List<AccessPoint> accessPointList = spy(new ArrayList<>());
Bundle bundle = new Bundle();
bundle.putString(KEY_SSID, "Test AP 1");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 2");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 3");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 4");
accessPointList.add(new AccessPoint(mContext, bundle));
when(networkRequestDialogFragment.getAccessPointList()).thenReturn(accessPointList);
networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null);
// Test if config would update list.
WifiConfiguration config = new WifiConfiguration();
config.SSID = "Test AP 3";
networkRequestDialogFragment.onUserSelectionConnectFailure(config);
AccessPoint verifyAccessPoint = new AccessPoint(mContext, config);
verify(accessPointList, times(1)).set(2, verifyAccessPoint);
}
@Test
public void onUserSelectionCallbackRegistration_shouldCallSelect() {
List<AccessPoint> accessPointList = spy(new ArrayList<>());
Bundle bundle = new Bundle();
bundle.putString(KEY_SSID, "Test AP 1");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 2");
accessPointList.add(new AccessPoint(mContext, bundle));
bundle.putString(KEY_SSID, "Test AP 3");
AccessPoint clickedAccessPoint = new AccessPoint(mContext, bundle);
accessPointList.add(clickedAccessPoint);
bundle.putString(KEY_SSID, "Test AP 4");
accessPointList.add(new AccessPoint(mContext, bundle));
when(networkRequestDialogFragment.getAccessPointList()).thenReturn(accessPointList);
NetworkRequestUserSelectionCallback selectionCallback = mock(
NetworkRequestUserSelectionCallback.class);
AlertDialog dialog = mock(AlertDialog.class);
networkRequestDialogFragment.onUserSelectionCallbackRegistration(selectionCallback);
networkRequestDialogFragment.onClick(dialog, 2);
verify(selectionCallback, times(1)).select(clickedAccessPoint.getConfig());
}
@Test
public void onMatch_shouldUpdatedList() {
// Prepares WifiManager.
when(networkRequestDialogFragment.getContext()).thenReturn(mContext);
Context applicationContext = spy(RuntimeEnvironment.application.getApplicationContext());
when(mContext.getApplicationContext()).thenReturn(applicationContext);
WifiManager wifiManager = mock(WifiManager.class);
when(applicationContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(wifiManager);
List<WifiConfiguration> wifiConfigurationList = new ArrayList<>();
WifiConfiguration config = new WifiConfiguration();
final String SSID_AP1 = "Test AP 1";
config.SSID = SSID_AP1;
wifiConfigurationList.add(config);
config = new WifiConfiguration();
final String SSID_AP2 = "Test AP 2";
config.SSID = SSID_AP2;
wifiConfigurationList.add(config);
// Prepares callback converted data.
List<ScanResult> scanResults = new ArrayList<>();
when(wifiManager.getAllMatchingWifiConfigs(scanResults)).thenReturn(wifiConfigurationList);
networkRequestDialogFragment.onMatch(scanResults);
List<AccessPoint> accessPointList = networkRequestDialogFragment.getAccessPointList();
assertThat(accessPointList).isNotEmpty();
assertThat(accessPointList.size()).isEqualTo(2);
assertThat(accessPointList.get(0).getSsid()).isEqualTo(SSID_AP1);
assertThat(accessPointList.get(1).getSsid()).isEqualTo(SSID_AP2);
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.dpp;
import static com.google.common.truth.Truth.assertThat;
import android.app.Activity;
import android.content.Intent;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class WifiDppConfiguratorActivityTest {
@Rule
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
@Test
public void testLaunchModeQrCodeScanner_shouldNotAutoFinish() {
Intent intent = new Intent();
intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
mActivityRule.launchActivity(intent);
assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
mActivityRule.finishActivity();
}
@Test
public void testNoLaunchMode_shouldFinishActivityWithResultCodeCanceled() {
// If we do not specify launch mode, the activity will finish itself right away
Intent intent = new Intent();
mActivityRule.launchActivity(intent);
assertThat(mActivityRule.getActivityResult().getResultCode()).
isEqualTo(Activity.RESULT_CANCELED);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.dpp;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.Espresso.onView;
import static com.google.common.truth.Truth.assertThat;
import android.app.Activity;
import android.content.Intent;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class WifiDppQrCodeScannerFragmentTest {
@Rule
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
new ActivityTestRule<>(WifiDppConfiguratorActivity.class, true);
@Before
public void setUp() {
Intent intent = new Intent();
intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
mActivityRule.launchActivity(intent);
}
@Test
public void testLeftButton_shouldFinishActivityWithResultCodeCanceled() {
onView(withText("Cancel")).perform(click());
assertThat(mActivityRule.getActivityResult().getResultCode()).
isEqualTo(Activity.RESULT_CANCELED);
}
}