Methods Summary |
---|
public android.hardware.display.WifiDisplay | applyWifiDisplayAlias(android.hardware.display.WifiDisplay display)
if (display != null) {
loadIfNeeded();
String alias = null;
int index = findRememberedWifiDisplay(display.getDeviceAddress());
if (index >= 0) {
alias = mRememberedWifiDisplays.get(index).getDeviceAlias();
}
if (!Objects.equal(display.getDeviceAlias(), alias)) {
return new WifiDisplay(display.getDeviceAddress(), display.getDeviceName(),
alias, display.isAvailable(), display.canConnect(), display.isRemembered());
}
}
return display;
|
public android.hardware.display.WifiDisplay[] | applyWifiDisplayAliases(android.hardware.display.WifiDisplay[] displays)
WifiDisplay[] results = displays;
if (results != null) {
int count = displays.length;
for (int i = 0; i < count; i++) {
WifiDisplay result = applyWifiDisplayAlias(displays[i]);
if (result != displays[i]) {
if (results == displays) {
results = new WifiDisplay[count];
System.arraycopy(displays, 0, results, 0, count);
}
results[i] = result;
}
}
}
return results;
|
private void | clearState()
mRememberedWifiDisplays.clear();
|
private int | findRememberedWifiDisplay(java.lang.String deviceAddress)
int count = mRememberedWifiDisplays.size();
for (int i = 0; i < count; i++) {
if (mRememberedWifiDisplays.get(i).getDeviceAddress().equals(deviceAddress)) {
return i;
}
}
return -1;
|
public boolean | forgetWifiDisplay(java.lang.String deviceAddress)
int index = findRememberedWifiDisplay(deviceAddress);
if (index >= 0) {
mRememberedWifiDisplays.remove(index);
setDirty();
return true;
}
return false;
|
public android.hardware.display.WifiDisplay | getRememberedWifiDisplay(java.lang.String deviceAddress)
loadIfNeeded();
int index = findRememberedWifiDisplay(deviceAddress);
if (index >= 0) {
return mRememberedWifiDisplays.get(index);
}
return null;
|
public android.hardware.display.WifiDisplay[] | getRememberedWifiDisplays()
loadIfNeeded();
return mRememberedWifiDisplays.toArray(new WifiDisplay[mRememberedWifiDisplays.size()]);
|
private void | load()
clearState();
final InputStream is;
try {
is = mAtomicFile.openRead();
} catch (FileNotFoundException ex) {
return;
}
XmlPullParser parser;
try {
parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(is), null);
loadFromXml(parser);
} catch (IOException ex) {
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
clearState();
} catch (XmlPullParserException ex) {
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
clearState();
} finally {
IoUtils.closeQuietly(is);
}
|
private void | loadFromXml(org.xmlpull.v1.XmlPullParser parser)
XmlUtils.beginDocument(parser, "display-manager-state");
final int outerDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
if (parser.getName().equals("remembered-wifi-displays")) {
loadRememberedWifiDisplaysFromXml(parser);
}
}
|
private void | loadIfNeeded()
if (!mLoaded) {
load();
mLoaded = true;
}
|
private void | loadRememberedWifiDisplaysFromXml(org.xmlpull.v1.XmlPullParser parser)
final int outerDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
if (parser.getName().equals("wifi-display")) {
String deviceAddress = parser.getAttributeValue(null, "deviceAddress");
String deviceName = parser.getAttributeValue(null, "deviceName");
String deviceAlias = parser.getAttributeValue(null, "deviceAlias");
if (deviceAddress == null || deviceName == null) {
throw new XmlPullParserException(
"Missing deviceAddress or deviceName attribute on wifi-display.");
}
if (findRememberedWifiDisplay(deviceAddress) >= 0) {
throw new XmlPullParserException(
"Found duplicate wifi display device address.");
}
mRememberedWifiDisplays.add(
new WifiDisplay(deviceAddress, deviceName, deviceAlias,
false, false, false));
}
}
|
public boolean | rememberWifiDisplay(android.hardware.display.WifiDisplay display)
loadIfNeeded();
int index = findRememberedWifiDisplay(display.getDeviceAddress());
if (index >= 0) {
WifiDisplay other = mRememberedWifiDisplays.get(index);
if (other.equals(display)) {
return false; // already remembered without change
}
mRememberedWifiDisplays.set(index, display);
} else {
mRememberedWifiDisplays.add(display);
}
setDirty();
return true;
|
private void | save()
final FileOutputStream os;
try {
os = mAtomicFile.startWrite();
boolean success = false;
try {
XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(new BufferedOutputStream(os), "utf-8");
saveToXml(serializer);
serializer.flush();
success = true;
} finally {
if (success) {
mAtomicFile.finishWrite(os);
} else {
mAtomicFile.failWrite(os);
}
}
} catch (IOException ex) {
Slog.w(TAG, "Failed to save display manager persistent store data.", ex);
}
|
public void | saveIfNeeded()
if (mDirty) {
save();
mDirty = false;
}
|
private void | saveToXml(org.xmlpull.v1.XmlSerializer serializer)
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, "display-manager-state");
serializer.startTag(null, "remembered-wifi-displays");
for (WifiDisplay display : mRememberedWifiDisplays) {
serializer.startTag(null, "wifi-display");
serializer.attribute(null, "deviceAddress", display.getDeviceAddress());
serializer.attribute(null, "deviceName", display.getDeviceName());
if (display.getDeviceAlias() != null) {
serializer.attribute(null, "deviceAlias", display.getDeviceAlias());
}
serializer.endTag(null, "wifi-display");
}
serializer.endTag(null, "remembered-wifi-displays");
serializer.endTag(null, "display-manager-state");
serializer.endDocument();
|
private void | setDirty()
mDirty = true;
|