Java Examples for com.android.internal.annotations.VisibleForTesting
The following java examples will help you to understand the usage of com.android.internal.annotations.VisibleForTesting. These source code samples are taken from different open source projects.
Example 1
| Project: platform_packages_providers_contactsprovider-master File: CallLogProvider.java View source code |
/**
* @param cursor to copy call log entries from
*/
@VisibleForTesting
long copyEntriesFromCursor(Cursor cursor, long lastSyncTime, boolean forShadow) {
long latestTimestamp = 0;
final ContentValues values = new ContentValues();
final SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransaction();
try {
final String[] args = new String[2];
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
values.clear();
DatabaseUtils.cursorRowToContentValues(cursor, values);
final String startTime = values.getAsString(Calls.DATE);
final String number = values.getAsString(Calls.NUMBER);
if (startTime == null || number == null) {
continue;
}
if (cursor.isLast()) {
try {
latestTimestamp = Long.valueOf(startTime);
} catch (NumberFormatException e) {
Log.e(TAG, "Call log entry does not contain valid start time: " + startTime);
}
}
// Avoid duplicating an already existing entry (which is uniquely identified by
// the number, and the start time)
args[0] = startTime;
args[1] = number;
if (DatabaseUtils.queryNumEntries(db, Tables.CALLS, Calls.DATE + " = ? AND " + Calls.NUMBER + " = ?", args) > 0) {
continue;
}
db.insert(Tables.CALLS, null, values);
}
if (latestTimestamp > lastSyncTime) {
setLastTimeSynced(latestTimestamp, forShadow);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return latestTimestamp;
}Example 2
| Project: platform_frameworks_base-master File: ConnectivityService.java View source code |
@VisibleForTesting
protected int reserveNetId() {
synchronized (mNetworkForNetId) {
for (int i = MIN_NET_ID; i <= MAX_NET_ID; i++) {
int netId = mNextNetId;
if (++mNextNetId > MAX_NET_ID)
mNextNetId = MIN_NET_ID;
// Make sure NetID unused. http://b/16815182
if (!mNetIdInUse.get(netId)) {
mNetIdInUse.put(netId, true);
return netId;
}
}
}
throw new IllegalStateException("No free netIds");
}Example 3
| Project: android-sdk-sources-for-api-level-23-master File: ImsCall.java View source code |
/**
* Report a new conference state to the current {@link ImsCall} and inform listeners of the
* change. Marked as {@code VisibleForTesting} so that the
* {@code com.android.internal.telephony.TelephonyTester} class can inject a test conference
* event package into a regular ongoing IMS call.
*
* @param state The {@link ImsConferenceState}.
*/
@VisibleForTesting
public void conferenceStateUpdated(ImsConferenceState state) {
Listener listener;
synchronized (this) {
notifyConferenceStateUpdated(state);
listener = mListener;
}
if (listener != null) {
try {
listener.onCallConferenceStateUpdated(this, state);
} catch (Throwable t) {
loge("callSessionConferenceStateUpdated :: ", t);
}
}
}Example 4
| Project: android_packages_apps_DocumentsUI-master File: RootsCache.java View source code |
@VisibleForTesting
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
final List<RootInfo> matching = Lists.newArrayList();
for (RootInfo root : roots) {
final boolean supportsCreate = (root.flags & Root.FLAG_SUPPORTS_CREATE) != 0;
final boolean advanced = (root.flags & Root.FLAG_ADVANCED) != 0;
final boolean localOnly = (root.flags & Root.FLAG_LOCAL_ONLY) != 0;
final boolean empty = (root.flags & Root.FLAG_EMPTY) != 0;
// Exclude read-only devices when creating
if (state.action == State.ACTION_CREATE && !supportsCreate)
continue;
// Exclude advanced devices when not requested
if (!state.showAdvanced && advanced)
continue;
// Exclude non-local devices when local only
if (state.localOnly && !localOnly)
continue;
// Only show empty roots when creating
if (state.action != State.ACTION_CREATE && empty)
continue;
// Only include roots that serve requested content
final boolean overlap = MimePredicate.mimeMatches(root.derivedMimeTypes, state.acceptMimes) || MimePredicate.mimeMatches(state.acceptMimes, root.derivedMimeTypes);
if (!overlap) {
continue;
}
matching.add(root);
}
return matching;
}Example 5
| Project: frameworks_opt-master File: ServiceStateTracker.java View source code |
@VisibleForTesting
public void updatePhoneType() {
mSS = new ServiceState();
mNewSS = new ServiceState();
mLastCellInfoListTime = 0;
mLastCellInfoList = null;
mSignalStrength = new SignalStrength();
mRestrictedState = new RestrictedState();
mStartedGprsRegCheck = false;
mReportedGprsNoReg = false;
mMdn = null;
mMin = null;
mPrlVersion = null;
mIsMinInfoReady = false;
mNitzUpdatedTime = false;
//cancel any pending pollstate request on voice tech switching
cancelPollState();
if (mPhone.isPhoneTypeGsm()) {
//clear CDMA registrations first
if (mCdmaSSM != null) {
mCdmaSSM.dispose(this);
}
mCi.unregisterForCdmaPrlChanged(this);
mPhone.unregisterForEriFileLoaded(this);
mCi.unregisterForCdmaOtaProvision(this);
mPhone.unregisterForSimRecordsLoaded(this);
mCellLoc = new GsmCellLocation();
mNewCellLoc = new GsmCellLocation();
mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
mCi.setOnRestrictedStateChanged(this, EVENT_RESTRICTED_STATE_CHANGED, null);
} else {
//clear GSM regsitrations first
mCi.unregisterForAvailable(this);
mCi.unSetOnRestrictedStateChanged(this);
mPhone.registerForSimRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
mCellLoc = new CdmaCellLocation();
mNewCellLoc = new CdmaCellLocation();
mCdmaSSM = CdmaSubscriptionSourceManager.getInstance(mPhone.getContext(), mCi, this, EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED, null);
mIsSubscriptionFromRuim = (mCdmaSSM.getCdmaSubscriptionSource() == CdmaSubscriptionSourceManager.SUBSCRIPTION_FROM_RUIM);
mCi.registerForCdmaPrlChanged(this, EVENT_CDMA_PRL_VERSION_CHANGED, null);
mPhone.registerForEriFileLoaded(this, EVENT_ERI_FILE_LOADED, null);
mCi.registerForCdmaOtaProvision(this, EVENT_OTA_PROVISION_STATUS_CHANGE, null);
mHbpcdUtils = new HbpcdUtils(mPhone.getContext());
// update OTASP state in case previously set by another service
updateOtaspState();
}
// This should be done after the technology specific initializations above since it relies
// on fields like mIsSubscriptionFromRuim (which is updated above)
onUpdateIccAvailability();
mPhone.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, ServiceState.rilRadioTechnologyToString(ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN));
// Query signal strength from the modem after service tracker is created (i.e. boot up,
// switching between GSM and CDMA phone), because the unsolicited signal strength
// information might come late or even never come. This will get the accurate signal
// strength information displayed on the UI.
mCi.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
sendMessage(obtainMessage(EVENT_PHONE_TYPE_SWITCHED));
logPhoneTypeChange();
// Tell everybody that we've thrown away state and are starting over with
// empty, detached ServiceStates.
mVoiceRoamingOffRegistrants.notifyRegistrants();
mDataRoamingOffRegistrants.notifyRegistrants();
mDetachedRegistrants.notifyRegistrants();
notifyDataRegStateRilRadioTechnologyChanged();
}Example 6
| Project: platform_packages_providers_telephonyprovider-master File: TelephonyBackupAgent.java View source code |
@VisibleForTesting
void putSmsMessagesToProvider(JsonReader jsonReader) throws IOException {
jsonReader.beginArray();
int msgCount = 0;
final int bulkInsertSize = mMaxMsgPerFile;
ContentValues[] values = new ContentValues[bulkInsertSize];
while (jsonReader.hasNext()) {
ContentValues cv = readSmsValuesFromReader(jsonReader);
if (doesSmsExist(cv)) {
continue;
}
values[(msgCount++) % bulkInsertSize] = cv;
if (msgCount % bulkInsertSize == 0) {
mContentResolver.bulkInsert(Telephony.Sms.CONTENT_URI, values);
}
}
if (msgCount % bulkInsertSize > 0) {
mContentResolver.bulkInsert(Telephony.Sms.CONTENT_URI, Arrays.copyOf(values, msgCount % bulkInsertSize));
}
jsonReader.endArray();
}Example 7
| Project: cnAndroidDocs-master File: MountService.java View source code |
@VisibleForTesting
public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
// Only adjust paths when storage is emulated
if (!Environment.isExternalStorageEmulated()) {
return canonicalPath;
}
String path = canonicalPath.toString();
// First trim off any external storage prefix
final UserEnvironment userEnv = new UserEnvironment(userId);
// /storage/emulated/0
final String externalPath = userEnv.getExternalStorageDirectory().toString();
// /storage/emulated_legacy
final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory().toString();
if (path.startsWith(externalPath)) {
path = path.substring(externalPath.length() + 1);
} else if (path.startsWith(legacyExternalPath)) {
path = path.substring(legacyExternalPath.length() + 1);
} else {
return canonicalPath;
}
// Handle special OBB paths on emulated storage
final String obbPath = "Android/obb";
if (path.startsWith(obbPath)) {
path = path.substring(obbPath.length() + 1);
if (forVold) {
return new File(Environment.getEmulatedStorageObbSource(), path).toString();
} else {
final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER);
return new File(ownerEnv.getExternalStorageObbDirectory(), path).toString();
}
}
// Handle normal external storage paths
if (forVold) {
return new File(Environment.getEmulatedStorageSource(userId), path).toString();
} else {
return new File(userEnv.getExternalStorageDirectory(), path).toString();
}
}Example 8
| Project: android_frameworks_base-master File: ApfFilter.java View source code |
/**
* Attempt to start listening for RAs and, if RAs are received, generating and installing
* filters to ignore useless RAs.
*/
@VisibleForTesting
void maybeStartFilter() {
FileDescriptor socket;
try {
mHardwareAddress = mNetworkInterface.getHardwareAddress();
synchronized (this) {
// Install basic filters
installNewProgramLocked();
}
socket = Os.socket(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
PacketSocketAddress addr = new PacketSocketAddress((short) ETH_P_IPV6, mNetworkInterface.getIndex());
Os.bind(socket, addr);
NetworkUtils.attachRaFilter(socket, mApfCapabilities.apfPacketFormat);
} catch (SocketExceptionErrnoException | e) {
Log.e(TAG, "Error starting filter", e);
return;
}
mReceiveThread = new ReceiveThread(socket);
mReceiveThread.start();
}Example 9
| Project: AndroidN-ify-master File: EmergencyListPreference.java View source code |
@Nullable
@VisibleForTesting
CharSequence[] getContentDescriptions() {
return mContentDescriptions;
}Example 10
| Project: qksms-master File: NetworkTemplate.java View source code |
@VisibleForTesting
public static void forceAllNetworkTypes() {
sForceAllNetworkTypes = true;
}Example 11
| Project: packages_apps_settings-master File: TetherService.java View source code |
@VisibleForTesting
void setUsageStatsManagerWrapper(UsageStatsManagerWrapper wrapper) {
mUsageManagerWrapper = wrapper;
}Example 12
| Project: android_packages_apps_Bluetooth-master File: GattService.java View source code |
@VisibleForTesting
long parseTimestampNanos(byte[] data) {
long timestampUnit = NumberUtils.littleEndianByteArrayToInt(data);
// Timestamp is in every 50 ms.
return TimeUnit.MILLISECONDS.toNanos(timestampUnit * 50);
}