Merge "Add Xiaozhen Lin and George Chan to OWNERS"
diff --git a/apct-tests/perftests/OWNERS b/apct-tests/perftests/OWNERS
index 7e7feaf..4c57e64 100644
--- a/apct-tests/perftests/OWNERS
+++ b/apct-tests/perftests/OWNERS
@@ -4,6 +4,7 @@
 dualli@google.com
 edgararriaga@google.com
 jpakaravoor@google.com
+jreck@google.com #{LAST_RESORT_SUGGESTION}
 kevinjeon@google.com
 philipcuadra@google.com
 shombert@google.com
diff --git a/apct-tests/perftests/core/OWNERS b/apct-tests/perftests/core/OWNERS
index 2b3564e..8fb057d 100644
--- a/apct-tests/perftests/core/OWNERS
+++ b/apct-tests/perftests/core/OWNERS
@@ -1,3 +1,4 @@
+include /graphics/java/android/graphics/OWNERS
 include /graphics/java/android/graphics/fonts/OWNERS
 
 # Bug component: 568761
diff --git a/cmds/idmap2/include/idmap2/SysTrace.h b/cmds/idmap2/include/idmap2/SysTrace.h
index 19b4353..fcadf96 100644
--- a/cmds/idmap2/include/idmap2/SysTrace.h
+++ b/cmds/idmap2/include/idmap2/SysTrace.h
@@ -17,8 +17,6 @@
 #ifndef IDMAP2_INCLUDE_IDMAP2_SYSTRACE_H_
 #define IDMAP2_INCLUDE_IDMAP2_SYSTRACE_H_
 
-#define ATRACE_TAG ATRACE_TAG_RRO
-
 #include <sstream>
 #include <vector>
 
@@ -29,16 +27,12 @@
 
 class ScopedTraceNoStart {
  public:
-  ~ScopedTraceNoStart() {
-    ATRACE_END();
-  }
+  ~ScopedTraceNoStart();
 };
 
 class ScopedTraceMessageHelper {
  public:
-  ~ScopedTraceMessageHelper() {
-    ATRACE_BEGIN(buffer_.str().c_str());
-  }
+  ~ScopedTraceMessageHelper();
 
   std::ostream& stream() {
     return buffer_;
@@ -48,9 +42,12 @@
   std::ostringstream buffer_;
 };
 
+bool atrace_enabled();
+
 #define SYSTRACE                                               \
   android::idmap2::utils::ScopedTraceNoStart _trace##__LINE__; \
-  (ATRACE_ENABLED()) && android::idmap2::utils::ScopedTraceMessageHelper().stream()
+  android::idmap2::utils::atrace_enabled() \
+  && android::idmap2::utils::ScopedTraceMessageHelper().stream()
 
 #else
 
diff --git a/cmds/idmap2/libidmap2/SysTrace.cpp b/cmds/idmap2/libidmap2/SysTrace.cpp
new file mode 100644
index 0000000..55d45b7
--- /dev/null
+++ b/cmds/idmap2/libidmap2/SysTrace.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define ATRACE_TAG ATRACE_TAG_RRO
+
+#include "idmap2/SysTrace.h"
+
+#ifdef __ANDROID__
+namespace android::idmap2::utils {
+
+ScopedTraceNoStart::~ScopedTraceNoStart() {
+    ATRACE_END();
+};
+
+ScopedTraceMessageHelper::~ScopedTraceMessageHelper() {
+    ATRACE_BEGIN(buffer_.str().c_str());
+}
+
+bool atrace_enabled() {
+    return ATRACE_ENABLED();
+}
+}  // namespace android::idmap2::utils
+#endif
diff --git a/cmds/screencap/OWNERS b/cmds/screencap/OWNERS
new file mode 100644
index 0000000..89f1177
--- /dev/null
+++ b/cmds/screencap/OWNERS
@@ -0,0 +1,2 @@
+include /graphics/java/android/graphics/OWNERS
+include /services/core/java/com/android/server/wm/OWNERS
diff --git a/core/java/android/app/TEST_MAPPING b/core/java/android/app/TEST_MAPPING
index 32207af..a2e4239 100644
--- a/core/java/android/app/TEST_MAPPING
+++ b/core/java/android/app/TEST_MAPPING
@@ -121,6 +121,9 @@
                     "include-annotation": "android.platform.test.annotations.Presubmit"
                 },
                 {
+                    "exclude-annotation": "android.platform.test.annotations.LargeTest"
+                },
+                {
                     "exclude-annotation": "androidx.test.filters.FlakyTest"
                 },
                 {
diff --git a/core/java/android/content/TEST_MAPPING b/core/java/android/content/TEST_MAPPING
index 5bb845d..dac79e7 100644
--- a/core/java/android/content/TEST_MAPPING
+++ b/core/java/android/content/TEST_MAPPING
@@ -7,6 +7,9 @@
           "include-annotation": "android.platform.test.annotations.Presubmit"
         },
         {
+          "exclude-annotation": "android.platform.test.annotations.LargeTest"
+        },
+        {
           "exclude-annotation": "androidx.test.filters.FlakyTest"
         },
         {
diff --git a/core/java/android/credentials/OWNERS b/core/java/android/credentials/OWNERS
new file mode 100644
index 0000000..e8f393e
--- /dev/null
+++ b/core/java/android/credentials/OWNERS
@@ -0,0 +1,5 @@
+reemabajwa@google.com
+helenqin@google.com
+sgjerry@google.com
+leecam@google.com
+akaphle@google.com
diff --git a/core/java/android/service/credentials/OWNERS b/core/java/android/service/credentials/OWNERS
new file mode 100644
index 0000000..f3b43c1
--- /dev/null
+++ b/core/java/android/service/credentials/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/credentials/OWNERS
diff --git a/core/java/android/view/TEST_MAPPING b/core/java/android/view/TEST_MAPPING
index 50d69f7..ecb98f9 100644
--- a/core/java/android/view/TEST_MAPPING
+++ b/core/java/android/view/TEST_MAPPING
@@ -10,6 +10,9 @@
           "include-annotation": "android.platform.test.annotations.Presubmit"
         },
         {
+          "exclude-annotation": "android.platform.test.annotations.LargeTest"
+        },
+        {
           "exclude-annotation": "androidx.test.filters.FlakyTest"
         },
         {
diff --git a/packages/SystemUI/OWNERS b/packages/SystemUI/OWNERS
index 7076ad9..9ef772e 100644
--- a/packages/SystemUI/OWNERS
+++ b/packages/SystemUI/OWNERS
@@ -13,7 +13,7 @@
 brockman@google.com
 brzezinski@google.com
 brycelee@google.com
-ccassidy@google.com
+caitlinshk@google.com
 chrisgollner@google.com
 dupin@google.com
 ethibodeau@google.com
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index b4e91b5..9cb1f1d 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -756,6 +756,8 @@
             int errorCode, @NonNull final String packageName, @Nullable final String sessionKey,
             @NonNull final VpnProfileState profileState, @Nullable final Network underlyingNetwork,
             @Nullable final NetworkCapabilities nc, @Nullable final LinkProperties lp) {
+        // Add log for debugging flaky test. b/242833779
+        Log.d(TAG, "buildVpnManagerEventIntent: sessionKey = " + sessionKey);
         final Intent intent = new Intent(VpnManager.ACTION_VPN_MANAGER_EVENT);
         intent.setPackage(packageName);
         intent.addCategory(category);
@@ -1196,25 +1198,7 @@
                 mContext.unbindService(mConnection);
                 cleanupVpnStateLocked();
             } else if (mVpnRunner != null) {
-                // Build intent first because the sessionKey will be reset after performing
-                // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in
-                // VpnRunner.exit() to prevent design being changed in the future.
-                // TODO(b/230548427): Remove SDK check once VPN related stuff are decoupled from
-                //  ConnectivityServiceTest.
-                final int ownerUid = mOwnerUID;
-                Intent intent = null;
-                if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
-                    intent = buildVpnManagerEventIntent(
-                            VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
-                            -1 /* errorClass */, -1 /* errorCode*/, mPackage,
-                            getSessionKeyLocked(), makeVpnProfileStateLocked(),
-                            null /* underlyingNetwork */, null /* nc */, null /* lp */);
-                }
-                // cleanupVpnStateLocked() is called from mVpnRunner.exit()
-                mVpnRunner.exit();
-                if (intent != null && isVpnApp(mPackage)) {
-                    notifyVpnManagerVpnStopped(mPackage, ownerUid, intent);
-                }
+                stopVpnRunnerAndNotifyAppLocked(mPackage);
             }
 
             try {
@@ -2774,6 +2758,8 @@
             mIpSecManager = (IpSecManager) mContext.getSystemService(Context.IPSEC_SERVICE);
             mNetworkCallback = new VpnIkev2Utils.Ikev2VpnNetworkCallback(TAG, this, mExecutor);
             mSessionKey = UUID.randomUUID().toString();
+            // Add log for debugging flaky test. b/242833779
+            Log.d(TAG, "Generate session key = " + mSessionKey);
 
             // Set the policy so that cancelled tasks will be removed from the work queue
             mExecutor.setRemoveOnCancelPolicy(true);
@@ -3966,7 +3952,13 @@
     @GuardedBy("this")
     @Nullable
     private String getSessionKeyLocked() {
-        return isIkev2VpnRunner() ? ((IkeV2VpnRunner) mVpnRunner).mSessionKey : null;
+        // Add log for debugging flaky test. b/242833779
+        final boolean isIkev2VpnRunner = isIkev2VpnRunner();
+        final String sessionKey =
+                isIkev2VpnRunner ? ((IkeV2VpnRunner) mVpnRunner).mSessionKey : null;
+        Log.d(TAG, "getSessionKeyLocked: isIkev2VpnRunner = " + isIkev2VpnRunner
+                + ", sessionKey = " + sessionKey);
+        return sessionKey;
     }
 
     /**
@@ -4068,6 +4060,29 @@
         }
     }
 
+    @GuardedBy("this")
+    private void stopVpnRunnerAndNotifyAppLocked(@NonNull String packageName) {
+        // Build intent first because the sessionKey will be reset after performing
+        // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in
+        // VpnRunner.exit() to prevent design being changed in the future.
+        // TODO(b/230548427): Remove SDK check once VPN related stuff are decoupled from
+        //  ConnectivityServiceTest.
+        final int ownerUid = mOwnerUID;
+        Intent intent = null;
+        if (SdkLevel.isAtLeastT() && isVpnApp(packageName)) {
+            intent = buildVpnManagerEventIntent(
+                    VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
+                    -1 /* errorClass */, -1 /* errorCode*/, packageName,
+                    getSessionKeyLocked(), makeVpnProfileStateLocked(),
+                    null /* underlyingNetwork */, null /* nc */, null /* lp */);
+        }
+        // cleanupVpnStateLocked() is called from mVpnRunner.exit()
+        mVpnRunner.exit();
+        if (intent != null && isVpnApp(packageName)) {
+            notifyVpnManagerVpnStopped(packageName, ownerUid, intent);
+        }
+    }
+
     /**
      * Stops an already running VPN Profile for the given package.
      *
@@ -4084,18 +4099,7 @@
         // To stop the VPN profile, the caller must be the current prepared package and must be
         // running an Ikev2VpnProfile.
         if (isCurrentIkev2VpnLocked(packageName)) {
-            // Build intent first because the sessionKey will be reset after performing
-            // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in
-            // VpnRunner.exit() to prevent design being changed in the future.
-            final int ownerUid = mOwnerUID;
-            final Intent intent = buildVpnManagerEventIntent(
-                    VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
-                    -1 /* errorClass */, -1 /* errorCode*/, packageName,
-                    getSessionKeyLocked(), makeVpnProfileStateLocked(),
-                    null /* underlyingNetwork */, null /* nc */, null /* lp */);
-
-            mVpnRunner.exit();
-            notifyVpnManagerVpnStopped(packageName, ownerUid, intent);
+            stopVpnRunnerAndNotifyAppLocked(packageName);
         }
     }
 
diff --git a/services/credentials/OWNERS b/services/credentials/OWNERS
new file mode 100644
index 0000000..f3b43c1
--- /dev/null
+++ b/services/credentials/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/credentials/OWNERS
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 70f1639..5ed6cb9 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -139,24 +139,19 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
     public static final Uri CONTENT_URI = SimInfo.CONTENT_URI;
 
-    /** @hide */
-    public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY =
+    private static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY =
             "cache_key.telephony.get_default_sub_id";
 
-    /** @hide */
-    public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY =
+    private static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY =
             "cache_key.telephony.get_default_data_sub_id";
 
-    /** @hide */
-    public static final String CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY =
+    private static final String CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY =
             "cache_key.telephony.get_default_sms_sub_id";
 
-    /** @hide */
-    public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY =
+    private static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY =
             "cache_key.telephony.get_active_data_sub_id";
 
-    /** @hide */
-    public static final String CACHE_KEY_SLOT_INDEX_PROPERTY =
+    private static final String CACHE_KEY_SLOT_INDEX_PROPERTY =
             "cache_key.telephony.get_slot_index";
 
     /** @hide */