Search in sources :

Example 6 with INfcAdapter

use of android.nfc.INfcAdapter in project android_frameworks_base by crdroidandroid.

the class CameraService method notifyNfcService.

private void notifyNfcService(boolean enablePolling) {
    IBinder nfcServiceBinder = getBinderService(NFC_SERVICE_BINDER_NAME);
    if (nfcServiceBinder == null) {
        Slog.w(TAG, "Could not connect to NFC service to notify it of camera state");
        return;
    }
    INfcAdapter nfcAdapterRaw = INfcAdapter.Stub.asInterface(nfcServiceBinder);
    int flags = enablePolling ? ENABLE_POLLING_FLAGS : DISABLE_POLLING_FLAGS;
    if (DEBUG)
        Slog.v(TAG, "Setting NFC reader mode to flags " + flags);
    try {
        nfcAdapterRaw.setReaderMode(nfcInterfaceToken, null, flags, null);
    } catch (RemoteException e) {
        Slog.w(TAG, "Could not notify NFC service, remote exception: " + e);
    }
}
Also used : IBinder(android.os.IBinder) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException)

Example 7 with INfcAdapter

use of android.nfc.INfcAdapter in project android_frameworks_base by crdroidandroid.

the class ShutdownThread method shutdownRadios.

private void shutdownRadios(final int timeout) {
    // If a radio is wedged, disabling it may hang so we do this work in another thread,
    // just in case.
    final long endTime = SystemClock.elapsedRealtime() + timeout;
    final boolean[] done = new boolean[1];
    Thread t = new Thread() {

        public void run() {
            boolean nfcOff;
            boolean bluetoothOff;
            boolean radioOff;
            final INfcAdapter nfc = INfcAdapter.Stub.asInterface(ServiceManager.checkService("nfc"));
            final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
            final IBluetoothManager bluetooth = IBluetoothManager.Stub.asInterface(ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE));
            try {
                nfcOff = nfc == null || nfc.getState() == NfcAdapter.STATE_OFF;
                if (!nfcOff) {
                    Log.w(TAG, "Turning off NFC...");
                    // Don't persist new state
                    nfc.disable(false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during NFC shutdown", ex);
                nfcOff = true;
            }
            try {
                bluetoothOff = bluetooth == null || bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                if (!bluetoothOff) {
                    Log.w(TAG, "Disabling Bluetooth...");
                    // disable but don't persist new state
                    bluetooth.disable(mContext.getPackageName(), false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                bluetoothOff = true;
            }
            try {
                radioOff = phone == null || !phone.needMobileRadioShutdown();
                if (!radioOff) {
                    Log.w(TAG, "Turning off cellular radios...");
                    phone.shutdownMobileRadios();
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during radio shutdown", ex);
                radioOff = true;
            }
            Log.i(TAG, "Waiting for NFC, Bluetooth and Radio...");
            long delay = endTime - SystemClock.elapsedRealtime();
            while (delay > 0) {
                if (mRebootHasProgressBar) {
                    int status = (int) ((timeout - delay) * 1.0 * (RADIO_STOP_PERCENT - PACKAGE_MANAGER_STOP_PERCENT) / timeout);
                    status += PACKAGE_MANAGER_STOP_PERCENT;
                    sInstance.setRebootProgress(status, null);
                }
                if (!bluetoothOff) {
                    try {
                        bluetoothOff = bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                        bluetoothOff = true;
                    }
                    if (bluetoothOff) {
                        Log.i(TAG, "Bluetooth turned off.");
                    }
                }
                if (!radioOff) {
                    try {
                        radioOff = !phone.needMobileRadioShutdown();
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during radio shutdown", ex);
                        radioOff = true;
                    }
                    if (radioOff) {
                        Log.i(TAG, "Radio turned off.");
                    }
                }
                if (!nfcOff) {
                    try {
                        nfcOff = nfc.getState() == NfcAdapter.STATE_OFF;
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during NFC shutdown", ex);
                        nfcOff = true;
                    }
                    if (nfcOff) {
                        Log.i(TAG, "NFC turned off.");
                    }
                }
                if (radioOff && bluetoothOff && nfcOff) {
                    Log.i(TAG, "NFC, Radio and Bluetooth shutdown complete.");
                    done[0] = true;
                    break;
                }
                SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
                delay = endTime - SystemClock.elapsedRealtime();
            }
        }
    };
    t.start();
    try {
        t.join(timeout);
    } catch (InterruptedException ex) {
    }
    if (!done[0]) {
        Log.w(TAG, "Timed out waiting for NFC, Radio and Bluetooth shutdown.");
    }
}
Also used : IBluetoothManager(android.bluetooth.IBluetoothManager) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 8 with INfcAdapter

use of android.nfc.INfcAdapter in project platform_frameworks_base by android.

the class ShutdownThread method shutdownRadios.

private void shutdownRadios(final int timeout) {
    // If a radio is wedged, disabling it may hang so we do this work in another thread,
    // just in case.
    final long endTime = SystemClock.elapsedRealtime() + timeout;
    final boolean[] done = new boolean[1];
    Thread t = new Thread() {

        public void run() {
            boolean nfcOff;
            boolean bluetoothOff;
            boolean radioOff;
            final INfcAdapter nfc = INfcAdapter.Stub.asInterface(ServiceManager.checkService("nfc"));
            final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
            final IBluetoothManager bluetooth = IBluetoothManager.Stub.asInterface(ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE));
            try {
                nfcOff = nfc == null || nfc.getState() == NfcAdapter.STATE_OFF;
                if (!nfcOff) {
                    Log.w(TAG, "Turning off NFC...");
                    // Don't persist new state
                    nfc.disable(false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during NFC shutdown", ex);
                nfcOff = true;
            }
            try {
                bluetoothOff = bluetooth == null || bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                if (!bluetoothOff) {
                    Log.w(TAG, "Disabling Bluetooth...");
                    // disable but don't persist new state
                    bluetooth.disable(mContext.getPackageName(), false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                bluetoothOff = true;
            }
            try {
                radioOff = phone == null || !phone.needMobileRadioShutdown();
                if (!radioOff) {
                    Log.w(TAG, "Turning off cellular radios...");
                    phone.shutdownMobileRadios();
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during radio shutdown", ex);
                radioOff = true;
            }
            Log.i(TAG, "Waiting for NFC, Bluetooth and Radio...");
            long delay = endTime - SystemClock.elapsedRealtime();
            while (delay > 0) {
                if (mRebootHasProgressBar) {
                    int status = (int) ((timeout - delay) * 1.0 * (RADIO_STOP_PERCENT - PACKAGE_MANAGER_STOP_PERCENT) / timeout);
                    status += PACKAGE_MANAGER_STOP_PERCENT;
                    sInstance.setRebootProgress(status, null);
                }
                if (!bluetoothOff) {
                    try {
                        bluetoothOff = bluetooth.getState() == BluetoothAdapter.STATE_OFF;
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                        bluetoothOff = true;
                    }
                    if (bluetoothOff) {
                        Log.i(TAG, "Bluetooth turned off.");
                    }
                }
                if (!radioOff) {
                    try {
                        radioOff = !phone.needMobileRadioShutdown();
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during radio shutdown", ex);
                        radioOff = true;
                    }
                    if (radioOff) {
                        Log.i(TAG, "Radio turned off.");
                    }
                }
                if (!nfcOff) {
                    try {
                        nfcOff = nfc.getState() == NfcAdapter.STATE_OFF;
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during NFC shutdown", ex);
                        nfcOff = true;
                    }
                    if (nfcOff) {
                        Log.i(TAG, "NFC turned off.");
                    }
                }
                if (radioOff && bluetoothOff && nfcOff) {
                    Log.i(TAG, "NFC, Radio and Bluetooth shutdown complete.");
                    done[0] = true;
                    break;
                }
                SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
                delay = endTime - SystemClock.elapsedRealtime();
            }
        }
    };
    t.start();
    try {
        t.join(timeout);
    } catch (InterruptedException ex) {
    }
    if (!done[0]) {
        Log.w(TAG, "Timed out waiting for NFC, Radio and Bluetooth shutdown.");
    }
}
Also used : IBluetoothManager(android.bluetooth.IBluetoothManager) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 9 with INfcAdapter

use of android.nfc.INfcAdapter in project android_frameworks_base by ParanoidAndroid.

the class ShutdownThread method shutdownRadios.

private void shutdownRadios(int timeout) {
    // If a radio is wedged, disabling it may hang so we do this work in another thread,
    // just in case.
    final long endTime = SystemClock.elapsedRealtime() + timeout;
    final boolean[] done = new boolean[1];
    Thread t = new Thread() {

        public void run() {
            boolean nfcOff;
            boolean bluetoothOff;
            boolean radioOff;
            final INfcAdapter nfc = INfcAdapter.Stub.asInterface(ServiceManager.checkService("nfc"));
            final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
            final IBluetoothManager bluetooth = IBluetoothManager.Stub.asInterface(ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE));
            try {
                nfcOff = nfc == null || nfc.getState() == NfcAdapter.STATE_OFF;
                if (!nfcOff) {
                    Log.w(TAG, "Turning off NFC...");
                    // Don't persist new state
                    nfc.disable(false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during NFC shutdown", ex);
                nfcOff = true;
            }
            try {
                bluetoothOff = bluetooth == null || !bluetooth.isEnabled();
                if (!bluetoothOff) {
                    Log.w(TAG, "Disabling Bluetooth...");
                    // disable but don't persist new state
                    bluetooth.disable(false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                bluetoothOff = true;
            }
            try {
                radioOff = phone == null || !phone.isRadioOn();
                if (!radioOff) {
                    Log.w(TAG, "Turning off radio...");
                    phone.setRadio(false);
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "RemoteException during radio shutdown", ex);
                radioOff = true;
            }
            Log.i(TAG, "Waiting for NFC, Bluetooth and Radio...");
            while (SystemClock.elapsedRealtime() < endTime) {
                if (!bluetoothOff) {
                    try {
                        bluetoothOff = !bluetooth.isEnabled();
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
                        bluetoothOff = true;
                    }
                    if (bluetoothOff) {
                        Log.i(TAG, "Bluetooth turned off.");
                    }
                }
                if (!radioOff) {
                    try {
                        radioOff = !phone.isRadioOn();
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during radio shutdown", ex);
                        radioOff = true;
                    }
                    if (radioOff) {
                        Log.i(TAG, "Radio turned off.");
                    }
                }
                if (!nfcOff) {
                    try {
                        nfcOff = nfc.getState() == NfcAdapter.STATE_OFF;
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException during NFC shutdown", ex);
                        nfcOff = true;
                    }
                    if (radioOff) {
                        Log.i(TAG, "NFC turned off.");
                    }
                }
                if (radioOff && bluetoothOff && nfcOff) {
                    Log.i(TAG, "NFC, Radio and Bluetooth shutdown complete.");
                    done[0] = true;
                    break;
                }
                SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
            }
        }
    };
    t.start();
    try {
        t.join(timeout);
    } catch (InterruptedException ex) {
    }
    if (!done[0]) {
        Log.w(TAG, "Timed out waiting for NFC, Radio and Bluetooth shutdown.");
    }
}
Also used : IBluetoothManager(android.bluetooth.IBluetoothManager) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 10 with INfcAdapter

use of android.nfc.INfcAdapter in project platform_frameworks_base by android.

the class CameraService method notifyNfcService.

private void notifyNfcService(boolean enablePolling) {
    IBinder nfcServiceBinder = getBinderService(NFC_SERVICE_BINDER_NAME);
    if (nfcServiceBinder == null) {
        Slog.w(TAG, "Could not connect to NFC service to notify it of camera state");
        return;
    }
    INfcAdapter nfcAdapterRaw = INfcAdapter.Stub.asInterface(nfcServiceBinder);
    int flags = enablePolling ? ENABLE_POLLING_FLAGS : DISABLE_POLLING_FLAGS;
    if (DEBUG)
        Slog.v(TAG, "Setting NFC reader mode to flags " + flags);
    try {
        nfcAdapterRaw.setReaderMode(nfcInterfaceToken, null, flags, null);
    } catch (RemoteException e) {
        Slog.w(TAG, "Could not notify NFC service, remote exception: " + e);
    }
}
Also used : IBinder(android.os.IBinder) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException)

Aggregations

INfcAdapter (android.nfc.INfcAdapter)15 RemoteException (android.os.RemoteException)15 IBluetoothManager (android.bluetooth.IBluetoothManager)5 IPackageManager (android.content.pm.IPackageManager)5 IBinder (android.os.IBinder)5 ITelephony (com.android.internal.telephony.ITelephony)5