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;
}
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;
}
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);
}
}
}
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;
}
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();
}
Aggregations