Search in sources :

Example 16 with IBinder

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

the class ActiveServices method bindServiceLocked.

int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service, String resolvedType, IServiceConnection connection, int flags, int userId) {
    if (DEBUG_SERVICE)
        Slog.v(TAG, "bindService: " + service + " type=" + resolvedType + " conn=" + connection.asBinder() + " flags=0x" + Integer.toHexString(flags));
    final ProcessRecord callerApp = mAm.getRecordForAppLocked(caller);
    if (callerApp == null) {
        throw new SecurityException("Unable to find app for caller " + caller + " (pid=" + Binder.getCallingPid() + ") when binding service " + service);
    }
    ActivityRecord activity = null;
    if (token != null) {
        activity = mAm.mMainStack.isInStackLocked(token);
        if (activity == null) {
            Slog.w(TAG, "Binding with unknown activity: " + token);
            return 0;
        }
    }
    int clientLabel = 0;
    PendingIntent clientIntent = null;
    if (callerApp.info.uid == Process.SYSTEM_UID) {
        // others to know why certain services are running.
        try {
            clientIntent = (PendingIntent) service.getParcelableExtra(Intent.EXTRA_CLIENT_INTENT);
        } catch (RuntimeException e) {
        }
        if (clientIntent != null) {
            clientLabel = service.getIntExtra(Intent.EXTRA_CLIENT_LABEL, 0);
            if (clientLabel != 0) {
                // There are no useful extras in the intent, trash them.
                // System code calling with this stuff just needs to know
                // this will happen.
                service = service.cloneFilter();
            }
        }
    }
    ServiceLookupResult res = retrieveServiceLocked(service, resolvedType, Binder.getCallingPid(), Binder.getCallingUid(), userId, true);
    if (res == null) {
        return 0;
    }
    if (res.record == null) {
        return -1;
    }
    ServiceRecord s = res.record;
    final long origId = Binder.clearCallingIdentity();
    try {
        if (unscheduleServiceRestartLocked(s)) {
            if (DEBUG_SERVICE)
                Slog.v(TAG, "BIND SERVICE WHILE RESTART PENDING: " + s);
        }
        AppBindRecord b = s.retrieveAppBindingLocked(service, callerApp);
        ConnectionRecord c = new ConnectionRecord(b, activity, connection, flags, clientLabel, clientIntent);
        IBinder binder = connection.asBinder();
        ArrayList<ConnectionRecord> clist = s.connections.get(binder);
        if (clist == null) {
            clist = new ArrayList<ConnectionRecord>();
            s.connections.put(binder, clist);
        }
        clist.add(c);
        b.connections.add(c);
        if (activity != null) {
            if (activity.connections == null) {
                activity.connections = new HashSet<ConnectionRecord>();
            }
            activity.connections.add(c);
        }
        b.client.connections.add(c);
        if ((c.flags & Context.BIND_ABOVE_CLIENT) != 0) {
            b.client.hasAboveClient = true;
        }
        clist = mServiceConnections.get(binder);
        if (clist == null) {
            clist = new ArrayList<ConnectionRecord>();
            mServiceConnections.put(binder, clist);
        }
        clist.add(c);
        if ((flags & Context.BIND_AUTO_CREATE) != 0) {
            s.lastActivity = SystemClock.uptimeMillis();
            if (bringUpServiceLocked(s, service.getFlags(), false) != null) {
                return 0;
            }
        }
        if (s.app != null) {
            // This could have made the service more important.
            mAm.updateOomAdjLocked(s.app);
        }
        if (DEBUG_SERVICE)
            Slog.v(TAG, "Bind " + s + " with " + b + ": received=" + b.intent.received + " apps=" + b.intent.apps.size() + " doRebind=" + b.intent.doRebind);
        if (s.app != null && b.intent.received) {
            // publish the connection.
            try {
                c.conn.connected(s.name, b.intent.binder);
            } catch (Exception e) {
                Slog.w(TAG, "Failure sending service " + s.shortName + " to connection " + c.conn.asBinder() + " (in " + c.binding.client.processName + ")", e);
            }
            // rebound, then do so.
            if (b.intent.apps.size() == 1 && b.intent.doRebind) {
                requestServiceBindingLocked(s, b.intent, true);
            }
        } else if (!b.intent.requested) {
            requestServiceBindingLocked(s, b.intent, false);
        }
    } finally {
        Binder.restoreCallingIdentity(origId);
    }
    return 1;
}
Also used : RemoteException(android.os.RemoteException) IOException(java.io.IOException) IBinder(android.os.IBinder) PendingIntent(android.app.PendingIntent)

Example 17 with IBinder

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

the class ActiveServices method peekServiceLocked.

IBinder peekServiceLocked(Intent service, String resolvedType) {
    ServiceLookupResult r = retrieveServiceLocked(service, resolvedType, Binder.getCallingPid(), Binder.getCallingUid(), UserHandle.getCallingUserId(), false);
    IBinder ret = null;
    if (r != null) {
        // r.record is null if findServiceLocked() failed the caller permission check
        if (r.record == null) {
            throw new SecurityException("Permission Denial: Accessing service " + r.record.name + " from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " requires " + r.permission);
        }
        IntentBindRecord ib = r.record.bindings.get(r.record.intent);
        if (ib != null) {
            ret = ib.binder;
        }
    }
    return ret;
}
Also used : IBinder(android.os.IBinder)

Example 18 with IBinder

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

the class ActiveServices method removeConnectionLocked.

void removeConnectionLocked(ConnectionRecord c, ProcessRecord skipApp, ActivityRecord skipAct) {
    IBinder binder = c.conn.asBinder();
    AppBindRecord b = c.binding;
    ServiceRecord s = b.service;
    ArrayList<ConnectionRecord> clist = s.connections.get(binder);
    if (clist != null) {
        clist.remove(c);
        if (clist.size() == 0) {
            s.connections.remove(binder);
        }
    }
    b.connections.remove(c);
    if (c.activity != null && c.activity != skipAct) {
        if (c.activity.connections != null) {
            c.activity.connections.remove(c);
        }
    }
    if (b.client != skipApp) {
        b.client.connections.remove(c);
        if ((c.flags & Context.BIND_ABOVE_CLIENT) != 0) {
            b.client.updateHasAboveClientLocked();
        }
    }
    clist = mServiceConnections.get(binder);
    if (clist != null) {
        clist.remove(c);
        if (clist.size() == 0) {
            mServiceConnections.remove(binder);
        }
    }
    if (b.connections.size() == 0) {
        b.intent.apps.remove(b.client);
    }
    if (!c.serviceDead) {
        if (DEBUG_SERVICE)
            Slog.v(TAG, "Disconnecting binding " + b.intent + ": shouldUnbind=" + b.intent.hasBound);
        if (s.app != null && s.app.thread != null && b.intent.apps.size() == 0 && b.intent.hasBound) {
            try {
                bumpServiceExecutingLocked(s, "unbind");
                mAm.updateOomAdjLocked(s.app);
                b.intent.hasBound = false;
                // Assume the client doesn't want to know about a rebind;
                // we will deal with that later if it asks for one.
                b.intent.doRebind = false;
                s.app.thread.scheduleUnbindService(s, b.intent.intent.getIntent());
            } catch (Exception e) {
                Slog.w(TAG, "Exception when unbinding service " + s.shortName, e);
                serviceDoneExecutingLocked(s, true);
            }
        }
        if ((c.flags & Context.BIND_AUTO_CREATE) != 0) {
            bringDownServiceLocked(s, false);
        }
    }
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 19 with IBinder

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

the class AccessibilityManagerService method getActiveWindowBounds.

/**
     * Gets the bounds of the active window.
     *
     * @param outBounds The output to which to write the bounds.
     */
boolean getActiveWindowBounds(Rect outBounds) {
    IBinder token;
    synchronized (mLock) {
        final int windowId = mSecurityPolicy.mActiveWindowId;
        token = mGlobalWindowTokens.get(windowId);
        if (token == null) {
            token = getCurrentUserStateLocked().mWindowTokens.get(windowId);
        }
    }
    try {
        mWindowManagerService.getWindowFrame(token, outBounds);
        if (!outBounds.isEmpty()) {
            return true;
        }
    } catch (RemoteException re) {
    /* ignore */
    }
    return false;
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 20 with IBinder

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

the class Tethering method updateConfiguration.

void updateConfiguration() {
    String[] tetherableUsbRegexs = mContext.getResources().getStringArray(com.android.internal.R.array.config_tether_usb_regexs);
    String[] tetherableWifiRegexs = mContext.getResources().getStringArray(com.android.internal.R.array.config_tether_wifi_regexs);
    String[] tetherableBluetoothRegexs = mContext.getResources().getStringArray(com.android.internal.R.array.config_tether_bluetooth_regexs);
    int[] ifaceTypes = mContext.getResources().getIntArray(com.android.internal.R.array.config_tether_upstream_types);
    Collection<Integer> upstreamIfaceTypes = new ArrayList();
    IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
    IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
    try {
        int activeNetType = cm.getActiveNetworkInfo().getType();
        for (int i : ifaceTypes) {
            if (i == activeNetType) {
                upstreamIfaceTypes.add(new Integer(i));
            }
        }
    } catch (Exception e) {
        Log.d(TAG, "Exception adding default nw to upstreamIfaceTypes: " + e);
    }
    for (int i : ifaceTypes) {
        if (!upstreamIfaceTypes.contains(new Integer(i))) {
            upstreamIfaceTypes.add(new Integer(i));
        }
    }
    synchronized (mPublicSync) {
        mTetherableUsbRegexs = tetherableUsbRegexs;
        mTetherableWifiRegexs = tetherableWifiRegexs;
        mTetherableBluetoothRegexs = tetherableBluetoothRegexs;
        mUpstreamIfaceTypes = upstreamIfaceTypes;
    }
    // check if the upstream type list needs to be modified due to secure-settings
    checkDunRequired();
}
Also used : IBinder(android.os.IBinder) ArrayList(java.util.ArrayList) IConnectivityManager(android.net.IConnectivityManager) RemoteException(android.os.RemoteException)

Aggregations

IBinder (android.os.IBinder)1139 RemoteException (android.os.RemoteException)553 Intent (android.content.Intent)186 ComponentName (android.content.ComponentName)166 ServiceConnection (android.content.ServiceConnection)127 Parcel (android.os.Parcel)112 PendingIntent (android.app.PendingIntent)69 Point (android.graphics.Point)67 Bundle (android.os.Bundle)56 IOException (java.io.IOException)53 UserHandle (android.os.UserHandle)50 Binder (android.os.Binder)47 Message (android.os.Message)37 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)35 Handler (android.os.Handler)33 AndroidRuntimeException (android.util.AndroidRuntimeException)33 ArrayList (java.util.ArrayList)30 IUsbManager (android.hardware.usb.IUsbManager)29 Context (android.content.Context)28 Messenger (android.os.Messenger)26