Merge changes from topic "sc-dev_WifiDialogActivity_permission-sc-qpr1-dev-sc-v2-dev" into sc-v2-dev

* changes:
  [RESTRICT AUTOMERGE] Revert "Add permission checking to WifiDialogActivity"
  [RESTRICT AUTOMERGE] Revert "Add SafetyNet logging"
This commit is contained in:
Weng Su
2021-10-06 18:48:54 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 232 deletions

View File

@@ -16,12 +16,8 @@
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;
@@ -33,7 +29,6 @@ import android.os.Process;
import android.os.SimpleClock;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -83,12 +78,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
@VisibleForTesting
static final int RESULT_CONNECTED = RESULT_FIRST_USER;
private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
@VisibleForTesting
static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
private 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;
@@ -263,7 +256,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
}
}
Intent resultData = hasPermissionForResult() ? createResultData(config, null) : null;
final Intent resultData = new Intent();
if (config != null) {
resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
}
setResult(RESULT_CONNECTED, resultData);
finish();
}
@@ -291,22 +287,17 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
}
}
Intent resultData = hasPermissionForResult() ? createResultData(config, accessPoint) : null;
setResult(RESULT_CONNECTED, resultData);
finish();
}
protected Intent createResultData(WifiConfiguration config, AccessPoint accessPoint) {
Intent result = new Intent();
Intent resultData = new Intent();
if (accessPoint != null) {
Bundle accessPointState = new Bundle();
accessPoint.saveWifiState(accessPointState);
result.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
}
if (config != null) {
result.putExtra(KEY_WIFI_CONFIGURATION, config);
resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
}
return result;
setResult(RESULT_CONNECTED, resultData);
finish();
}
@Override
@@ -342,44 +333,9 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
if (resultCode != RESULT_OK) {
return;
}
if (hasPermissionForResult()) {
setResult(RESULT_CONNECTED, data);
} else {
setResult(RESULT_CONNECTED);
}
setResult(RESULT_CONNECTED, data);
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.");
EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no calling package");
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.");
try {
EventLog.writeEvent(0x534e4554, "185126813",
getPackageManager().getPackageUid(callingPackage, 0 /* flags */),
"no permission");
} catch (PackageManager.NameNotFoundException e) {
EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no permission");
Log.w(TAG, "Cannot find the UID, calling package: " + callingPackage, e);
}
return false;
}
}