Java Code Examples for com.android.internal.util.Preconditions#checkNotNull()
The following examples show how to use
com.android.internal.util.Preconditions#checkNotNull() .
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: ContentProviderClient.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** See {@link ContentProvider#call(String, String, Bundle)} */ public @Nullable Bundle call(@NonNull String method, @Nullable String arg, @Nullable Bundle extras) throws RemoteException { Preconditions.checkNotNull(method, "method"); beforeRemote(); try { return mContentProvider.call(mPackageName, method, arg, extras); } catch (DeadObjectException e) { if (!mStable) { mContentResolver.unstableProviderDied(mContentProvider); } throw e; } finally { afterRemote(); } }
Example 2
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId) { Preconditions.checkNotNull(callingPackage, "callingPackage"); Preconditions.checkNotNull(packageName, "packageName"); Preconditions.checkNotNull(shortcutId, "shortcutId"); synchronized (mLock) { throwIfUserLockedL(userId); throwIfUserLockedL(launcherUserId); getLauncherShortcutsLocked(callingPackage, userId, launcherUserId) .attemptToRestoreIfNeededAndSave(); final ShortcutPackage p = getUserShortcutsLocked(userId) .getPackageShortcutsIfExists(packageName); if (p == null) { return 0; } final ShortcutInfo shortcutInfo = p.findShortcutById(shortcutId); return (shortcutInfo != null && shortcutInfo.hasIconResource()) ? shortcutInfo.getIconResourceId() : 0; } }
Example 3
Source File: TextClassificationManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onDestroyTextClassificationSession(TextClassificationSessionId sessionId) throws RemoteException { Preconditions.checkNotNull(sessionId); synchronized (mLock) { UserState userState = getCallingUserStateLocked(); if (userState.isBoundLocked()) { userState.mService.onDestroyTextClassificationSession(sessionId); } else { userState.mPendingRequests.add(new PendingRequest( () -> onDestroyTextClassificationSession(sessionId), null /* onServiceFailure */, null /* binder */, this, userState)); } } }
Example 4
Source File: ContentProviderClient.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** See {@link ContentProvider#uncanonicalize} */ public final @Nullable Uri uncanonicalize(@NonNull Uri url) throws RemoteException { Preconditions.checkNotNull(url, "url"); beforeRemote(); try { return mContentProvider.uncanonicalize(mPackageName, url); } catch (DeadObjectException e) { if (!mStable) { mContentResolver.unstableProviderDied(mContentProvider); } throw e; } finally { afterRemote(); } }
Example 5
Source File: ConnectivityManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** {@hide} */ public static final void enforceTetherChangePermission(Context context, String callingPkg) { Preconditions.checkNotNull(context, "Context cannot be null"); Preconditions.checkNotNull(callingPkg, "callingPkg cannot be null"); if (context.getResources().getStringArray( com.android.internal.R.array.config_mobile_hotspot_provision_app).length == 2) { // Have a provisioning app - must only let system apps (which check this app) // turn on tethering context.enforceCallingOrSelfPermission( android.Manifest.permission.TETHER_PRIVILEGED, "ConnectivityService"); } else { int uid = Binder.getCallingUid(); // If callingPkg's uid is not same as Binder.getCallingUid(), // AppOpsService throws SecurityException. Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPkg, true /* throwException */); } }
Example 6
Source File: UsbDevice.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * UsbDevice should only be instantiated by UsbService implementation * @hide */ public UsbDevice(@NonNull String name, int vendorId, int productId, int Class, int subClass, int protocol, @Nullable String manufacturerName, @Nullable String productName, @NonNull String version, @Nullable String serialNumber) { mName = Preconditions.checkNotNull(name); mVendorId = vendorId; mProductId = productId; mClass = Class; mSubclass = subClass; mProtocol = protocol; mManufacturerName = manufacturerName; mProductName = productName; mVersion = Preconditions.checkStringNotEmpty(version); mSerialNumber = serialNumber; }
Example 7
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** @hide */ @Override public KeySet getKeySetByAlias(String packageName, String alias) { Preconditions.checkNotNull(packageName); Preconditions.checkNotNull(alias); KeySet ks; try { ks = mPM.getKeySetByAlias(packageName, alias); } catch (RemoteException e) { return null; } return ks; }
Example 8
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** @hide */ @Override public boolean isSignedBy(String packageName, KeySet ks) { Preconditions.checkNotNull(packageName); Preconditions.checkNotNull(ks); try { return mPM.isPackageSignedByKeySet(packageName, ks); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example 9
Source File: SQLiteDatabase.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Sets <a href="https://sqlite.org/pragma.html#pragma_synchronous">synchronous mode</a> * . * @return */ @NonNull public Builder setSynchronousMode(@NonNull String syncMode) { Preconditions.checkNotNull(syncMode); mSyncMode = syncMode; return this; }
Example 10
Source File: RankingHelper.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public NotificationChannelGroup getNotificationChannelGroup(String groupId, String pkg, int uid) { Preconditions.checkNotNull(pkg); Record r = getRecord(pkg, uid); if (r == null) { return null; } return r.groups.get(groupId); }
Example 11
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void removeDynamicShortcuts(String packageName, List shortcutIds, @UserIdInt int userId) { verifyCaller(packageName, userId); Preconditions.checkNotNull(shortcutIds, "shortcutIds must be provided"); synchronized (mLock) { throwIfUserLockedL(userId); final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds, /*ignoreInvisible=*/ true); for (int i = shortcutIds.size() - 1; i >= 0; i--) { final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)); if (!ps.isShortcutExistsAndVisibleToPublisher(id)) { continue; } ps.deleteDynamicWithId(id, /*ignoreInvisible=*/ true); } // We may have removed dynamic shortcuts which may have left a gap, so adjust the ranks. ps.adjustRanks(); } packageShortcutsChanged(packageName, userId); verifyStates(); }
Example 12
Source File: ConnectivityManager.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * {@hide} */ public ConnectivityManager(Context context, IConnectivityManager service) { mContext = Preconditions.checkNotNull(context, "missing context"); mService = Preconditions.checkNotNull(service, "missing IConnectivityManager"); sInstance = this; }
Example 13
Source File: ContextHubTransaction.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Sets the listener to be invoked invoked when the transaction completes. * * This function provides an asynchronous approach to retrieve the result of the * transaction. When the transaction response has been provided by the Context Hub, * the given listener will be invoked. * * If the transaction has already completed at the time of invocation, the listener * will be immediately invoked. If the transaction has been invalidated, * the listener will never be invoked. * * A transaction can be invalidated if the process owning the transaction is no longer active * and the reference to this object is lost. * * This method or {@link #setOnCompleteListener(ContextHubTransaction.OnCompleteListener)} can * only be invoked once, or an IllegalStateException will be thrown. * * @param listener the listener to be invoked upon completion * @param executor the executor to invoke the callback * * @throws IllegalStateException if this method is called multiple times * @throws NullPointerException if the callback or handler is null */ public void setOnCompleteListener( @NonNull ContextHubTransaction.OnCompleteListener<T> listener, @NonNull @CallbackExecutor Executor executor) { synchronized (this) { Preconditions.checkNotNull(listener, "OnCompleteListener cannot be null"); Preconditions.checkNotNull(executor, "Executor cannot be null"); if (mListener != null) { throw new IllegalStateException( "Cannot set ContextHubTransaction listener multiple times"); } mListener = listener; mExecutor = executor; if (mDoneSignal.getCount() == 0) { mExecutor.execute(() -> mListener.onComplete(this, mResponse)); } } }
Example 14
Source File: ContentResolver.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Transform the given <var>url</var> to a canonical representation of * its referenced resource, which can be used across devices, persisted, * backed up and restored, etc. The returned Uri is still a fully capable * Uri for use with its content provider, allowing you to do all of the * same content provider operations as with the original Uri -- * {@link #query}, {@link #openInputStream(android.net.Uri)}, etc. The * only difference in behavior between the original and new Uris is that * the content provider may need to do some additional work at each call * using it to resolve it to the correct resource, especially if the * canonical Uri has been moved to a different environment. * * <p>If you are moving a canonical Uri between environments, you should * perform another call to {@link #canonicalize} with that original Uri to * re-canonicalize it for the current environment. Alternatively, you may * want to use {@link #uncanonicalize} to transform it to a non-canonical * Uri that works only in the current environment but potentially more * efficiently than the canonical representation.</p> * * @param url The {@link Uri} that is to be transformed to a canonical * representation. Like all resolver calls, the input can be either * a non-canonical or canonical Uri. * * @return Returns the official canonical representation of <var>url</var>, * or null if the content provider does not support a canonical representation * of the given Uri. Many providers may not support canonicalization of some * or all of their Uris. * * @see #uncanonicalize */ public final @Nullable Uri canonicalize(@NonNull Uri url) { Preconditions.checkNotNull(url, "url"); IContentProvider provider = acquireProvider(url); if (provider == null) { return null; } try { return provider.canonicalize(mPackageName, url); } catch (RemoteException e) { // Arbitrary and not worth documenting, as Activity // Manager will kill this process shortly anyway. return null; } finally { releaseProvider(provider); } }
Example 15
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
public ApplicationContentResolver( Context context, ActivityThread mainThread, UserHandle user) { super(context); mMainThread = Preconditions.checkNotNull(mainThread); mUser = Preconditions.checkNotNull(user); }
Example 16
Source File: AssetManager.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Open an asset using an explicit access mode, returning an InputStream to * read its contents. This provides access to files that have been bundled * with an application as assets -- that is, files placed in to the * "assets" directory. * * @param fileName The name of the asset to open. This name can be hierarchical. * @param accessMode Desired access mode for retrieving the data. * * @see #ACCESS_UNKNOWN * @see #ACCESS_STREAMING * @see #ACCESS_RANDOM * @see #ACCESS_BUFFER * @see #open(String) * @see #list */ public @NonNull InputStream open(@NonNull String fileName, int accessMode) throws IOException { Preconditions.checkNotNull(fileName, "fileName"); synchronized (this) { ensureOpenLocked(); final long asset = nativeOpenAsset(mObject, fileName, accessMode); if (asset == 0) { throw new FileNotFoundException("Asset file: " + fileName); } final AssetInputStream assetInputStream = new AssetInputStream(asset); incRefsLocked(assetInputStream.hashCode()); return assetInputStream; } }
Example 17
Source File: SelectionEvent.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Creates an event specifying an action taken on a selection. * Use when the user clicks on an action to act on the selected text and the selection's * entity type is known. * * @param start the start (inclusive) index of the selection * @param end the end (exclusive) index of the selection * @param actionType the action that was performed on the selection * @param classification the TextClassification object returned by the TextClassifier that * classified the selected text * * @throws IllegalArgumentException if end is less than start * @throws IllegalArgumentException If actionType is not a valid SelectionEvent actionType */ @NonNull public static SelectionEvent createSelectionActionEvent( int start, int end, @SelectionEvent.ActionType int actionType, @NonNull TextClassification classification) { Preconditions.checkArgument(end >= start, "end cannot be less than start"); Preconditions.checkNotNull(classification); checkActionType(actionType); final String entityType = classification.getEntityCount() > 0 ? classification.getEntity(0) : TextClassifier.TYPE_UNKNOWN; return new SelectionEvent(start, end, actionType, entityType, INVOCATION_UNKNOWN, classification.getId()); }
Example 18
Source File: AssetManager.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Populates `outData` with array elements of `resId`. `outData` is normally * used with * {@link TypedArray}. * * Each logical element in `outData` is {@link TypedArray#STYLE_NUM_ENTRIES} * long, * with the indices of the data representing the type, value, asset cookie, * resource ID, * configuration change mask, and density of the element. * * @param resId The resource ID of an array resource. * @param outData The array to populate with data. * @return The length of the array. * * @see TypedArray#STYLE_TYPE * @see TypedArray#STYLE_DATA * @see TypedArray#STYLE_ASSET_COOKIE * @see TypedArray#STYLE_RESOURCE_ID * @see TypedArray#STYLE_CHANGING_CONFIGURATIONS * @see TypedArray#STYLE_DENSITY */ int getResourceArray(@ArrayRes int resId, @NonNull int[] outData) { Preconditions.checkNotNull(outData, "outData"); synchronized (this) { ensureValidLocked(); return nativeGetResourceArray(mObject, resId, outData); } }
Example 19
Source File: BatchUpdates.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Applies the {@code updates} in the underlying presentation template. * * <p><b>Note:</b> The updates are applied before the * {@link #transformChild(int, Transformation) transformations} are applied to the children * views. * * <p>Theme does not work with RemoteViews layout. Avoid hardcoded text color * or background color: Autofill on different platforms may have different themes. * * @param updates a {@link RemoteViews} with the updated actions to be applied in the * underlying presentation template. * * @return this builder * @throws IllegalArgumentException if {@code condition} is not a class provided * by the Android System. */ public Builder updateTemplate(@NonNull RemoteViews updates) { throwIfDestroyed(); mUpdates = Preconditions.checkNotNull(updates); return this; }
Example 20
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Sets the target activity. A shortcut will be shown along with this activity's icon * on the launcher. * * When selecting a target activity, keep the following in mind: * <ul> * <li>All dynamic shortcuts must have a target activity. When a shortcut with no target * activity is published using * {@link ShortcutManager#addDynamicShortcuts(List)} or * {@link ShortcutManager#setDynamicShortcuts(List)}, * the first main activity defined in the app's <code>AndroidManifest.xml</code> * file is used. * * <li>Only "main" activities—ones that define the {@link Intent#ACTION_MAIN} * and {@link Intent#CATEGORY_LAUNCHER} intent filters—can be target * activities. * * <li>By default, the first main activity defined in the app's manifest is * the target activity. * * <li>A target activity must belong to the publisher app. * </ul> * * @see ShortcutInfo#getActivity() */ @NonNull public Builder setActivity(@NonNull ComponentName activity) { mActivity = Preconditions.checkNotNull(activity, "activity cannot be null"); return this; }