diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-05-14 21:57:23 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-05-14 21:57:23 +0000 |
commit | f58e054a98e88f8829effd72b954826866abe8a9 (patch) | |
tree | ab81fb1d39ca21f321f08bb4fc587272fabe4acb | |
parent | ea1b439cba8fa45473c84c7ced2072200a47940c (diff) | |
parent | 4d8f28e9f4e2dc64d119c0fb0d6d2596875ae018 (diff) | |
download | base-f58e054a98e88f8829effd72b954826866abe8a9.tar.gz |
Merge cherrypicks of [14554374, 14554375, 14554376, 14554377, 14554421, 14554378, 14554522, 14554523, 14554381, 14554563, 14554564, 14554566, 14554568, 14554570, 14554571, 14554573, 14554526, 14554576] into security-aosp-oc-mr1-releaseandroid-security-8.1.0_r91android-security-8.1.0_r90
Change-Id: I0e31b90f001d9959d05757095b9dc3a778f0c7f3
4 files changed, 46 insertions, 146 deletions
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 3081244ec511..a8d1353bc1c1 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -852,27 +852,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } /** - * Detects whether we should show a lock screen in front of this task for a locked user. - * <p> - * We'll do this if either of the following holds: - * <ul> - * <li>The top activity explicitly belongs to {@param userId}.</li> - * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> - * </ul> - * - * @return {@code true} if the top activity looks like it belongs to {@param userId}. - */ - private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { - // To handle the case that work app is in the task but just is not the top one. - final ActivityRecord activityRecord = task.getTopActivity(); - final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); - - return (activityRecord != null && activityRecord.userId == userId) - || (resultTo != null && resultTo.userId == userId); - } - - /** - * Find all visible task stacks containing {@param userId} and intercept them with an activity + * Find all task stacks containing {@param userId} and intercept them with an activity * to block out the contents and possibly start a credential-confirming intent. * * @param userId user handle for the locked managed profile. @@ -885,13 +865,14 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D final List<TaskRecord> tasks = stacks.get(stackNdx).getAllTasks(); for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { final TaskRecord task = tasks.get(taskNdx); - - // Check the task for a top activity belonging to userId, or returning a result - // to an activity belonging to userId. Example case: a document picker for - // personal files, opened by a work app, should still get locked. - if (taskTopActivityIsUser(task, userId)) { - mService.mTaskChangeNotificationController.notifyTaskProfileLocked( - task.taskId, userId); + for (int activityNdx = task.mActivities.size() - 1; activityNdx >= 0; + activityNdx--) { + final ActivityRecord activity = task.mActivities.get(activityNdx); + if (!activity.finishing && activity.userId == userId) { + mService.mTaskChangeNotificationController.notifyTaskProfileLocked( + task.taskId, userId); + break; + } } } } diff --git a/services/core/java/com/android/server/connectivity/NetworkMonitor.java b/services/core/java/com/android/server/connectivity/NetworkMonitor.java index d3a93542c740..bc7c30017a63 100644 --- a/services/core/java/com/android/server/connectivity/NetworkMonitor.java +++ b/services/core/java/com/android/server/connectivity/NetworkMonitor.java @@ -38,22 +38,12 @@ import android.net.metrics.IpConnectivityLog; import android.net.metrics.NetworkEvent; import android.net.metrics.ValidationProbeEvent; import android.net.util.Stopwatch; -import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; -import android.telephony.CellIdentityCdma; -import android.telephony.CellIdentityGsm; -import android.telephony.CellIdentityLte; -import android.telephony.CellIdentityWcdma; -import android.telephony.CellInfo; -import android.telephony.CellInfoCdma; -import android.telephony.CellInfoGsm; -import android.telephony.CellInfoLte; -import android.telephony.CellInfoWcdma; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.LocalLog; @@ -122,22 +112,6 @@ public class NetworkMonitor extends StateMachine { } } - public static final String ACTION_NETWORK_CONDITIONS_MEASURED = - "android.net.conn.NETWORK_CONDITIONS_MEASURED"; - public static final String EXTRA_CONNECTIVITY_TYPE = "extra_connectivity_type"; - public static final String EXTRA_NETWORK_TYPE = "extra_network_type"; - public static final String EXTRA_RESPONSE_RECEIVED = "extra_response_received"; - public static final String EXTRA_IS_CAPTIVE_PORTAL = "extra_is_captive_portal"; - public static final String EXTRA_CELL_ID = "extra_cellid"; - public static final String EXTRA_SSID = "extra_ssid"; - public static final String EXTRA_BSSID = "extra_bssid"; - /** real time since boot */ - public static final String EXTRA_REQUEST_TIMESTAMP_MS = "extra_request_timestamp_ms"; - public static final String EXTRA_RESPONSE_TIMESTAMP_MS = "extra_response_timestamp_ms"; - - private static final String PERMISSION_ACCESS_NETWORK_CONDITIONS = - "android.permission.ACCESS_NETWORK_CONDITIONS"; - // After a network has been tested this result can be sent with EVENT_NETWORK_TESTED. // The network should be used as a default internet connection. It was found to be: // 1. a functioning network providing internet access, or @@ -804,10 +778,6 @@ public class NetworkMonitor extends StateMachine { long endTime = SystemClock.elapsedRealtime(); - sendNetworkConditionsBroadcast(true /* response received */, - result.isPortal() /* isCaptivePortal */, - startTime, endTime); - return result; } @@ -1026,88 +996,6 @@ public class NetworkMonitor extends StateMachine { return null; } - /** - * @param responseReceived - whether or not we received a valid HTTP response to our request. - * If false, isCaptivePortal and responseTimestampMs are ignored - * TODO: This should be moved to the transports. The latency could be passed to the transports - * along with the captive portal result. Currently the TYPE_MOBILE broadcasts appear unused so - * perhaps this could just be added to the WiFi transport only. - */ - private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, - long requestTimestampMs, long responseTimestampMs) { - if (Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) { - return; - } - - if (systemReady == false) return; - - Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED); - switch (mNetworkAgentInfo.networkInfo.getType()) { - case ConnectivityManager.TYPE_WIFI: - WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo(); - if (currentWifiInfo != null) { - // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not - // surrounded by double quotation marks (thus violating the Javadoc), but this - // was changed to match the Javadoc in API 17. Since clients may have started - // sanitizing the output of this method since API 17 was released, we should - // not change it here as it would become impossible to tell whether the SSID is - // simply being surrounded by quotes due to the API, or whether those quotes - // are actually part of the SSID. - latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID()); - latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID()); - } else { - if (VDBG) logw("network info is TYPE_WIFI but no ConnectionInfo found"); - return; - } - break; - case ConnectivityManager.TYPE_MOBILE: - latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType()); - List<CellInfo> info = mTelephonyManager.getAllCellInfo(); - if (info == null) return; - int numRegisteredCellInfo = 0; - for (CellInfo cellInfo : info) { - if (cellInfo.isRegistered()) { - numRegisteredCellInfo++; - if (numRegisteredCellInfo > 1) { - if (VDBG) logw("more than one registered CellInfo." + - " Can't tell which is active. Bailing."); - return; - } - if (cellInfo instanceof CellInfoCdma) { - CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity(); - latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId); - } else if (cellInfo instanceof CellInfoGsm) { - CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity(); - latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId); - } else if (cellInfo instanceof CellInfoLte) { - CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity(); - latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId); - } else if (cellInfo instanceof CellInfoWcdma) { - CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity(); - latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId); - } else { - if (VDBG) logw("Registered cellinfo is unrecognized"); - return; - } - } - } - break; - default: - return; - } - latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType()); - latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived); - latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs); - - if (responseReceived) { - latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal); - latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs); - } - mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, - PERMISSION_ACCESS_NETWORK_CONDITIONS); - } - private void logNetworkEvent(int evtype) { mMetricsLog.log(new NetworkEvent(mNetId, evtype)); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 39cb2e079db2..a17f562e0889 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -4036,6 +4036,7 @@ public class NotificationManagerService extends SystemService { final PendingIntent pi = PendingIntent.getBroadcast(getContext(), REQUEST_CODE_TIMEOUT, new Intent(ACTION_NOTIFICATION_TIMEOUT) + .setPackage("android") .setData(new Uri.Builder().scheme(SCHEME_TIMEOUT) .appendPath(record.getKey()).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND) diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java index 661dd4fc828c..986037ed0c8a 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java @@ -18,25 +18,26 @@ package com.android.server.am; import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; import static android.app.ActivityManager.StackId.PINNED_STACK_ID; + +import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; import android.content.ComponentName; import android.graphics.Rect; +import android.os.RemoteException; +import android.os.UserHandle; import android.platform.test.annotations.Presubmit; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; -import org.junit.runner.RunWith; import org.junit.Test; +import org.junit.runner.RunWith; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; /** * Tests for the {@link ActivityStackSupervisor} class. @@ -135,4 +136,33 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { assertFalse(service.mStackSupervisor.mStoppingActivities.contains(firstActivity)); } + + @Test + public void testLockAllProfileTasks() throws Exception { + // Make an activity visible with the user id set to 1 + final ActivityManagerService service = createActivityManagerService(); + final TaskRecord task = createTask(service, testActivityComponent, + FULLSCREEN_WORKSPACE_STACK_ID); + final ActivityRecord activity = createActivity(service, testActivityComponent, task, 1); + + // Create another activity on top and the user id is 2 + final ActivityRecord topActivity = createActivity(service, testActivityComponent, task, 2); + + // Make sure the listeners will be notified for putting the task to locked state + LocalTaskStackListener listener = new LocalTaskStackListener(); + service.registerTaskStackListener(listener); + service.mStackSupervisor.lockAllProfileTasks(1); + assertTrue(listener.mTaskProfileLocked); + service.unregisterTaskStackListener(listener); + } + + private class LocalTaskStackListener extends android.app.TaskStackListener { + boolean mTaskProfileLocked; + + @Override + public void onTaskProfileLocked(int taskId, int userId) { + super.onTaskProfileLocked(taskId, userId); + mTaskProfileLocked = true; + } + } } |