use of android.os.UserHandle in project platform_frameworks_base by android.
the class DevicePolicyManagerService method choosePrivateKeyAlias.
@Override
public void choosePrivateKeyAlias(final int uid, final Uri uri, final String alias, final IBinder response) {
// Caller UID needs to be trusted, so we restrict this method to SYSTEM_UID callers.
if (!isCallerWithSystemUid()) {
return;
}
final UserHandle caller = mInjector.binderGetCallingUserHandle();
// If there is a profile owner, redirect to that; otherwise query the device owner.
ComponentName aliasChooser = getProfileOwner(caller.getIdentifier());
if (aliasChooser == null && caller.isSystem()) {
ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
if (deviceOwnerAdmin != null) {
aliasChooser = deviceOwnerAdmin.info.getComponent();
}
}
if (aliasChooser == null) {
sendPrivateKeyAliasResponse(null, response);
return;
}
Intent intent = new Intent(DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS);
intent.setComponent(aliasChooser);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, uid);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_URI, uri);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_ALIAS, alias);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_RESPONSE, response);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
final long id = mInjector.binderClearCallingIdentity();
try {
mContext.sendOrderedBroadcastAsUser(intent, caller, null, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String chosenAlias = getResultData();
sendPrivateKeyAliasResponse(chosenAlias, response);
}
}, null, Activity.RESULT_OK, null, null);
} finally {
mInjector.binderRestoreCallingIdentity(id);
}
}
use of android.os.UserHandle in project platform_frameworks_base by android.
the class ManagedApplicationService method connect.
/**
* Asynchronously bind to the application service if not bound.
*/
public void connect() {
synchronized (mLock) {
if (mConnection != null || mPendingConnection != null) {
// We're already connected or are trying to connect
return;
}
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mSettingsAction), 0);
final Intent intent = new Intent().setComponent(mComponent).putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
final ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
IInterface iface = null;
PendingEvent pendingEvent = null;
synchronized (mLock) {
if (mPendingConnection == this) {
// No longer pending, remove from pending connection
mPendingConnection = null;
mConnection = this;
} else {
// Service connection wasn't pending, must have been disconnected
mContext.unbindService(this);
return;
}
try {
iBinder.linkToDeath(mDeathRecipient, 0);
mBoundInterface = mChecker.asInterface(iBinder);
if (!mChecker.checkType(mBoundInterface)) {
// Received an invalid binder, disconnect
mContext.unbindService(this);
mBoundInterface = null;
}
iface = mBoundInterface;
pendingEvent = mPendingEvent;
mPendingEvent = null;
} catch (RemoteException e) {
// DOA
Slog.w(TAG, "Unable to bind service: " + intent, e);
mBoundInterface = null;
}
}
if (iface != null && pendingEvent != null) {
try {
pendingEvent.runEvent(iface);
} catch (RuntimeException | RemoteException ex) {
Slog.e(TAG, "Received exception from user service: ", ex);
}
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Slog.w(TAG, "Service disconnected: " + intent);
mConnection = null;
mBoundInterface = null;
}
};
mPendingConnection = serviceConnection;
try {
if (!mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId))) {
Slog.w(TAG, "Unable to bind service: " + intent);
}
} catch (SecurityException e) {
Slog.w(TAG, "Unable to bind service: " + intent, e);
}
}
}
use of android.os.UserHandle in project platform_frameworks_base by android.
the class TvRemoteProviderWatcher method start.
public void start() {
if (DEBUG)
Slog.d(TAG, "start()");
if (!mRunning) {
mRunning = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
filter.addDataScheme("package");
mContext.registerReceiverAsUser(mScanPackagesReceiver, new UserHandle(mUserId), filter, null, mHandler);
// Scan packages.
// Also has the side-effect of restarting providers if needed.
mHandler.post(mScanPackagesRunnable);
}
}
use of android.os.UserHandle in project platform_frameworks_base by android.
the class RemotePrintService method ensureBound.
private void ensureBound() {
if (isBound() || mBinding) {
return;
}
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
}
mBinding = true;
mContext.bindServiceAsUser(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId));
}
use of android.os.UserHandle in project platform_frameworks_base by android.
the class VoiceInteractionManagerServiceImpl method startLocked.
void startLocked() {
Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
intent.setComponent(mComponent);
mBound = mContext.bindServiceAsUser(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUser));
if (!mBound) {
Slog.w(TAG, "Failed binding to voice interaction service " + mComponent);
}
}
Aggregations