Fixed SimpleIntentReceiverActivity.

It was crashing in some builds because Context.getuserId() was
throwing NoSuchMethodError.

Fixes: 183232033
Bug: 183427655

Test: m -j CtsIntentReceiverApp && adb install -t --user all $OUT/testcases/CtsIntentReceiverApp/*/CtsIntentReceiverApp.apk && adb shell am start com.android.cts.intent.receiver/.SimpleIntentReceiverActivity
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSuspendPackage,testSuspendPackageWithPackageManager com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testSuspendPackage,testSuspendPackageWithPackageManager com.android.cts.devicepolicy.MixedProfileOwnerTest#testSuspendPackage,testSuspendPackageWithPackageManager

Change-Id: I96850cb542cf8107a4788584742610401431c6ff
diff --git a/hostsidetests/devicepolicy/app/IntentReceiver/src/com/android/cts/intent/receiver/SimpleIntentReceiverActivity.java b/hostsidetests/devicepolicy/app/IntentReceiver/src/com/android/cts/intent/receiver/SimpleIntentReceiverActivity.java
index 045ba88..6fe23d2 100644
--- a/hostsidetests/devicepolicy/app/IntentReceiver/src/com/android/cts/intent/receiver/SimpleIntentReceiverActivity.java
+++ b/hostsidetests/devicepolicy/app/IntentReceiver/src/com/android/cts/intent/receiver/SimpleIntentReceiverActivity.java
@@ -28,7 +28,7 @@
  * running in a managed profile.
  */
 public class SimpleIntentReceiverActivity extends Activity {
-    private static final String TAG = "SimpleIntentReceiverActivity";
+    private static final String TAG = SimpleIntentReceiverActivity.class.getSimpleName();
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -41,8 +41,14 @@
                 (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
         boolean inManagedProfile = dpm.isProfileOwnerApp("com.android.cts.managedprofile");
 
-        Log.i(TAG, "activity " + className + " started on user " + getUserId()
-                + ", is in managed profile: " + inManagedProfile);
+        try {
+            Log.i(TAG, "activity " + className + " started on user " + getUserId()
+                    + ", is in managed profile: " + inManagedProfile);
+        } catch (NoSuchMethodError e) {
+            // TODO(b/183427655): figure out why it's failing...
+            Log.i(TAG, "activity " + className + ", is in managed profile: " + inManagedProfile
+                    + " (could not infer user id: " + e + ")");
+        }
         Intent result = new Intent();
         result.putExtra("extra_receiver_class", className);
         result.putExtra("extra_in_managed_profile", inManagedProfile);
diff --git a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/IntentSenderActivity.java b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/IntentSenderActivity.java
index b55437c..935090f 100644
--- a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/IntentSenderActivity.java
+++ b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/IntentSenderActivity.java
@@ -32,7 +32,7 @@
 
 public class IntentSenderActivity extends Activity {
 
-    private static String TAG = "IntentSenderActivity";
+    private static final String TAG = IntentSenderActivity.class.getSimpleName();
 
     private final SynchronousQueue<Result> mResult = new SynchronousQueue<>();
 
diff --git a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
index 991bcb3..16d4f03 100644
--- a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
+++ b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
@@ -97,19 +97,22 @@
         Intent intent = new Intent();
         intent.setClassName(INTENT_RECEIVER_PKG, TARGET_ACTIVITY_NAME);
         if (!temporarilySkipActivityLaunch()) {
-            Log.d(TAG, "assertPackageSuspended(suspended=" + suspended
-                    + ", customDialog=" + customDialog + "): getting result for activity " + intent
-                    + " on user " + mContext.getUserId());
             Intent result = mActivity.getResult(intent);
+            Log.d(TAG, "assertPackageSuspended(suspended=" + suspended
+                    + ", customDialog=" + customDialog + "): result for activity "
+                    + INTENT_RECEIVER_PKG + "/" + TARGET_ACTIVITY_NAME + " on user "
+                    + mContext.getUserId() + ": " + result);
             if (suspended) {
                 if (customDialog) {
                     dismissCustomDialog();
                 } else {
                     dismissPolicyTransparencyDialog();
                 }
-                assertWithMessage("result for activitiy %s", intent).that(result).isNull();
+                assertWithMessage("result for activitiy %s while suspended", intent).that(result)
+                        .isNull();
             } else {
-                assertWithMessage("result for activitiy %s", intent).that(result).isNotNull();
+                assertWithMessage("result for activitiy %s while NOT suspended", intent)
+                        .that(result).isNotNull();
             }
         }
         // No matter if it is suspended or not, we should be able to resolve the activity.