Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e81e3a4f authored by Martijn Coenen's avatar Martijn Coenen Committed by Android (Google) Code Review
Browse files

Merge "Added NFC disable during phone shutdown"

parents 48b6b711 3bba8d04
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ interface INfcAdapter
    INfcAdapterExtras getNfcAdapterExtrasInterface(in String pkg);

    int getState();
    boolean disable();
    boolean disable(boolean saveState);
    boolean enable();
    boolean enableNdefPush();
    boolean disableNdefPush();
+2 −1
Original line number Diff line number Diff line
@@ -574,9 +574,10 @@ public final class NfcAdapter {
     *
     * @hide
     */

    public boolean disable() {
        try {
            return sService.disable();
            return sService.disable(true);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            return false;
+31 −6
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.app.IActivityManager;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.IBluetooth;
import android.nfc.NfcAdapter;
import android.nfc.INfcAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -48,7 +50,7 @@ import android.view.WindowManager;
public final class ShutdownThread extends Thread {
    // constants
    private static final String TAG = "ShutdownThread";
    private static final int MAX_NUM_PHONE_STATE_READS = 16;
    private static final int MAX_NUM_PHONE_STATE_READS = 24;
    private static final int PHONE_STATE_POLL_SLEEP_MSEC = 500;
    // maximum time we wait for the shutdown broadcast before going on.
    private static final int MAX_BROADCAST_TIME = 10*1000;
@@ -231,6 +233,7 @@ public final class ShutdownThread extends Thread {
     * Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
     */
    public void run() {
        boolean nfcOff;
        boolean bluetoothOff;
        boolean radioOff;

@@ -284,16 +287,29 @@ public final class ShutdownThread extends Thread {
            }
        }
        
        final INfcAdapter nfc =
                INfcAdapter.Stub.asInterface(ServiceManager.checkService("nfc"));
        final ITelephony phone =
                ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
        final IBluetooth bluetooth =
                IBluetooth.Stub.asInterface(ServiceManager.checkService(
                        BluetoothAdapter.BLUETOOTH_SERVICE));

        final IMountService mount =
                IMountService.Stub.asInterface(
                        ServiceManager.checkService("mount"));

        try {
            nfcOff = nfc == null ||
                     nfc.getState() == NfcAdapter.STATE_OFF;
            if (!nfcOff) {
                Log.w(TAG, "Turning off NFC...");
                nfc.disable(false); // Don't persist new state
            }
        } catch (RemoteException ex) {
	    Log.e(TAG, "RemoteException during NFC shutdown", ex);
            nfcOff = true;
        }

        try {
            bluetoothOff = bluetooth == null ||
                           bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
@@ -317,7 +333,7 @@ public final class ShutdownThread extends Thread {
            radioOff = true;
        }

        Log.i(TAG, "Waiting for Bluetooth and Radio...");
        Log.i(TAG, "Waiting for NFC, Bluetooth and Radio...");
        
        // Wait a max of 32 seconds for clean shutdown
        for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
@@ -338,8 +354,17 @@ public final class ShutdownThread extends Thread {
                    radioOff = true;
                }
            }
            if (radioOff && bluetoothOff) {
                Log.i(TAG, "Radio and Bluetooth shutdown complete.");
            if (!nfcOff) {
                try {
                    nfcOff = nfc.getState() == NfcAdapter.STATE_OFF;
                } catch (RemoteException ex) {
                    Log.e(TAG, "RemoteException during NFC shutdown", ex);
                    nfcOff = true;
                }
            }

            if (radioOff && bluetoothOff && nfcOff) {
                Log.i(TAG, "NFC, Radio and Bluetooth shutdown complete.");
                break;
            }
            SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);