Java Code Examples for com.android.internal.util.Preconditions#checkState()
The following examples show how to use
com.android.internal.util.Preconditions#checkState() .
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: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void verifyCaller(@NonNull String packageName, @UserIdInt int userId) { Preconditions.checkStringNotEmpty(packageName, "packageName"); if (isCallerSystem()) { return; // no check } final int callingUid = injectBinderCallingUid(); // Otherwise, make sure the arguments are valid. if (UserHandle.getUserId(callingUid) != userId) { throw new SecurityException("Invalid user-ID"); } if (injectGetPackageUid(packageName, userId) != callingUid) { throw new SecurityException("Calling package name mismatch"); } Preconditions.checkState(!isEphemeralApp(packageName, userId), "Ephemeral apps can't use ShortcutManager"); }
Example 2
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * @hide * * @isUpdating set true if it's "update", as opposed to "replace". */ public void ensureUpdatableWith(ShortcutInfo source, boolean isUpdating) { if (isUpdating) { Preconditions.checkState(isVisibleToPublisher(), "[Framework BUG] Invisible shortcuts can't be updated"); } Preconditions.checkState(mUserId == source.mUserId, "Owner User ID must match"); Preconditions.checkState(mId.equals(source.mId), "ID must match"); Preconditions.checkState(mPackageName.equals(source.mPackageName), "Package name must match"); if (isVisibleToPublisher()) { // Don't do this check for restore-blocked shortcuts. Preconditions.checkState(!isImmutable(), "Target ShortcutInfo is immutable"); } }
Example 3
Source File: DeviceDiscoveryAction.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void handleReportPhysicalAddress(HdmiCecMessage cmd) { Preconditions.checkState(mProcessedDeviceCount < mDevices.size()); DeviceInfo current = mDevices.get(mProcessedDeviceCount); if (current.mLogicalAddress != cmd.getSource()) { Slog.w(TAG, "Unmatched address[expected:" + current.mLogicalAddress + ", actual:" + cmd.getSource()); return; } byte params[] = cmd.getParams(); current.mPhysicalAddress = HdmiUtils.twoBytesToInt(params); current.mPortId = getPortId(current.mPhysicalAddress); current.mDeviceType = params[2] & 0xFF; tv().updateCecSwitchInfo(current.mLogicalAddress, current.mDeviceType, current.mPhysicalAddress); increaseProcessedDeviceCount(); checkAndProceedStage(); }
Example 4
Source File: DeviceDiscoveryAction.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void handleSetOsdName(HdmiCecMessage cmd) { Preconditions.checkState(mProcessedDeviceCount < mDevices.size()); DeviceInfo current = mDevices.get(mProcessedDeviceCount); if (current.mLogicalAddress != cmd.getSource()) { Slog.w(TAG, "Unmatched address[expected:" + current.mLogicalAddress + ", actual:" + cmd.getSource()); return; } String displayName = null; try { if (cmd.getOpcode() == Constants.MESSAGE_FEATURE_ABORT) { displayName = HdmiUtils.getDefaultDeviceName(current.mLogicalAddress); } else { displayName = new String(cmd.getParams(), "US-ASCII"); } } catch (UnsupportedEncodingException e) { Slog.w(TAG, "Failed to decode display name: " + cmd.toString()); // If failed to get display name, use the default name of device. displayName = HdmiUtils.getDefaultDeviceName(current.mLogicalAddress); } current.mDisplayName = displayName; increaseProcessedDeviceCount(); checkAndProceedStage(); }
Example 5
Source File: RemoteViews.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Returns a deep copy of the RemoteViews object. The RemoteView may not be * attached to another RemoteView -- it must be the root of a hierarchy. * * @deprecated use {@link #RemoteViews(RemoteViews)} instead. * @throws IllegalStateException if this is not the root of a RemoteView * hierarchy */ @Override @Deprecated public RemoteViews clone() { Preconditions.checkState(mIsRoot, "RemoteView has been attached to another RemoteView. " + "May only clone the root of a RemoteView hierarchy."); return new RemoteViews(this); }
Example 6
Source File: UserRestrictionsUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static Set<String> newSetWithUniqueCheck(String[] strings) { final Set<String> ret = Sets.newArraySet(strings); // Make sure there's no overlap. Preconditions.checkState(ret.size() == strings.length); return ret; }
Example 7
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Nullable private ShortcutInfo deleteOrDisableWithId(@NonNull String shortcutId, boolean disable, boolean overrideImmutable, boolean ignoreInvisible, int disabledReason) { Preconditions.checkState( (disable == (disabledReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED)), "disable and disabledReason disagree: " + disable + " vs " + disabledReason); final ShortcutInfo oldShortcut = mShortcuts.get(shortcutId); if (oldShortcut == null || !oldShortcut.isEnabled() && (ignoreInvisible && !oldShortcut.isVisibleToPublisher())) { return null; // Doesn't exist or already disabled. } if (!overrideImmutable) { ensureNotImmutable(oldShortcut, /*ignoreInvisible=*/ true); } if (oldShortcut.isPinned()) { oldShortcut.setRank(0); oldShortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_MANIFEST); if (disable) { oldShortcut.addFlags(ShortcutInfo.FLAG_DISABLED); // Do not overwrite the disabled reason if one is alreay set. if (oldShortcut.getDisabledReason() == ShortcutInfo.DISABLED_REASON_NOT_DISABLED) { oldShortcut.setDisabledReason(disabledReason); } } oldShortcut.setTimestamp(mShortcutUser.mService.injectCurrentTimeMillis()); // See ShortcutRequestPinProcessor.directPinShortcut(). if (mShortcutUser.mService.isDummyMainActivity(oldShortcut.getActivity())) { oldShortcut.setActivity(null); } return oldShortcut; } else { forceDeleteShortcutInner(shortcutId); return null; } }
Example 8
Source File: AmbientBrightnessDayStats.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void checkSorted(float[] values) { if (values.length <= 1) { return; } float prevValue = values[0]; for (int i = 1; i < values.length; i++) { Preconditions.checkState(prevValue < values[i]); prevValue = values[i]; } return; }
Example 9
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Handles {@link #requestPinShortcut} and {@link ShortcutServiceInternal#requestPinAppWidget}. * After validating the caller, it passes the request to {@link #mShortcutRequestPinProcessor}. * Either {@param shortcut} or {@param appWidget} should be non-null. */ private boolean requestPinItem(String packageName, int userId, ShortcutInfo shortcut, AppWidgetProviderInfo appWidget, Bundle extras, IntentSender resultIntent) { verifyCaller(packageName, userId); verifyShortcutInfoPackage(packageName, shortcut); final boolean ret; synchronized (mLock) { throwIfUserLockedL(userId); Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()), "Calling application must have a foreground activity or a foreground service"); // If it's a pin shortcut request, and there's already a shortcut with the same ID // that's not visible to the caller (i.e. restore-blocked; meaning it's pinned by // someone already), then we just replace the existing one with this new one, // and then proceed the rest of the process. if (shortcut != null) { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked( packageName, userId); final String id = shortcut.getId(); if (ps.isShortcutExistsAndInvisibleToPublisher(id)) { ps.updateInvisibleShortcutForPinRequestWith(shortcut); packageShortcutsChanged(packageName, userId); } } // Send request to the launcher, if supported. ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, extras, userId, resultIntent); } verifyStates(); return ret; }
Example 10
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Sets the message that should be shown when the user attempts to start a shortcut that * is disabled. * * @see ShortcutInfo#getDisabledMessage() */ @NonNull public Builder setDisabledMessage(@NonNull CharSequence disabledMessage) { Preconditions.checkState( mDisabledMessageResId == 0, "disabledMessageResId already set"); mDisabledMessage = Preconditions.checkStringNotEmpty(disabledMessage, "disabledMessage cannot be empty"); return this; }
Example 11
Source File: SaveInfo.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Builds a new {@link SaveInfo} instance. * * @throws IllegalStateException if no * {@link #SaveInfo.Builder(int, AutofillId[]) required ids} * or {@link #setOptionalIds(AutofillId[]) optional ids} were set */ public SaveInfo build() { throwIfDestroyed(); Preconditions.checkState( !ArrayUtils.isEmpty(mRequiredIds) || !ArrayUtils.isEmpty(mOptionalIds), "must have at least one required or optional id"); mDestroyed = true; return new SaveInfo(this); }
Example 12
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Optionally updating user restrictions, calculate the effective user restrictions and also * propagate to other services and system settings. * * @param newBaseRestrictions User restrictions to set. * If null, will not update user restrictions and only does the propagation. * @param userId target user ID. */ @GuardedBy("mRestrictionsLock") private void updateUserRestrictionsInternalLR( @Nullable Bundle newBaseRestrictions, int userId) { final Bundle prevAppliedRestrictions = UserRestrictionsUtils.nonNull( mAppliedUserRestrictions.get(userId)); // Update base restrictions. if (newBaseRestrictions != null) { // If newBaseRestrictions == the current one, it's probably a bug. final Bundle prevBaseRestrictions = mBaseUserRestrictions.get(userId); Preconditions.checkState(prevBaseRestrictions != newBaseRestrictions); Preconditions.checkState(mCachedEffectiveUserRestrictions.get(userId) != newBaseRestrictions); if (updateRestrictionsIfNeededLR(userId, newBaseRestrictions, mBaseUserRestrictions)) { scheduleWriteUser(getUserDataNoChecks(userId)); } } final Bundle effective = computeEffectiveUserRestrictionsLR(userId); mCachedEffectiveUserRestrictions.put(userId, effective); // Apply the new restrictions. if (DBG) { debug("Applying user restrictions: userId=" + userId + " new=" + effective + " prev=" + prevAppliedRestrictions); } if (mAppOpsService != null) { // We skip it until system-ready. mHandler.post(new Runnable() { @Override public void run() { try { mAppOpsService.setUserRestrictions(effective, mUserRestriconToken, userId); } catch (RemoteException e) { Log.w(LOG_TAG, "Unable to notify AppOpsService of UserRestrictions"); } } }); } propagateUserRestrictionsLR(userId, effective, prevAppliedRestrictions); mAppliedUserRestrictions.put(userId, new Bundle(effective)); }
Example 13
Source File: CharSequenceTransformation.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void throwIfDestroyed() { Preconditions.checkState(!mDestroyed, "Already called build()"); }
Example 14
Source File: SaveInfo.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Sets a custom description to be shown in the UI when the user is asked to save. * * <p>Typically used when the service must show more info about the object being saved, * like a credit card logo, masked number, and expiration date. * * @param customDescription the custom description. * @return This Builder. * * @throws IllegalStateException if this call was made after calling * {@link #setDescription(CharSequence)}. */ public @NonNull Builder setCustomDescription(@NonNull CustomDescription customDescription) { throwIfDestroyed(); Preconditions.checkState(mDescription == null, "Can call setDescription() or setCustomDescription(), but not both"); mCustomDescription = customDescription; return this; }
Example 15
Source File: SaveInfo.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Sets an optional description to be shown in the UI when the user is asked to save. * * <p>Typically, it describes how the data will be stored by the service, so it can help * users to decide whether they can trust the service to save their data. * * @param description a succint description. * @return This Builder. * * @throws IllegalStateException if this call was made after calling * {@link #setCustomDescription(CustomDescription)}. */ public @NonNull Builder setDescription(@Nullable CharSequence description) { throwIfDestroyed(); Preconditions.checkState(mCustomDescription == null, "Can call setDescription() or setCustomDescription(), but not both"); mDescription = description; return this; }
Example 16
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Sets the text of a shortcut. * * <p>This field is intended to be more descriptive than the shortcut title. The launcher * shows this instead of the short title when it has enough space. * * <p>The recommend maximum length is 25 characters. * * @see ShortcutInfo#getLongLabel() */ @NonNull public Builder setLongLabel(@NonNull CharSequence longLabel) { Preconditions.checkState(mTextResId == 0, "longLabelResId already set"); mText = Preconditions.checkStringNotEmpty(longLabel, "longLabel cannot be empty"); return this; }
Example 17
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Sets the short title of a shortcut. * * <p>This is a mandatory field when publishing a new shortcut with * {@link ShortcutManager#addDynamicShortcuts(List)} or * {@link ShortcutManager#setDynamicShortcuts(List)}. * * <p>This field is intended to be a concise description of a shortcut. * * <p>The recommended maximum length is 10 characters. * * @see ShortcutInfo#getShortLabel() */ @NonNull public Builder setShortLabel(@NonNull CharSequence shortLabel) { Preconditions.checkState(mTitleResId == 0, "shortLabelResId already set"); mTitle = Preconditions.checkStringNotEmpty(shortLabel, "shortLabel cannot be empty"); return this; }
Example 18
Source File: AutofillValue.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Gets the value to autofill a toggable field. * * <p>See {@link View#AUTOFILL_TYPE_TOGGLE} for more info.</p> * * @throws IllegalStateException if the value is not a toggle value */ public boolean getToggleValue() { Preconditions.checkState(isToggle(), "value must be a toggle value, not type=" + mType); return (Boolean) mValue; }
Example 19
Source File: AutofillValue.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Gets the value to autofill a selection list field. * * <p>See {@link View#AUTOFILL_TYPE_LIST} for more info.</p> * * @throws IllegalStateException if the value is not a list value */ public int getListValue() { Preconditions.checkState(isList(), "value must be a list value, not type=" + mType); return (Integer) mValue; }
Example 20
Source File: AutofillValue.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Gets the value to autofill a date field. * * <p>See {@link View#AUTOFILL_TYPE_DATE} for more info.</p> * * @throws IllegalStateException if the value is not a date value */ public long getDateValue() { Preconditions.checkState(isDate(), "value must be a date value, not type=" + mType); return (Long) mValue; }