use of com.android.internal.telephony.ITelephony in project android_frameworks_base by ResurrectionRemix.
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.");
}
}
use of com.android.internal.telephony.ITelephony in project android_frameworks_base by ResurrectionRemix.
the class ConnectivityManager method getMobileDataEnabled.
/**
* @hide
* @deprecated Talk to TelephonyManager directly
*/
public boolean getMobileDataEnabled() {
IBinder b = ServiceManager.getService(Context.TELEPHONY_SERVICE);
if (b != null) {
try {
ITelephony it = ITelephony.Stub.asInterface(b);
int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Log.d("ConnectivityManager", "getMobileDataEnabled()+ subId=" + subId);
boolean retVal = it.getDataEnabled(subId);
Log.d("ConnectivityManager", "getMobileDataEnabled()- subId=" + subId + " retVal=" + retVal);
return retVal;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
Log.d("ConnectivityManager", "getMobileDataEnabled()- remote exception retVal=false");
return false;
}
use of com.android.internal.telephony.ITelephony in project android_frameworks_base by DirtyUnicorns.
the class TelephonyManager method getCellLocation.
/**
* Returns the current location of the device.
*<p>
* If there is only one radio in the device and that radio has an LTE connection,
* this method will return null. The implementation must not to try add LTE
* identifiers into the existing cdma/gsm classes.
*<p>
* In the future this call will be deprecated.
*<p>
* @return Current location of the device or null if not available.
*
* <p>Requires Permission:
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
*/
public CellLocation getCellLocation() {
try {
ITelephony telephony = getITelephony();
if (telephony == null) {
Rlog.d(TAG, "getCellLocation returning null because telephony is null");
return null;
}
Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName());
if (bundle.isEmpty()) {
Rlog.d(TAG, "getCellLocation returning null because bundle is empty");
return null;
}
CellLocation cl = CellLocation.newFromBundle(bundle);
if (cl.isEmpty()) {
Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty");
return null;
}
return cl;
} catch (RemoteException ex) {
Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex);
return null;
} catch (NullPointerException ex) {
Rlog.d(TAG, "getCellLocation returning null due to NullPointerException " + ex);
return null;
}
}
use of com.android.internal.telephony.ITelephony in project android_frameworks_base by DirtyUnicorns.
the class TelephonyManager method setDataEnabled.
/** @hide */
@SystemApi
public void setDataEnabled(int subId, boolean enable) {
try {
Log.d(TAG, "setDataEnabled: enabled=" + enable);
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.setDataEnabled(subId, enable);
} catch (RemoteException e) {
Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e);
} catch (NullPointerException npe) {
Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", npe);
}
}
use of com.android.internal.telephony.ITelephony in project android_frameworks_base by DirtyUnicorns.
the class TelephonyManager method factoryReset.
/**
* Resets telephony manager settings back to factory defaults.
*
* @hide
*/
public void factoryReset(int subId) {
try {
Log.d(TAG, "factoryReset: subId=" + subId);
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.factoryReset(subId);
} catch (RemoteException e) {
}
}
Aggregations