Java Code Examples for androidx.annotation.VisibleForTesting#PACKAGE_PRIVATE

The following examples show how to use androidx.annotation.VisibleForTesting#PACKAGE_PRIVATE . 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: Component.java    From litho with Apache License 2.0 6 votes vote down vote up
/** Called to install internal state based on a component's parent context. */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
protected void updateInternalChildState(ComponentContext parentContext) {
  if (ComponentsConfiguration.isDebugModeEnabled || ComponentsConfiguration.useGlobalKeys) {
    if (getGlobalKey() == null) {
      final String globalKey;
      if (ComponentsConfiguration.useNewGenerateMechanismForGlobalKeys) {
        globalKey = LayoutState.generateGlobalKey(parentContext, this);
      } else {
        globalKey = ComponentKeyUtils.generateGlobalKey(parentContext.getComponentScope(), this);
      }
      setGlobalKey(globalKey);
    }
  }

  applyStateUpdates(parentContext);
  generateErrorEventHandler(parentContext);

  // Needed for tests, mocks can run into this.
  if (mLayoutVersionGenerator != null) {
    mLayoutVersionGenerator.set(true);
  }
}
 
Example 2
Source File: SectionContext.java    From litho with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public static SectionContext withSectionTree(SectionContext context, SectionTree sectionTree) {
  SectionContext sectionContext = new SectionContext(context);
  sectionContext.mSectionTree = sectionTree;
  sectionContext.mTreeLoadingEventHandler = new SectionTreeLoadingEventHandler(sectionTree);

  return sectionContext;
}
 
Example 3
Source File: FitbitGatt.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public synchronized void putConnectionIntoDevices(FitbitBluetoothDevice device, GattConnection conn) {
    // we don't want duplicate connections in the map
    if (!connectionMap.containsKey(device)) {
        connectionMap.put(device, conn);
        // since this directly calls notify listeners of connection added
        // we will need to synchronize around those listeners since
        // someone could be adding or removing a listener while this asynchronous
        // call happens.  To do this easily, we will use a
        // CopyOnWriteArrayList for the {@link FitbitGattCallback}
        FitbitGatt.getInstance().notifyListenersOfConnectionAdded(conn);
    }
}
 
Example 4
Source File: InvalidationTracker.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Notifies all the registered {@link Observer}s of table changes.
 * <p>
 * This can be used for notifying invalidation that cannot be detected by this
 * {@link InvalidationTracker}, for example, invalidation from another process.
 *
 * @param tables The invalidated tables.
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void notifyObserversByTableNames(String... tables) {
    synchronized (mObserverMap) {
        for (Map.Entry<Observer, ObserverWrapper> entry : mObserverMap) {
            if (!entry.getKey().isRemote()) {
                entry.getValue().notifyByTableNames(tables);
            }
        }
    }
}
 
Example 5
Source File: ComponentContext.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ComponentContext instance and sets the {@link ComponentTree} on the component.
 *
 * @param context context scoped to the parent component
 * @param componentTree component tree associated with the newly created context
 * @return a new ComponentContext instance
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public static ComponentContext withComponentTree(
    ComponentContext context, ComponentTree componentTree) {
  ComponentContext componentContext =
      new ComponentContext(context, new StateHandler(), null, null);
  componentContext.mComponentTree = componentTree;
  componentContext.mComponentScope = null;

  return componentContext;
}
 
Example 6
Source File: Change.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * @return the Component that will render this Change (if this Change is either an INSERT or an
 *     UPDATE).
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public RenderInfo getRenderInfo() {
  return mRenderInfo;
}
 
Example 7
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void setChildren(Children children) {
  mChildren = children == null ? new ArrayList<Section>() : children.getChildren();
}
 
Example 8
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/** @return the direct children of this {@link Section}. */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public List<Section> getChildren() {
  return mChildren;
}
 
Example 9
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the total number of {@link com.facebook.litho.Component} that the subtree of {@link
 * Section}s having its root in this {@link Section} generated.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void setCount(int count) {
  mCount = count;
}
 
Example 10
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * @return te total number of {@link com.facebook.litho.Component} that the subtree of {@link
 *     Section}s having its root in this {@link Section} generated.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
int getCount() {
  return mCount;
}
 
Example 11
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the key for this Section. This is only used for testing as the key will be set from the
 * {@link Builder}
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void setKey(String key) {
  mKey = key;
}
 
Example 12
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/** Set a unique key for this {@link Section} within its tree. */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void setGlobalKey(String key) {
  mGlobalKey = key;
}
 
Example 13
Source File: Section.java    From litho with Apache License 2.0 4 votes vote down vote up
/** @return a unique key for this {@link Section} within its tree. */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public String getGlobalKey() {
  return mGlobalKey;
}
 
Example 14
Source File: Children.java    From litho with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public List<Section> getChildren() {
  return mSections;
}
 
Example 15
Source File: ViewController.java    From react-native-navigation with MIT License 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void ensureViewIsCreated() {
    getView();
}
 
Example 16
Source File: AbtComponent.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** Firebase ABT Component constructor. */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
protected AbtComponent(Context appContext, AnalyticsConnector analyticsConnector) {
  this.appContext = appContext;
  this.analyticsConnector = analyticsConnector;
}
 
Example 17
Source File: GattTransaction.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Will execute the transaction's discreet operations, will return before executing all transactions
 * if a transaction status of fail or timeout is returned before the last transaction, transactions
 * will be executed in the order that they were added.
 * <p>
 * All transaction callbacks will occur on the fbgatt thread associated with the connection,
 * unless they are performing GATT operations which will result on the callback being delivered
 * on the main thread.  If the user needs to transition back to the main thread for a non-gatt
 * operation, they will have to make that transition themselves.
 */
@VisibleForTesting( otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void commit(GattTransactionCallback callback) {
    // get main looper would only be null in a test, unless mocked
    // we have to do all of this null checking for connection because of a contract with fbairlink
    // that makes the transaction connection constructor accept null, we should review this
    // contract after the launch of Golden Gate.
    Looper mainLooper = this.appContext.getMainLooper();
    if(getConnection() != null && getConnection().getClientTransactionQueueController() != null) {
        if (mainLooper != null &&
                (Thread.currentThread().equals(mainLooper.getThread()))) {
            throw new IllegalStateException(String.format(Locale.ENGLISH,
                    "[%s] This transaction %s is not allowed to run on the %s thread",
                    getDevice(),
                    getName(),
                    mainLooper.getThread()));
        }
    } else if(getGattServer() != null && getGattServer().getServerTransactionQueueController() != null) {
        if (mainLooper != null &&
                (Thread.currentThread().equals(mainLooper.getThread()))) {
            throw new IllegalStateException(String.format(Locale.ENGLISH,
                    "[%s] This transaction %s is not allowed to run on the %s thread",
                    getDevice(),
                    getName(),
                    mainLooper.getThread()));
        }
    } else {
        throw new IllegalStateException(String.format(Locale.ENGLISH, "[%s] This transaction can not be run because there is no connection to support it", getDevice()));
    }
    if (taskHasStarted.getAndSet(true)) {
        throw new IllegalStateException(String.format(Locale.ENGLISH, "[%s] This transaction was already started!", getDevice()));
    }
    // let's allocate the array to the proper size ( why let it grow and waste cycles )
    ArrayList<GattTransaction> transactions = new ArrayList<>(preCommitHooks.size() + postCommitHooks.size() + 1);
    // if this is a composite transaction, we will want to make sure that while intermediate callbacks can be called back
    // we hold a reference to the parent tx and call it on tx complete
    synchronized (hookLock) {
        this.callback = callback;
        transactions.addAll(preCommitHooks);
        transactions.add(this);
        transactions.addAll(postCommitHooks);
    }
    // the entire transaction must complete in {@link timeout} time.
    scheduleTransactionTimeout(this, callback);
    while (!transactions.isEmpty()) {
        GattTransaction tx = transactions.remove(0);
        if (!areConditionsValidForExecution(tx)) {
            if (connection != null) {
                Timber.i("[%s] The transaction couldn't be run because the connection is in %s state", getDevice(), connection.getGattState());
            } else {
                Timber.w("[%s] The transaction couldn't be run because there is no connection", getDevice());
            }
            return;
        }
        if (this.haltChain) {
            Timber.w("[%s] We are aborting the chain because a transaction failed", getDevice());
            return;
        }
        executeTransaction(tx, callback);
        // in the case of the composite transaction, this can lead to the composite transaction
        // scheduler being interrupted which will throw on await.  If we are cancelled at this
        // point, we should quietly end.
        if(!Thread.currentThread().isAlive() || Thread.currentThread().isInterrupted()) {
            Timber.i("Already stopped");
            return;
        }
        try {
            cdl.await(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            Timber.d("Transaction was interrupted while waiting for result, re-interrupting thread : %s", Thread.currentThread().getName());
            Thread.currentThread().interrupt();
            return;
        }
    }
    if (FitbitGatt.getInstance().isSlowLoggingEnabled()) {
        Timber.v("[%s] Completed running all pre-commit, post-commit, and main transactions", getDevice());
    }
}
 
Example 18
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
String getStringRepresentationOfPermissionsForCharacteristic(BluetoothGattCharacteristic characteristic) {
    StringBuilder permissionBuilder = new StringBuilder();
    ArrayList<Integer> permissions = new ArrayList<>(8);
    int characteristicPermissions = characteristic.getPermissions();
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_READ) == BluetoothGattCharacteristic.PERMISSION_READ) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_READ);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED) == BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM) == BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_WRITE) == BluetoothGattCharacteristic.PERMISSION_WRITE) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_WRITE);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED) == BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM) == BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED) == BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED);
    }
    if ((characteristicPermissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM) == BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM) {
        permissions.add(BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM);
    }
    for (int i = 0; i < permissions.size(); i++) {
        int permission = permissions.get(i);
        switch (permission) {
            case BluetoothGattCharacteristic.PERMISSION_READ:
                permissionBuilder.append("read");
                break;
            case BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED:
                permissionBuilder.append("read-encrypted");
                break;
            case BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM:
                permissionBuilder.append("read-encrypted-mitm");
                break;
            case BluetoothGattCharacteristic.PERMISSION_WRITE:
                permissionBuilder.append("write");
                break;
            case BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED:
                permissionBuilder.append("write-encrypted");
                break;
            case BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM:
                permissionBuilder.append("write-encrypted-mitm");
                break;
            case BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED:
                permissionBuilder.append("write-signed");
                break;
            case BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM:
                permissionBuilder.append("write-signed-mitm");
                break;
            default:
                permissionBuilder.append("unknown");
        }
        if (i < permissions.size() - 1) {
            permissionBuilder.append(", ");
        }
    }
    return permissionBuilder.toString();
}
 
Example 19
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
String getStringRepresentationOfPropertiesForCharacteristic(BluetoothGattCharacteristic characteristic) {
    StringBuilder propertyBuilder = new StringBuilder();
    ArrayList<Integer> properties = new ArrayList<>(8);
    int characteristicProperties = characteristic.getProperties();
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_READ) == BluetoothGattCharacteristic.PROPERTY_READ) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_READ);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) == BluetoothGattCharacteristic.PROPERTY_WRITE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_WRITE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) == BluetoothGattCharacteristic.PROPERTY_BROADCAST) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_BROADCAST);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) == BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_INDICATE) == BluetoothGattCharacteristic.PROPERTY_INDICATE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_INDICATE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_NOTIFY);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) == BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE);
    }
    for (int i = 0; i < properties.size(); i++) {
        int property = properties.get(i);
        switch (property) {
            case BluetoothGattCharacteristic.PROPERTY_READ:
                propertyBuilder.append("read");
                break;
            case BluetoothGattCharacteristic.PROPERTY_WRITE:
                propertyBuilder.append("write");
                break;
            case BluetoothGattCharacteristic.PROPERTY_BROADCAST:
                propertyBuilder.append("broadcast");
                break;
            case BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS:
                propertyBuilder.append("extended-props");
                break;
            case BluetoothGattCharacteristic.PROPERTY_NOTIFY:
                propertyBuilder.append("notify");
                break;
            case BluetoothGattCharacteristic.PROPERTY_INDICATE:
                propertyBuilder.append("indicate");
                break;
            case BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE:
                propertyBuilder.append("write-signed");
                break;
            case BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE:
                propertyBuilder.append("write-no-response");
                break;
            default:
                propertyBuilder.append("unknown");
        }
        if (i < properties.size() - 1) {
            propertyBuilder.append(", ");
        }
    }
    return propertyBuilder.toString();
}
 
Example 20
Source File: BraintreeFragment.java    From braintree_android with MIT License 2 votes vote down vote up
/**
 * Check if this Braintree fragment is still active.
 *
 * @return {@code true} if still active and process can proceed, {@code false} otherwise.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public boolean isActive() {
    return isAdded();
}