From 29131643f314a744b064b170f73f0e92ea59b693 Mon Sep 17 00:00:00 2001 From: Shuo Qian Date: Mon, 9 Dec 2019 14:04:56 -0800 Subject: [PATCH] Introduce Radio Shutdown System APIs for Mainline Test: built; cts Bug: 145554073 Change-Id: I26f01ea5f7cca88d1c3aeefae96ff3bf11b5138f --- api/system-current.txt | 2 + .../android/server/power/ShutdownThread.java | 29 +++++--------- .../android/telephony/TelephonyManager.java | 38 +++++++++++++++++++ 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 6b51eabf6f347..71b2273ad3c5f 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -9610,6 +9610,7 @@ package android.telephony { method @Nullable @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(int, @Nullable String, int); method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String iccTransmitApduBasicChannelBySlot(int, int, int, int, int, int, @Nullable String); method @Nullable @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String iccTransmitApduLogicalChannelBySlot(int, int, int, int, int, int, int, @Nullable String); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isAnyRadioPoweredOn(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isApplicationOnUicc(int); method public boolean isDataConnectivityPossible(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isDataEnabledForApn(int); @@ -9648,6 +9649,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setSimPowerStateForSlot(int, int); method @Deprecated public void setVisualVoicemailEnabled(android.telecom.PhoneAccountHandle, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setVoiceActivationState(int); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void shutdownAllRadios(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPin(String); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPuk(String, String); diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java index 6da8fb4b1edbc..cc1cddd3a1112 100644 --- a/services/core/java/com/android/server/power/ShutdownThread.java +++ b/services/core/java/com/android/server/power/ShutdownThread.java @@ -41,12 +41,12 @@ import android.os.Trace; import android.os.UserHandle; import android.os.UserManager; import android.os.Vibrator; +import android.telephony.TelephonyManager; import android.util.ArrayMap; import android.util.Log; import android.util.TimingsTraceLog; import android.view.WindowManager; -import com.android.internal.telephony.ITelephony; import com.android.server.LocalServices; import com.android.server.RescueParty; import com.android.server.pm.PackageManagerService; @@ -586,19 +586,15 @@ public final class ShutdownThread extends Thread { TimingsTraceLog shutdownTimingsTraceLog = newTimingsLog(); boolean radioOff; - final ITelephony phone = - ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); + TelephonyManager telephonyManager = mContext.getSystemService( + TelephonyManager.class); - try { - radioOff = phone == null || !phone.needMobileRadioShutdown(); - if (!radioOff) { - Log.w(TAG, "Turning off cellular radios..."); - metricStarted(METRIC_RADIO); - phone.shutdownMobileRadios(); - } - } catch (RemoteException ex) { - Log.e(TAG, "RemoteException during radio shutdown", ex); - radioOff = true; + radioOff = telephonyManager == null + || !telephonyManager.isAnyRadioPoweredOn(); + if (!radioOff) { + Log.w(TAG, "Turning off cellular radios..."); + metricStarted(METRIC_RADIO); + telephonyManager.shutdownAllRadios(); } Log.i(TAG, "Waiting for Radio..."); @@ -613,12 +609,7 @@ public final class ShutdownThread extends Thread { } if (!radioOff) { - try { - radioOff = !phone.needMobileRadioShutdown(); - } catch (RemoteException ex) { - Log.e(TAG, "RemoteException during radio shutdown", ex); - radioOff = true; - } + radioOff = !telephonyManager.isAnyRadioPoweredOn(); if (radioOff) { Log.i(TAG, "Radio turned off."); metricEnded(METRIC_RADIO); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 9f5acb3072cb5..09de9991f752e 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -8357,6 +8357,44 @@ public class TelephonyManager { return false; } + /** + * Shut down all the live radios over all the slot index. + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + public void shutdownAllRadios() { + try { + ITelephony telephony = getITelephony(); + if (telephony != null) { + telephony.shutdownMobileRadios(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelephony#shutdownMobileRadios", e); + } + } + + /** + * Check if any radio is on over all the slot indexes. + * + * @return {@code true} if any radio is on over any slot index. + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public boolean isAnyRadioPoweredOn() { + try { + ITelephony telephony = getITelephony(); + if (telephony != null) { + return telephony.needMobileRadioShutdown(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelephony#needMobileRadioShutdown", e); + } + return false; + } + /** * Radio explicitly powered off (e.g, airplane mode). * @hide