Add permission checking to WifiDialogActivity
- Use getCallingPackage() to get calling package. - Check if the calling package has ACCESS_COARSE_LOCATION or ACCESS_COARSE_LOCATION permission. - Only set result data to permission granted callers Bug: 185126813 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiDialogActivityTest Change-Id: If7ca069c842ed2bd1aed23f9d4041473c68a4dad
This commit is contained in:
@@ -16,8 +16,12 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -78,10 +82,12 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
|
||||
public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
|
||||
|
||||
private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
|
||||
@VisibleForTesting
|
||||
static final int RESULT_CONNECTED = RESULT_FIRST_USER;
|
||||
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
|
||||
|
||||
private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
|
||||
@VisibleForTesting
|
||||
static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
|
||||
|
||||
// Max age of tracked WifiEntries.
|
||||
private static final long MAX_SCAN_AGE_MILLIS = 15_000;
|
||||
@@ -258,10 +264,7 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
}
|
||||
|
||||
final Intent resultData = new Intent();
|
||||
if (config != null) {
|
||||
resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
|
||||
}
|
||||
Intent resultData = hasPermissionForResult() ? createResultData(config, null) : null;
|
||||
setResult(RESULT_CONNECTED, resultData);
|
||||
finish();
|
||||
}
|
||||
@@ -289,17 +292,22 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
}
|
||||
|
||||
Intent resultData = new Intent();
|
||||
Intent resultData = hasPermissionForResult() ? createResultData(config, accessPoint) : null;
|
||||
setResult(RESULT_CONNECTED, resultData);
|
||||
finish();
|
||||
}
|
||||
|
||||
protected Intent createResultData(WifiConfiguration config, AccessPoint accessPoint) {
|
||||
Intent result = new Intent();
|
||||
if (accessPoint != null) {
|
||||
Bundle accessPointState = new Bundle();
|
||||
accessPoint.saveWifiState(accessPointState);
|
||||
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
|
||||
result.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
|
||||
}
|
||||
if (config != null) {
|
||||
resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
|
||||
result.putExtra(KEY_WIFI_CONFIGURATION, config);
|
||||
}
|
||||
setResult(RESULT_CONNECTED, resultData);
|
||||
finish();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,9 +343,35 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
if (resultCode != RESULT_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
setResult(RESULT_CONNECTED, data);
|
||||
if (hasPermissionForResult()) {
|
||||
setResult(RESULT_CONNECTED, data);
|
||||
} else {
|
||||
setResult(RESULT_CONNECTED);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasPermissionForResult() {
|
||||
final String callingPackage = getCallingPackage();
|
||||
if (callingPackage == null) {
|
||||
Log.d(TAG, "Failed to get the calling package, don't return the result.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getPackageManager().checkPermission(ACCESS_COARSE_LOCATION, callingPackage)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(TAG, "The calling package has ACCESS_COARSE_LOCATION permission for result.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getPackageManager().checkPermission(ACCESS_FINE_LOCATION, callingPackage)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(TAG, "The calling package has ACCESS_FINE_LOCATION permission for result.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.d(TAG, "The calling package does not have the necessary permissions for result.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user