Merge "Settings: Fix NPE FC when access saved wifi p2p device after screen rotation" am: c68e241fa6
am: ec1b6c308a
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1989236 Change-Id: I7ba4a451a493b9d4df278f7aee6bfbacc9bf2322 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -47,6 +47,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -199,7 +200,10 @@ public class WifiP2pSettings extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
final View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
if (mWifiP2pManager == null) {
|
if (mWifiP2pManager == null) {
|
||||||
mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
||||||
@@ -332,8 +336,7 @@ public class WifiP2pSettings extends DashboardFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return root;
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -39,7 +39,7 @@ import android.net.wifi.p2p.WifiP2pInfo;
|
|||||||
import android.net.wifi.p2p.WifiP2pManager;
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
@@ -110,30 +110,30 @@ public class WifiP2pSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityCreate_withNullBundle_canNotGetValue() {
|
public void onCreateView_withNullBundle_canNotGetValue() {
|
||||||
mFragment.onActivityCreated(null);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, null);
|
||||||
|
|
||||||
assertThat(mFragment.mSelectedWifiPeer).isNull();
|
assertThat(mFragment.mSelectedWifiPeer).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityCreate_withDeviceName_shouldGetDeviceName() {
|
public void onCreateView_withDeviceName_shouldGetDeviceName() {
|
||||||
final String fakeDeviceName = "fakename";
|
final String fakeDeviceName = "fakename";
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
||||||
|
|
||||||
mFragment.onActivityCreated(bundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, bundle);
|
||||||
|
|
||||||
assertThat(mFragment.mSavedDeviceName).isEqualTo(fakeDeviceName);
|
assertThat(mFragment.mSavedDeviceName).isEqualTo(fakeDeviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityCreate_withGroupName_shouldGetGroupName() {
|
public void onCreateView_withGroupName_shouldGetGroupName() {
|
||||||
final String fakeGroupName = "fakegroup";
|
final String fakeGroupName = "fakegroup";
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
|
bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
|
||||||
|
|
||||||
mFragment.onActivityCreated(bundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, bundle);
|
||||||
|
|
||||||
assertThat(mFragment.mSelectedGroupName).isEqualTo(fakeGroupName);
|
assertThat(mFragment.mSelectedGroupName).isEqualTo(fakeGroupName);
|
||||||
assertThat(mFragment.mSavedDeviceName).isNull();
|
assertThat(mFragment.mSavedDeviceName).isNull();
|
||||||
@@ -279,7 +279,7 @@ public class WifiP2pSettingsTest {
|
|||||||
final String fakeDeviceName = "fakeName";
|
final String fakeDeviceName = "fakeName";
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
||||||
mFragment.onActivityCreated(bundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, bundle);
|
||||||
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
||||||
|
|
||||||
mFragment.mRenameListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
mFragment.mRenameListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||||
@@ -292,7 +292,8 @@ public class WifiP2pSettingsTest {
|
|||||||
final String fakeDeviceName = "wrongName***";
|
final String fakeDeviceName = "wrongName***";
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
||||||
mFragment.onActivityCreated(bundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, bundle);
|
||||||
|
|
||||||
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
||||||
|
|
||||||
mFragment.mRenameListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
mFragment.mRenameListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||||
@@ -394,7 +395,7 @@ public class WifiP2pSettingsTest {
|
|||||||
final String fakeDeviceName = "fakeName";
|
final String fakeDeviceName = "fakeName";
|
||||||
final Bundle createBundle = new Bundle();
|
final Bundle createBundle = new Bundle();
|
||||||
createBundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
createBundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
|
||||||
mFragment.onActivityCreated(createBundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, createBundle);
|
||||||
final Bundle outBundle = new Bundle();
|
final Bundle outBundle = new Bundle();
|
||||||
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
|
||||||
|
|
||||||
@@ -430,7 +431,7 @@ public class WifiP2pSettingsTest {
|
|||||||
doReturn(groupList).when(wifiP2pGroupList).getGroupList();
|
doReturn(groupList).when(wifiP2pGroupList).getGroupList();
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
|
bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
|
||||||
mFragment.onActivityCreated(bundle);
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, bundle);
|
||||||
|
|
||||||
mFragment.onPersistentGroupInfoAvailable(wifiP2pGroupList);
|
mFragment.onPersistentGroupInfoAvailable(wifiP2pGroupList);
|
||||||
|
|
||||||
@@ -503,20 +504,20 @@ public class WifiP2pSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() {
|
public void onCreateView_withNullP2pManager_shouldGetP2pManagerAgain() {
|
||||||
mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow
|
mFragment.mChannel = null; // Reset channel to re-test onCreateView flow
|
||||||
mFragment.mWifiP2pManager = null;
|
mFragment.mWifiP2pManager = null;
|
||||||
|
|
||||||
mFragment.onActivityCreated(new Bundle());
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle());
|
||||||
|
|
||||||
assertThat(mFragment.mWifiP2pManager).isNotNull();
|
assertThat(mFragment.mWifiP2pManager).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityCreate_withNullChannel_shouldSetP2pManagerNull() {
|
public void onCreateView_withNullChannel_shouldSetP2pManagerNull() {
|
||||||
doReturn(null).when(mWifiP2pManager).initialize(any(), any(), any());
|
doReturn(null).when(mWifiP2pManager).initialize(any(), any(), any());
|
||||||
mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow
|
mFragment.mChannel = null; // Reset channel to re-test onCreateView flow
|
||||||
mFragment.onActivityCreated(new Bundle());
|
mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle());
|
||||||
|
|
||||||
assertThat(mFragment.mWifiP2pManager).isNull();
|
assertThat(mFragment.mWifiP2pManager).isNull();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user