Java Code Examples for android.content.Context#bindServiceAsUser()
The following examples show how to use
android.content.Context#bindServiceAsUser() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyguardServiceDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 8 votes |
public void bindService(Context context) { Intent intent = new Intent(); final Resources resources = context.getApplicationContext().getResources(); final ComponentName keyguardComponent = ComponentName.unflattenFromString( resources.getString(com.android.internal.R.string.config_keyguardComponent)); intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); intent.setComponent(keyguardComponent); if (!context.bindServiceAsUser(intent, mKeyguardConnection, Context.BIND_AUTO_CREATE, mHandler, UserHandle.SYSTEM)) { Log.v(TAG, "*** Keyguard: can't bind to " + keyguardComponent); mKeyguardState.showing = false; mKeyguardState.showingAndNotOccluded = false; mKeyguardState.secure = false; synchronized (mKeyguardState) { // TODO: Fix synchronisation model in this class. The other state in this class // is at least self-healing but a race condition here can lead to the scrim being // stuck on keyguard-less devices. mKeyguardState.deviceHasKeyguard = false; } } else { if (DEBUG) Log.v(TAG, "*** Keyguard started"); } }
Example 2
Source File: SyncManager.java From android_9.0.0_r45 with Apache License 2.0 | 7 votes |
static void sendOnUnsyncableAccount(@NonNull Context context, @NonNull RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo, @UserIdInt int userId, @NonNull OnReadyCallback onReadyCallback) { OnUnsyncableAccountCheck connection = new OnUnsyncableAccountCheck(syncAdapterInfo, onReadyCallback); boolean isBound = context.bindServiceAsUser( getAdapterBindIntent(context, syncAdapterInfo.componentName, userId), connection, SYNC_ADAPTER_CONNECTION_FLAGS, UserHandle.of(userId)); if (isBound) { // Unbind after SERVICE_BOUND_TIME_MILLIS to not leak the connection. (new Handler(Looper.getMainLooper())).postDelayed( () -> context.unbindService(connection), OnUnsyncableAccountCheck.SERVICE_BOUND_TIME_MILLIS); } else { /* * The default implementation of adapter.onUnsyncableAccount returns true. Hence if * there the service cannot be bound, assume the default behavior. */ connection.onReady(); } }
Example 3
Source File: NetworkScoreService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@VisibleForTesting public void bind(Context context) { if (!mBound) { Intent service = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS); service.setComponent(mAppData.getRecommendationServiceComponent()); mBound = context.bindServiceAsUser(service, this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, UserHandle.SYSTEM); if (!mBound) { Log.w(TAG, "Bind call failed for " + service); context.unbindService(this); } else { if (DBG) Log.d(TAG, "ScoringServiceConnection bound."); } } }
Example 4
Source File: TrustAgentWrapper.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public TrustAgentWrapper(Context context, TrustManagerService trustManagerService, Intent intent, UserHandle user) { mContext = context; mTrustManagerService = trustManagerService; mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); mUserId = user.getIdentifier(); mName = intent.getComponent(); mAlarmIntent = new Intent(TRUST_EXPIRED_ACTION).putExtra(EXTRA_COMPONENT_NAME, mName); mAlarmIntent.setData(Uri.parse(mAlarmIntent.toUri(Intent.URI_INTENT_SCHEME))); mAlarmIntent.setPackage(context.getPackageName()); final IntentFilter alarmFilter = new IntentFilter(TRUST_EXPIRED_ACTION); alarmFilter.addDataScheme(mAlarmIntent.getScheme()); final String pathUri = mAlarmIntent.toUri(Intent.URI_INTENT_SCHEME); alarmFilter.addDataPath(pathUri, PatternMatcher.PATTERN_LITERAL); // Schedules a restart for when connecting times out. If the connection succeeds, // the restart is canceled in mCallback's onConnected. scheduleRestart(); mBound = context.bindServiceAsUser(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, user); if (mBound) { mContext.registerReceiver(mBroadcastReceiver, alarmFilter, PERMISSION, null); } else { Log.e(TAG, "Can't bind to TrustAgent " + mName.flattenToShortString()); } }