Search in sources :

Example 31 with ITelephony

use of com.android.internal.telephony.ITelephony in project android_frameworks_base by crdroidandroid.

the class TelephonyManager method getLine1Number.

/**
     * Returns the phone number string for line 1, for example, the MSISDN
     * for a GSM phone for a particular subscription. Return null if it is unavailable.
     * <p>
     * Requires Permission:
     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     *   OR
     *   {@link android.Manifest.permission#READ_SMS}
     * <p>
     * The default SMS app can also use this.
     *
     * @param subId whose phone number for line 1 is returned
     * @hide
     */
public String getLine1Number(int subId) {
    android.util.SeempLog.record_str(9, "" + subId);
    String number = null;
    try {
        ITelephony telephony = getITelephony();
        if (telephony != null)
            number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName());
    } catch (RemoteException ex) {
    } catch (NullPointerException ex) {
    }
    if (number != null) {
        return number;
    }
    try {
        IPhoneSubInfo info = getSubscriberInfo();
        if (info == null)
            return null;
        return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName());
    } catch (RemoteException ex) {
        return null;
    } catch (NullPointerException ex) {
        // This could happen before phone restarts due to crashing
        return null;
    }
}
Also used : IPhoneSubInfo(com.android.internal.telephony.IPhoneSubInfo) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 32 with ITelephony

use of com.android.internal.telephony.ITelephony in project android_frameworks_base by crdroidandroid.

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) {
    }
}
Also used : RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 33 with ITelephony

use of com.android.internal.telephony.ITelephony in project android_frameworks_base by crdroidandroid.

the class TelephonyManager method setDataEnabled.

/** @hide */
@SystemApi
public void setDataEnabled(int subId, boolean enable) {
    try {
        Log.d(TAG, "setDataEnabled: enabled=" + enable);
        AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        if (enable) {
            if (appOps.noteOp(AppOpsManager.OP_DATA_CONNECT_CHANGE) != AppOpsManager.MODE_ALLOWED) {
                Log.w(TAG, "Permission denied by user.");
                return;
            }
        }
        ITelephony telephony = getITelephony();
        if (telephony != null)
            telephony.setDataEnabled(subId, enable);
    } catch (RemoteException e) {
        Log.e(TAG, "Error calling setDataEnabled", e);
    } catch (NullPointerException npe) {
        Log.e(TAG, "Error calling setDataEnabled", npe);
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony) SystemApi(android.annotation.SystemApi)

Example 34 with ITelephony

use of com.android.internal.telephony.ITelephony 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 35 with ITelephony

use of com.android.internal.telephony.ITelephony in project cornerstone by Onskreen.

the class PhoneWindowManager method interceptKeyBeforeDispatching.

/**
 * {@inheritDoc}
 */
@Override
public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
    final boolean keyguardOn = keyguardOn();
    final int keyCode = event.getKeyCode();
    final int repeatCount = event.getRepeatCount();
    final int metaState = event.getMetaState();
    final int flags = event.getFlags();
    final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
    final boolean canceled = event.isCanceled();
    if (DEBUG_INPUT) {
        Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed + " canceled=" + canceled);
    }
    // try again later before dispatching.
    if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
        if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
            final long now = SystemClock.uptimeMillis();
            final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
            if (now < timeoutTime) {
                return timeoutTime - now;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeDownKeyConsumedByScreenshotChord) {
            if (!down) {
                mVolumeDownKeyConsumedByScreenshotChord = false;
            }
            return -1;
        }
    }
    // timeout.
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        // while it was pressed, then it is time to go home!
        if (!down) {
            final boolean homeWasLongPressed = mHomeLongPressed;
            mHomePressed = false;
            mHomeLongPressed = false;
            if (!homeWasLongPressed) {
                try {
                    IStatusBarService statusbar = getStatusBarService();
                    if (statusbar != null) {
                        statusbar.cancelPreloadRecentApps();
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when showing recent apps", e);
                    // re-acquire status bar service next time it is needed.
                    mStatusBarService = null;
                }
                mHomePressed = false;
                if (!canceled) {
                    // If an incoming call is ringing, HOME is totally disabled.
                    // (The user is already on the InCallScreen at this point,
                    // and his ONLY options are to answer or reject the call.)
                    boolean incomingRinging = false;
                    try {
                        ITelephony telephonyService = getTelephonyService();
                        if (telephonyService != null) {
                            incomingRinging = telephonyService.isRinging();
                        }
                    } catch (RemoteException ex) {
                        Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                    }
                    if (incomingRinging) {
                        Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
                    } else {
                        launchHomeFromHotKey();
                    }
                } else {
                    Log.i(TAG, "Ignoring HOME; event canceled.");
                }
                return -1;
            }
        }
        // If a system window has focus, then it doesn't make sense
        // right now to interact with applications.
        WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
        if (attrs != null) {
            final int type = attrs.type;
            if (type == WindowManager.LayoutParams.TYPE_KEYGUARD || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
                // the "app" is keyguard, so give it the key
                return 0;
            }
            final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
            for (int i = 0; i < typeCount; i++) {
                if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
                    // don't do anything, but also don't pass it to the app
                    return -1;
                }
            }
        }
        if (down) {
            if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
                try {
                    IStatusBarService statusbar = getStatusBarService();
                    if (statusbar != null) {
                        statusbar.preloadRecentApps();
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when preloading recent apps", e);
                    // re-acquire status bar service next time it is needed.
                    mStatusBarService = null;
                }
            }
            if (repeatCount == 0) {
                /**
                 * Author: Onskreen
                 * Date: 31/05/2011
                 *
                 * If the dialog is present, first kill/dismiss the dialog
                 * and then launch the HOME app or recent app dialog.
                 */
                if (win.isDialog()) {
                    win.removeWindowState();
                }
                mHomePressed = true;
            } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                if (!keyguardOn) {
                    handleLongPressOnHome();
                }
            }
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        // Hijack modified menu keys for debugging features
        final int chordBug = KeyEvent.META_SHIFT_ON;
        if (down && repeatCount == 0) {
            if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
                Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
                mContext.sendOrderedBroadcast(intent, null);
                return -1;
            } else if (SHOW_PROCESSES_ON_ALT_MENU && (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
                Intent service = new Intent();
                service.setClassName(mContext, "com.android.server.LoadAverageService");
                ContentResolver res = mContext.getContentResolver();
                boolean shown = Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0;
                if (!shown) {
                    mContext.startService(service);
                } else {
                    mContext.stopService(service);
                }
                Settings.System.putInt(res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
                return -1;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        if (down) {
            if (repeatCount == 0) {
                mSearchKeyShortcutPending = true;
                mConsumeSearchKeyUp = false;
            }
        } else {
            mSearchKeyShortcutPending = false;
            if (mConsumeSearchKeyUp) {
                mConsumeSearchKeyUp = false;
                return -1;
            }
        }
        return 0;
    } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
        if (down && repeatCount == 0 && !keyguardOn) {
            showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
        if (down) {
            if (repeatCount == 0) {
                mAssistKeyLongPressed = false;
            } else if (repeatCount == 1) {
                mAssistKeyLongPressed = true;
                if (!keyguardOn) {
                    launchAssistLongPressAction();
                }
            }
        } else {
            if (mAssistKeyLongPressed) {
                mAssistKeyLongPressed = false;
            } else {
                if (!keyguardOn) {
                    launchAssistAction();
                }
            }
        }
        return -1;
    }
    // shortcut keys (that emit Search+x) and some of them are not registered.
    if (mSearchKeyShortcutPending) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            mConsumeSearchKeyUp = true;
            mSearchKeyShortcutPending = false;
            if (down && repeatCount == 0 && !keyguardOn) {
                Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
                if (shortcutIntent != null) {
                    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        mContext.startActivity(shortcutIntent);
                    } catch (ActivityNotFoundException ex) {
                        Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
                    }
                } else {
                    Slog.i(TAG, "Dropping unregistered shortcut key combination: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
                }
            }
            return -1;
        }
    }
    // Invoke shortcuts using Meta.
    if (down && repeatCount == 0 && !keyguardOn && (metaState & KeyEvent.META_META_ON) != 0) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState & ~(KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
            if (shortcutIntent != null) {
                shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    mContext.startActivity(shortcutIntent);
                } catch (ActivityNotFoundException ex) {
                    Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
                }
                return -1;
            }
        }
    }
    // Handle application launch keys.
    if (down && repeatCount == 0 && !keyguardOn) {
        String category = sApplicationLaunchKeyCategories.get(keyCode);
        if (category != null) {
            Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                mContext.startActivity(intent);
            } catch (ActivityNotFoundException ex) {
                Slog.w(TAG, "Dropping application launch key because " + "the activity to which it is registered was not found: " + "keyCode=" + keyCode + ", category=" + category, ex);
            }
            return -1;
        }
    }
    // Display task switcher for ALT-TAB or Meta-TAB.
    if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
        if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
            final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
            if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) || KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_META_ON)) {
                mRecentAppsDialogHeldModifiers = shiftlessModifiers;
                showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
                return -1;
            }
        }
    } else if (!down && mRecentAppsDialogHeldModifiers != 0 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
        mRecentAppsDialogHeldModifiers = 0;
        showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
    }
    // Handle keyboard language switching.
    if (down && repeatCount == 0 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || (keyCode == KeyEvent.KEYCODE_SPACE && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
        int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
        mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
        return -1;
    }
    if (mLanguageSwitchKeyPressed && !down && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || keyCode == KeyEvent.KEYCODE_SPACE)) {
        mLanguageSwitchKeyPressed = false;
        return -1;
    }
    // Let the application handle the key.
    return 0;
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) Intent(android.content.Intent) KeyCharacterMap(android.view.KeyCharacterMap) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager) ContentResolver(android.content.ContentResolver) ActivityNotFoundException(android.content.ActivityNotFoundException) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Aggregations

ITelephony (com.android.internal.telephony.ITelephony)36 RemoteException (android.os.RemoteException)35 IBluetoothManager (android.bluetooth.IBluetoothManager)5 INfcAdapter (android.nfc.INfcAdapter)5 IBinder (android.os.IBinder)5 SystemApi (android.annotation.SystemApi)4 Bundle (android.os.Bundle)4 Intent (android.content.Intent)3 AppOpsManager (android.app.AppOpsManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ContentResolver (android.content.ContentResolver)2 Message (android.os.Message)2 IWindowManager (android.view.IWindowManager)2 KeyCharacterMap (android.view.KeyCharacterMap)2 KeyEvent (android.view.KeyEvent)2 WindowManager (android.view.WindowManager)2 IPhoneSubInfo (com.android.internal.telephony.IPhoneSubInfo)2 IActivityManager (android.app.IActivityManager)1 IBluetooth (android.bluetooth.IBluetooth)1 BroadcastReceiver (android.content.BroadcastReceiver)1