• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

packages/apps/Settings


Commit MetaInfo

Revision72c60f0d6a869158943961a1d8b2d1d4539a32e2 (tree)
Zeit2021-08-16 13:15:31
AutorAndroid Build Coastguard Worker <android-build-coastguard-worker@goog...>
CommiterAndroid Build Coastguard Worker

Log Message

Merge cherrypicks of [15581311, 15581312, 15581313, 15581314, 15581326, 15581327, 15581138, 15581139, 15581140, 15581341, 15581342, 15581343, 15581344, 15581095, 15581315, 15581316, 15581317, 15581345, 15581328] into rvc-d2-release

Change-Id: I2cb951d02f087df3bef53d54679b0ae786a1ebfb

Ändern Zusammenfassung

Diff

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2711,6 +2711,10 @@
27112711 </intent-filter>
27122712 </activity>
27132713
2714+ <!--
2715+ The Wi-Fi result data will only be returned from WifiDialogActivity if the calling
2716+ package has ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission. (see b/185126813)
2717+ -->
27142718 <activity
27152719 android:name=".wifi.WifiDialogActivity"
27162720 android:label=""
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -16,14 +16,19 @@
1616
1717 package com.android.settings.wifi;
1818
19+import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
20+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
21+
1922 import android.app.Activity;
2023 import android.content.DialogInterface;
2124 import android.content.Intent;
25+import android.content.pm.PackageManager;
2226 import android.net.NetworkInfo;
2327 import android.net.wifi.WifiConfiguration;
2428 import android.net.wifi.WifiManager;
2529 import android.net.wifi.WifiManager.ActionListener;
2630 import android.os.Bundle;
31+import android.util.EventLog;
2732 import android.util.Log;
2833
2934 import androidx.annotation.VisibleForTesting;
@@ -53,10 +58,12 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
5358
5459 public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
5560
56- private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
61+ @VisibleForTesting
62+ static final int RESULT_CONNECTED = RESULT_FIRST_USER;
5763 private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
5864
59- private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
65+ @VisibleForTesting
66+ static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
6067
6168 private WifiDialog mDialog;
6269
@@ -156,17 +163,22 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
156163 }
157164 }
158165
159- Intent resultData = new Intent();
166+ Intent resultData = hasPermissionForResult() ? createResultData(config, accessPoint) : null;
167+ setResult(RESULT_CONNECTED, resultData);
168+ finish();
169+ }
170+
171+ protected Intent createResultData(WifiConfiguration config, AccessPoint accessPoint) {
172+ Intent result = new Intent();
160173 if (accessPoint != null) {
161174 Bundle accessPointState = new Bundle();
162175 accessPoint.saveWifiState(accessPointState);
163- resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
176+ result.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
164177 }
165178 if (config != null) {
166- resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
179+ result.putExtra(KEY_WIFI_CONFIGURATION, config);
167180 }
168- setResult(RESULT_CONNECTED, resultData);
169- finish();
181+ return result;
170182 }
171183
172184 @Override
@@ -192,9 +204,44 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
192204 if (resultCode != RESULT_OK) {
193205 return;
194206 }
195-
196- setResult(RESULT_CONNECTED, data);
207+ if (hasPermissionForResult()) {
208+ setResult(RESULT_CONNECTED, data);
209+ } else {
210+ setResult(RESULT_CONNECTED);
211+ }
197212 finish();
198213 }
199214 }
215+
216+ protected boolean hasPermissionForResult() {
217+ final String callingPackage = getCallingPackage();
218+ if (callingPackage == null) {
219+ Log.d(TAG, "Failed to get the calling package, don't return the result.");
220+ EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no calling package");
221+ return false;
222+ }
223+
224+ if (getPackageManager().checkPermission(ACCESS_COARSE_LOCATION, callingPackage)
225+ == PackageManager.PERMISSION_GRANTED) {
226+ Log.d(TAG, "The calling package has ACCESS_COARSE_LOCATION permission for result.");
227+ return true;
228+ }
229+
230+ if (getPackageManager().checkPermission(ACCESS_FINE_LOCATION, callingPackage)
231+ == PackageManager.PERMISSION_GRANTED) {
232+ Log.d(TAG, "The calling package has ACCESS_FINE_LOCATION permission for result.");
233+ return true;
234+ }
235+
236+ Log.d(TAG, "The calling package does not have the necessary permissions for result.");
237+ try {
238+ EventLog.writeEvent(0x534e4554, "185126813",
239+ getPackageManager().getPackageUid(callingPackage, 0 /* flags */),
240+ "no permission");
241+ } catch (PackageManager.NameNotFoundException e) {
242+ EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no permission");
243+ Log.w(TAG, "Cannot find the UID, calling package: " + callingPackage, e);
244+ }
245+ return false;
246+ }
200247 }
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
@@ -16,17 +16,31 @@
1616
1717 package com.android.settings.wifi;
1818
19+import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
20+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
21+
22+import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
23+import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED;
24+import static com.android.settings.wifi.WifiDialogActivity.RESULT_OK;
25+
1926 import static com.google.common.truth.Truth.assertThat;
2027
28+import static org.mockito.ArgumentMatchers.any;
2129 import static org.mockito.Mockito.doReturn;
30+import static org.mockito.Mockito.spy;
31+import static org.mockito.Mockito.verify;
32+import static org.mockito.Mockito.when;
2233
2334 import android.content.Intent;
35+import android.content.pm.PackageManager;
2436 import android.net.wifi.WifiConfiguration;
37+import android.net.wifi.WifiManager;
2538
2639 import com.android.settings.R;
2740 import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
2841 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
2942 import com.android.settings.testutils.shadow.ShadowWifiManager;
43+import com.android.settingslib.wifi.AccessPoint;
3044
3145 import com.google.android.setupcompat.util.WizardManagerHelper;
3246
@@ -48,13 +62,30 @@ import org.robolectric.util.ReflectionHelpers;
4862 })
4963 public class WifiDialogActivityTest {
5064
65+ private static final String CALLING_PACKAGE = "calling_package";
5166 private static final String AP1_SSID = "\"ap1\"";
67+
68+ @Mock
69+ PackageManager mPackageManager;
70+ @Mock
71+ WifiManager mWifiManager;
72+ @Mock
73+ WifiDialog mWifiDialog;
74+ @Mock
75+ WifiConfiguration mWifiConfiguration;
76+ @Mock
77+ AccessPoint mAccessPoint;
78+ @Mock
79+ Intent mResultData;
5280 @Mock
5381 private WifiConfigController mController;
5482
5583 @Before
5684 public void setUp() {
5785 MockitoAnnotations.initMocks(this);
86+ when(mWifiDialog.getController()).thenReturn(mController);
87+ when(mController.getConfig()).thenReturn(mWifiConfiguration);
88+ when(mController.getAccessPoint()).thenReturn(mAccessPoint);
5889
5990 WifiConfiguration wifiConfig = new WifiConfiguration();
6091 wifiConfig.SSID = AP1_SSID;
@@ -75,6 +106,29 @@ public class WifiDialogActivityTest {
75106 }
76107
77108 @Test
109+ public void onSubmit_noPermissionForResult_setResultWithoutData() {
110+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
111+ when(activity.hasPermissionForResult()).thenReturn(false);
112+ when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
113+
114+ activity.onSubmit(mWifiDialog);
115+
116+ verify(activity).setResult(RESULT_CONNECTED, null);
117+ }
118+
119+ @Test
120+ public void onSubmit_hasPermissionForResult_setResultWithData() {
121+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
122+ when(activity.hasPermissionForResult()).thenReturn(true);
123+ when(activity.createResultData(any(), any())).thenReturn(mResultData);
124+ when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
125+
126+ activity.onSubmit(mWifiDialog);
127+
128+ verify(activity).setResult(RESULT_CONNECTED, mResultData);
129+ }
130+
131+ @Test
78132 public void onSubmit_whenConnectForCallerIsFalse_shouldNotConnectToNetwork() {
79133 WifiDialogActivity activity =
80134 Robolectric.buildActivity(
@@ -111,4 +165,97 @@ public class WifiDialogActivityTest {
111165 assertThat(dialog.getContext().getThemeResId())
112166 .isEqualTo(R.style.SuwAlertDialogThemeCompat_Light);
113167 }
168+
169+ @Test
170+ public void onActivityResult_noPermissionForResult_setResultWithoutData() {
171+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
172+ when(activity.hasPermissionForResult()).thenReturn(false);
173+ final Intent data = new Intent();
174+
175+ activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
176+ data);
177+
178+ verify(activity).setResult(RESULT_CONNECTED);
179+ }
180+
181+ @Test
182+ public void onActivityResult_hasPermissionForResult_setResultWithData() {
183+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
184+ when(activity.hasPermissionForResult()).thenReturn(true);
185+ final Intent data = new Intent();
186+
187+ activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
188+ data);
189+
190+ verify(activity).setResult(RESULT_CONNECTED, data);
191+ }
192+
193+ @Test
194+ public void hasPermissionForResult_noCallingPackage_returnFalse() {
195+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
196+ when(activity.getCallingPackage()).thenReturn(null);
197+
198+ final boolean result = activity.hasPermissionForResult();
199+
200+ assertThat(result).isFalse();
201+ }
202+
203+ @Test
204+ public void hasPermissionForResult_noPermission_returnFalse() {
205+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
206+ when(activity.getCallingPackage()).thenReturn(null);
207+ when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
208+ .thenReturn(PackageManager.PERMISSION_DENIED);
209+ when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
210+ .thenReturn(PackageManager.PERMISSION_DENIED);
211+
212+ final boolean result = activity.hasPermissionForResult();
213+
214+ assertThat(result).isFalse();
215+ }
216+
217+ @Test
218+ public void hasPermissionForResult_hasCoarseLocationPermission_returnTrue() {
219+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
220+ when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
221+ when(activity.getPackageManager()).thenReturn(mPackageManager);
222+ when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
223+ .thenReturn(PackageManager.PERMISSION_GRANTED);
224+ when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
225+ .thenReturn(PackageManager.PERMISSION_DENIED);
226+
227+ final boolean result = activity.hasPermissionForResult();
228+
229+ assertThat(result).isTrue();
230+ }
231+
232+ @Test
233+ public void hasPermissionForResult_hasFineLocationPermission_returnTrue() {
234+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
235+ when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
236+ when(activity.getPackageManager()).thenReturn(mPackageManager);
237+ when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
238+ .thenReturn(PackageManager.PERMISSION_DENIED);
239+ when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
240+ .thenReturn(PackageManager.PERMISSION_GRANTED);
241+
242+ final boolean result = activity.hasPermissionForResult();
243+
244+ assertThat(result).isTrue();
245+ }
246+
247+ @Test
248+ public void hasPermissionForResult_haveBothLocationPermissions_returnTrue() {
249+ WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
250+ when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
251+ when(activity.getPackageManager()).thenReturn(mPackageManager);
252+ when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
253+ .thenReturn(PackageManager.PERMISSION_GRANTED);
254+ when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
255+ .thenReturn(PackageManager.PERMISSION_GRANTED);
256+
257+ final boolean result = activity.hasPermissionForResult();
258+
259+ assertThat(result).isTrue();
260+ }
114261 }