Check for Batteryless device and drop handhold hack

Current, the handhold check is used to see if device should report of
battery presence.
But this check is not reliable since there is no real handhold feature.
For Android system now has checking rule for batteryless device,
use the proper "battery present" intent extra from BatteryManager instead.
https://source.android.com/devices/tech/power/batteryless

Test: run cts -m CtsContentTestCases -t android.content.cts.AvailableIntentsTest#testPowerUsageSummarySettings

Bug: 173134056

Signed-off-by: TowaCJWang <TowaCJWang@fih-foxconn.com>
Change-Id: I6cd27683263dc1d093d8f11a276d388e56857dd3
diff --git a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
index 8684e84..9c19662 100644
--- a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
+++ b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
@@ -23,11 +23,13 @@
 import android.content.ContentUris;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.media.RingtoneManager;
 import android.net.Uri;
 import android.net.wifi.WifiManager;
+import android.os.BatteryManager;
 import android.os.storage.StorageManager;
 import android.platform.test.annotations.AppModeFull;
 import android.provider.AlarmClock;
@@ -420,7 +422,7 @@
     }
 
     public void testPowerUsageSummarySettings() {
-        if (isHandheld()) {
+        if (isBatteryPresent()) {
             assertCanBeHandled(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));
         }
     }
@@ -479,4 +481,10 @@
                 && !pm.hasSystemFeature(pm.FEATURE_TELEVISION)
                 && !pm.hasSystemFeature(pm.FEATURE_AUTOMOTIVE);
     }
+
+    private boolean isBatteryPresent() {
+        final Intent batteryInfo = mContext.registerReceiver(null,
+                                    new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+        return batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
+    }
 }