Search in sources :

Example 96 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class MediaScanner method processPlayLists.

private void processPlayLists() throws RemoteException {
    Iterator<FileEntry> iterator = mPlayLists.iterator();
    Cursor fileList = null;
    try {
        // use the files uri and projection because we need the format column,
        // but restrict the query to just audio files
        fileList = mMediaProvider.query(mPackageName, mFilesUri, FILES_PRESCAN_PROJECTION, "media_type=2", null, null, null);
        while (iterator.hasNext()) {
            FileEntry entry = iterator.next();
            // only process playlist files if they are new or have been modified since the last scan
            if (entry.mLastModifiedChanged) {
                processPlayList(entry, fileList);
            }
        }
    } catch (RemoteException e1) {
    } finally {
        if (fileList != null) {
            fileList.close();
        }
    }
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException)

Example 97 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class AudioService method setModeInt.

// must be called synchronized on mSetModeDeathHandlers
// setModeInt() returns a valid PID if the audio mode was successfully set to
// any mode other than NORMAL.
int setModeInt(int mode, IBinder cb, int pid) {
    int newModeOwnerPid = 0;
    if (cb == null) {
        Log.e(TAG, "setModeInt() called with null binder");
        return newModeOwnerPid;
    }
    SetModeDeathHandler hdlr = null;
    Iterator iter = mSetModeDeathHandlers.iterator();
    while (iter.hasNext()) {
        SetModeDeathHandler h = (SetModeDeathHandler) iter.next();
        if (h.getPid() == pid) {
            hdlr = h;
            // Remove from client list so that it is re-inserted at top of list
            iter.remove();
            hdlr.getBinder().unlinkToDeath(hdlr, 0);
            break;
        }
    }
    int status = AudioSystem.AUDIO_STATUS_OK;
    do {
        if (mode == AudioSystem.MODE_NORMAL) {
            // get new mode from client at top the list if any
            if (!mSetModeDeathHandlers.isEmpty()) {
                hdlr = mSetModeDeathHandlers.get(0);
                cb = hdlr.getBinder();
                mode = hdlr.getMode();
            }
        } else {
            if (hdlr == null) {
                hdlr = new SetModeDeathHandler(cb, pid);
            }
            // Register for client death notification
            try {
                cb.linkToDeath(hdlr, 0);
            } catch (RemoteException e) {
                // Client has died!
                Log.w(TAG, "setMode() could not link to " + cb + " binder death");
            }
            // Last client to call setMode() is always at top of client list
            // as required by SetModeDeathHandler.binderDied()
            mSetModeDeathHandlers.add(0, hdlr);
            hdlr.setMode(mode);
        }
        if (mode != mMode) {
            status = AudioSystem.setPhoneState(mode);
            if (status == AudioSystem.AUDIO_STATUS_OK) {
                mMode = mode;
            } else {
                if (hdlr != null) {
                    mSetModeDeathHandlers.remove(hdlr);
                    cb.unlinkToDeath(hdlr, 0);
                }
                // force reading new top of mSetModeDeathHandlers stack
                mode = AudioSystem.MODE_NORMAL;
            }
        } else {
            status = AudioSystem.AUDIO_STATUS_OK;
        }
    } while (status != AudioSystem.AUDIO_STATUS_OK && !mSetModeDeathHandlers.isEmpty());
    if (status == AudioSystem.AUDIO_STATUS_OK) {
        if (mode != AudioSystem.MODE_NORMAL) {
            if (mSetModeDeathHandlers.isEmpty()) {
                Log.e(TAG, "setMode() different from MODE_NORMAL with empty mode client stack");
            } else {
                newModeOwnerPid = mSetModeDeathHandlers.get(0).getPid();
            }
        }
        int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
        if (streamType == STREAM_REMOTE_MUSIC) {
            // here handle remote media playback the same way as local playback
            streamType = AudioManager.STREAM_MUSIC;
        }
        int device = getDeviceForStream(streamType);
        int index = mStreamStates[mStreamVolumeAlias[streamType]].getIndex(device);
        setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true);
        updateStreamVolumeAlias(true);
    }
    return newModeOwnerPid;
}
Also used : Iterator(java.util.Iterator) RemoteException(android.os.RemoteException)

Example 98 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class MediaRouter method selectRouteStatic.

static void selectRouteStatic(int types, RouteInfo route) {
    final RouteInfo oldRoute = sStatic.mSelectedRoute;
    if (oldRoute == route)
        return;
    if ((route.getSupportedTypes() & types) == 0) {
        Log.w(TAG, "selectRoute ignored; cannot select route with supported types " + typesToString(route.getSupportedTypes()) + " into route types " + typesToString(types));
        return;
    }
    final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute;
    if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 && (route == btRoute || route == sStatic.mDefaultAudioVideo)) {
        try {
            sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute);
        } catch (RemoteException e) {
            Log.e(TAG, "Error changing Bluetooth A2DP state", e);
        }
    }
    final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay();
    final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null;
    final boolean newRouteHasAddress = route != null && route.mDeviceAddress != null;
    if (activeDisplay != null || oldRouteHasAddress || newRouteHasAddress) {
        if (newRouteHasAddress && !matchesDeviceAddress(activeDisplay, route)) {
            sStatic.mDisplayService.connectWifiDisplay(route.mDeviceAddress);
        } else if (activeDisplay != null && !newRouteHasAddress) {
            sStatic.mDisplayService.disconnectWifiDisplay();
        }
    }
    if (oldRoute != null) {
        dispatchRouteUnselected(types & oldRoute.getSupportedTypes(), oldRoute);
    }
    sStatic.mSelectedRoute = route;
    if (route != null) {
        dispatchRouteSelected(types & route.getSupportedTypes(), route);
    }
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay) RemoteException(android.os.RemoteException)

Example 99 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class MtpDatabase method getObjectInfo.

private boolean getObjectInfo(int handle, int[] outStorageFormatParent, char[] outName, long[] outCreatedModified) {
    Cursor c = null;
    try {
        c = mMediaProvider.query(mPackageName, mObjectsUri, OBJECT_INFO_PROJECTION, ID_WHERE, new String[] { Integer.toString(handle) }, null, null);
        if (c != null && c.moveToNext()) {
            outStorageFormatParent[0] = c.getInt(1);
            outStorageFormatParent[1] = c.getInt(2);
            outStorageFormatParent[2] = c.getInt(3);
            // extract name from path
            String path = c.getString(4);
            int lastSlash = path.lastIndexOf('/');
            int start = (lastSlash >= 0 ? lastSlash + 1 : 0);
            int end = path.length();
            if (end - start > 255) {
                end = start + 255;
            }
            path.getChars(start, end, outName, 0);
            outName[end - start] = 0;
            outCreatedModified[0] = c.getLong(5);
            outCreatedModified[1] = c.getLong(6);
            // use modification date as creation date if date added is not set
            if (outCreatedModified[0] == 0) {
                outCreatedModified[0] = outCreatedModified[1];
            }
            return true;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in getObjectInfo", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return false;
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException)

Example 100 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class MtpDatabase method beginSendObject.

private int beginSendObject(String path, int format, int parent, int storageId, long size, long modified) {
    // if mSubDirectories is not null, do not allow copying files to any other locations
    if (!inStorageSubDirectory(path))
        return -1;
    // make sure the object does not exist
    if (path != null) {
        Cursor c = null;
        try {
            c = mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, PATH_WHERE, new String[] { path }, null, null);
            if (c != null && c.getCount() > 0) {
                Log.w(TAG, "file already exists in beginSendObject: " + path);
                return -1;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in beginSendObject", e);
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
    mDatabaseModified = true;
    ContentValues values = new ContentValues();
    values.put(Files.FileColumns.DATA, path);
    values.put(Files.FileColumns.FORMAT, format);
    values.put(Files.FileColumns.PARENT, parent);
    values.put(Files.FileColumns.STORAGE_ID, storageId);
    values.put(Files.FileColumns.SIZE, size);
    values.put(Files.FileColumns.DATE_MODIFIED, modified);
    try {
        Uri uri = mMediaProvider.insert(mPackageName, mObjectsUri, values);
        if (uri != null) {
            return Integer.parseInt(uri.getPathSegments().get(2));
        } else {
            return -1;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in beginSendObject", e);
        return -1;
    }
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Aggregations

RemoteException (android.os.RemoteException)4527 Intent (android.content.Intent)595 IBinder (android.os.IBinder)480 Bundle (android.os.Bundle)461 Point (android.graphics.Point)423 IOException (java.io.IOException)381 PendingIntent (android.app.PendingIntent)274 ComponentName (android.content.ComponentName)265 ArrayList (java.util.ArrayList)248 ApplicationInfo (android.content.pm.ApplicationInfo)190 IPackageManager (android.content.pm.IPackageManager)190 Message (android.os.Message)184 Uri (android.net.Uri)157 UserHandle (android.os.UserHandle)154 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)151 Cursor (android.database.Cursor)150 Configuration (android.content.res.Configuration)133 UserInfo (android.content.pm.UserInfo)129 AndroidRuntimeException (android.util.AndroidRuntimeException)128 ParcelFileDescriptor (android.os.ParcelFileDescriptor)126