use of java.util.BitSet in project android_frameworks_base by ResurrectionRemix.
the class GlobalActions method setupAirplaneModeListeners.
/**
* Since there are two ways of handling airplane mode (with telephony, we depend on the internal
* device telephony state), and MSIM devices do not report phone state for missing SIMs, we
* need to dynamically setup listeners based on subscription changes.
*
* So if there is _any_ active SIM in the device, we can depend on the phone state,
* otherwise fall back to {@link Settings.Global#AIRPLANE_MODE_ON}.
*/
private void setupAirplaneModeListeners() {
TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
for (PhoneStateListener listener : mPhoneStateListeners) {
telephonyManager.listen(listener, PhoneStateListener.LISTEN_NONE);
}
mPhoneStateListeners.clear();
final List<SubscriptionInfo> subInfoList = SubscriptionManager.from(mContext).getActiveSubscriptionInfoList();
if (subInfoList != null) {
mHasTelephony = true;
mAirplaneModeBits = new BitSet(subInfoList.size());
for (int i = 0; i < subInfoList.size(); i++) {
final int finalI = i;
PhoneStateListener subListener = new PhoneStateListener(subInfoList.get(finalI).getSubscriptionId()) {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
mAirplaneModeBits.set(finalI, inAirplaneMode);
// we're in airplane mode if _any_ of the subscriptions say we are
mAirplaneState = mAirplaneModeBits.cardinality() > 0 ? ToggleAction.State.On : ToggleAction.State.Off;
mAirplaneModeOn.updateState(mAirplaneState);
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
};
mPhoneStateListeners.add(subListener);
telephonyManager.listen(subListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}
} else {
mHasTelephony = false;
}
// Set the initial status of airplane mode toggle
mAirplaneState = getUpdatedAirplaneToggleState();
}
use of java.util.BitSet in project Railcraft by Railcraft.
the class TrackKitLocking method readPacketData.
@Override
public void readPacketData(DataInputStream data) throws IOException {
super.readPacketData(data);
LockingProfileType p = LockingProfileType.fromOrdinal(data.readByte());
if (profile != p) {
profile = p;
profileInstance = p.create(this);
}
BitSet bits = BitSet.valueOf(new byte[] { data.readByte() });
redstone = bits.get(0);
locked = bits.get(1);
justLoaded = bits.get(2);
profileInstance.readPacketData(data);
markBlockNeedsUpdate();
}
use of java.util.BitSet in project android_frameworks_base by ResurrectionRemix.
the class WifiConfiguration method readBitSet.
private static BitSet readBitSet(Parcel src) {
int cardinality = src.readInt();
BitSet set = new BitSet();
for (int i = 0; i < cardinality; i++) {
set.set(src.readInt());
}
return set;
}
use of java.util.BitSet in project android_frameworks_base by ResurrectionRemix.
the class ModelTest method testModelIdIsUnique.
// Tests multiple authorities with clashing document IDs.
public void testModelIdIsUnique() {
MatrixCursor cIn1 = new MatrixCursor(COLUMNS);
MatrixCursor cIn2 = new MatrixCursor(COLUMNS);
// Make two sets of items with the same IDs, under different authorities.
final String AUTHORITY0 = "auth0";
final String AUTHORITY1 = "auth1";
for (int i = 0; i < ITEM_COUNT; ++i) {
MatrixCursor.RowBuilder row0 = cIn1.newRow();
row0.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY0);
row0.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
MatrixCursor.RowBuilder row1 = cIn2.newRow();
row1.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY1);
row1.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
}
Cursor cIn = new MergeCursor(new Cursor[] { cIn1, cIn2 });
// Update the model, then make sure it contains all the expected items.
DirectoryResult r = new DirectoryResult();
r.cursor = cIn;
model.update(r);
assertEquals(ITEM_COUNT * 2, model.getItemCount());
BitSet b0 = new BitSet(ITEM_COUNT);
BitSet b1 = new BitSet(ITEM_COUNT);
for (String id : model.getModelIds()) {
Cursor cOut = model.getItem(id);
String authority = DocumentInfo.getCursorString(cOut, RootCursorWrapper.COLUMN_AUTHORITY);
String docId = DocumentInfo.getCursorString(cOut, Document.COLUMN_DOCUMENT_ID);
switch(authority) {
case AUTHORITY0:
b0.set(Integer.parseInt(docId));
break;
case AUTHORITY1:
b1.set(Integer.parseInt(docId));
break;
default:
fail("Unrecognized authority string");
}
}
assertEquals(ITEM_COUNT, b0.cardinality());
assertEquals(ITEM_COUNT, b1.cardinality());
}
use of java.util.BitSet in project UltimateAndroid by cymcsg.
the class AbstractSlideExpandableListAdapter method readBitSet.
/**
* Utility methods to read and write a bitset from and to a Parcel
*/
private static BitSet readBitSet(Parcel src) {
BitSet set = new BitSet();
if (src == null) {
return set;
}
int cardinality = src.readInt();
for (int i = 0; i < cardinality; i++) {
set.set(src.readInt());
}
return set;
}
Aggregations