Merge changes from topic 'vrmode'
* changes:
Set ui mode in UiModeManagerService to vrheadset when VR mode is enabled.
Introduce new UI_MODE_TYPE_VR_HEADSET and qualifier.
diff --git a/api/current.txt b/api/current.txt
index 49021dc..ec0faf4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -10567,6 +10567,7 @@
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
+ field public static final int UI_MODE_TYPE_VR_HEADSET = 7; // 0x7
field public static final int UI_MODE_TYPE_WATCH = 6; // 0x6
field public int densityDpi;
field public float fontScale;
diff --git a/api/system-current.txt b/api/system-current.txt
index 5d3a38c..8827279 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -11071,6 +11071,7 @@
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
+ field public static final int UI_MODE_TYPE_VR_HEADSET = 7; // 0x7
field public static final int UI_MODE_TYPE_WATCH = 6; // 0x6
field public int densityDpi;
field public float fontScale;
diff --git a/api/test-current.txt b/api/test-current.txt
index 115feb7..dcc693a 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -10598,6 +10598,7 @@
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
+ field public static final int UI_MODE_TYPE_VR_HEADSET = 7; // 0x7
field public static final int UI_MODE_TYPE_WATCH = 6; // 0x6
field public int densityDpi;
field public float fontScale;
diff --git a/core/java/android/app/UiModeManager.java b/core/java/android/app/UiModeManager.java
index 2e21729..2572a20 100644
--- a/core/java/android/app/UiModeManager.java
+++ b/core/java/android/app/UiModeManager.java
@@ -194,8 +194,9 @@
* {@link Configuration#UI_MODE_TYPE_DESK Configuration.UI_MODE_TYPE_DESK},
* {@link Configuration#UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR},
* {@link Configuration#UI_MODE_TYPE_TELEVISION Configuration.UI_MODE_TYPE_TELEVISION},
- * {@link Configuration#UI_MODE_TYPE_APPLIANCE Configuration.UI_MODE_TYPE_APPLIANCE}, or
- * {@link Configuration#UI_MODE_TYPE_WATCH Configuration.UI_MODE_TYPE_WATCH}.
+ * {@link Configuration#UI_MODE_TYPE_APPLIANCE Configuration.UI_MODE_TYPE_APPLIANCE},
+ * {@link Configuration#UI_MODE_TYPE_WATCH Configuration.UI_MODE_TYPE_WATCH}, or
+ * {@link Configuration#UI_MODE_TYPE_VR_HEADSET Configuration.UI_MODE_TYPE_VR_HEADSET}.
*/
public int getCurrentModeType() {
if (mService != null) {
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 227dc91..d44af7f 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -552,6 +552,11 @@
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_WATCH = 0x06;
+ /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
+ * value that corresponds to the
+ * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">vrheadset</a>
+ * resource qualifier. */
+ public static final int UI_MODE_TYPE_VR_HEADSET = 0x07;
/** Constant for {@link #uiMode}: bits that encode the night mode. */
public static final int UI_MODE_NIGHT_MASK = 0x30;
@@ -575,7 +580,8 @@
* device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
* {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
* {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION},
- * {@link #UI_MODE_TYPE_APPLIANCE}, or {@link #UI_MODE_TYPE_WATCH}.
+ * {@link #UI_MODE_TYPE_APPLIANCE}, {@link #UI_MODE_TYPE_WATCH},
+ * or {@link #UI_MODE_TYPE_VR_HEADSET}.
*
* <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
* is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
@@ -869,6 +875,7 @@
case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break;
case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break;
case UI_MODE_TYPE_WATCH: sb.append(" watch"); break;
+ case UI_MODE_TYPE_VR_HEADSET: sb.append(" vrheadset"); break;
default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break;
}
switch ((uiMode&UI_MODE_NIGHT_MASK)) {
@@ -1746,6 +1753,9 @@
case Configuration.UI_MODE_TYPE_WATCH:
parts.add("watch");
break;
+ case Configuration.UI_MODE_TYPE_VR_HEADSET:
+ parts.add("vrheadset");
+ break;
default:
break;
}
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 89581bb..db157bf 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -755,6 +755,7 @@
4 UI_MODE_TYPE_TELEVISION
5 UI_MODE_TYPE_APPLIANCE
6 UI_MODE_TYPE_WATCH
+ 7 UI_MODE_TYPE_VR_HEADSET
Any other values will have surprising consequences. -->
<integer name="config_defaultUiModeType">1</integer>
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 99aeb43..77e8d77 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -593,6 +593,7 @@
<code>television<br/>
<code>appliance</code>
<code>watch</code>
+ <code>vrheadset</code>
</td>
<td>
<ul class="nolist">
@@ -605,8 +606,9 @@
<li>{@code appliance}: Device is serving as an appliance, with
no display</li>
<li>{@code watch}: Device has a display and is worn on the wrist</li>
+ <li>{@code vrheadset}: Device has a virtual reality capable display and is showing the the apps UI on a virtual display</li>
</ul>
- <p><em>Added in API level 8, television added in API 13, watch added in API 20.</em></p>
+ <p><em>Added in API level 8, television added in API 13, watch added in API 20, vrheadset added in API 26.</em></p>
<p>For information about how your app can respond when the device is inserted into or
removed from a dock, read <a
href="{@docRoot}training/monitoring-device-state/docking-monitoring.html">Determining
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 907d914..7fbfffe 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -2994,6 +2994,9 @@
case ResTable_config::UI_MODE_TYPE_WATCH:
res.append("watch");
break;
+ case ResTable_config::UI_MODE_TYPE_VR_HEADSET:
+ res.append("vrheadset");
+ break;
default:
res.appendFormat("uiModeType=%d",
dtohs(screenLayout&ResTable_config::MASK_UI_MODE_TYPE));
diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h
index 08d6591..33b91b9 100644
--- a/libs/androidfw/include/androidfw/ResourceTypes.h
+++ b/libs/androidfw/include/androidfw/ResourceTypes.h
@@ -1102,6 +1102,7 @@
UI_MODE_TYPE_TELEVISION = ACONFIGURATION_UI_MODE_TYPE_TELEVISION,
UI_MODE_TYPE_APPLIANCE = ACONFIGURATION_UI_MODE_TYPE_APPLIANCE,
UI_MODE_TYPE_WATCH = ACONFIGURATION_UI_MODE_TYPE_WATCH,
+ UI_MODE_TYPE_VR_HEADSET = ACONFIGURATION_UI_MODE_TYPE_VR_HEADSET,
// uiMode bits for the night switch.
MASK_UI_MODE_NIGHT = 0x30,
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
index 5e1e1e0..440ac90 100644
--- a/services/core/java/com/android/server/UiModeManagerService.java
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -38,10 +38,13 @@
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.dreams.Sandman;
+import android.service.vr.IVrManager;
+import android.service.vr.IVrStateCallbacks;
import android.util.Slog;
import android.view.WindowManagerInternal;
import android.view.WindowManagerPolicy;
@@ -77,6 +80,7 @@
private boolean mDeskModeKeepsScreenOn;
private boolean mTelevision;
private boolean mWatch;
+ private boolean mVrHeadset;
private boolean mComputedNightMode;
private int mCarModeEnableFlags;
@@ -170,6 +174,18 @@
}
};
+ private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
+ @Override
+ public void onVrStateChanged(boolean enabled) {
+ synchronized (mLock) {
+ mVrHeadset = enabled;
+ if (mSystemReady) {
+ updateLocked(0, 0);
+ }
+ }
+ }
+ };
+
@Override
public void onStart() {
final Context context = getContext();
@@ -394,6 +410,7 @@
mSystemReady = true;
mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR;
updateComputedNightModeLocked();
+ registerVrStateListener();
updateLocked(0, 0);
}
}
@@ -441,6 +458,8 @@
uiMode = Configuration.UI_MODE_TYPE_CAR;
} else if (isDeskDockState(mDockState)) {
uiMode = Configuration.UI_MODE_TYPE_DESK;
+ } else if (mVrHeadset) {
+ uiMode = Configuration.UI_MODE_TYPE_VR_HEADSET;
}
if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
@@ -721,5 +740,15 @@
}
}
+ private void registerVrStateListener() {
+ IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService("vrmanager"));
+ try {
+ if (vrManager != null) {
+ vrManager.registerListener(mVrStateCallbacks);
+ }
+ } catch (RemoteException e) {
+ Slog.e(TAG, "Failed to register VR mode state listener: " + e);
+ }
+ }
}
diff --git a/tools/aapt/AaptConfig.cpp b/tools/aapt/AaptConfig.cpp
index b12867a..565d2f0 100644
--- a/tools/aapt/AaptConfig.cpp
+++ b/tools/aapt/AaptConfig.cpp
@@ -249,7 +249,10 @@
}
uint16_t minSdk = 0;
- if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) {
+ if ((config->uiMode & ResTable_config::MASK_UI_MODE_TYPE)
+ == ResTable_config::UI_MODE_TYPE_VR_HEADSET) {
+ minSdk = SDK_O;
+ } else if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) {
minSdk = SDK_MNC;
} else if (config->density == ResTable_config::DENSITY_ANY) {
minSdk = SDK_LOLLIPOP;
@@ -477,6 +480,11 @@
(out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
| ResTable_config::UI_MODE_TYPE_WATCH;
return true;
+ } else if (strcmp(name, "vrheadset") == 0) {
+ if (out) out->uiMode =
+ (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
+ | ResTable_config::UI_MODE_TYPE_VR_HEADSET;
+ return true;
}
return false;
diff --git a/tools/aapt/SdkConstants.h b/tools/aapt/SdkConstants.h
index 16e622a..d92de06 100644
--- a/tools/aapt/SdkConstants.h
+++ b/tools/aapt/SdkConstants.h
@@ -39,6 +39,9 @@
SDK_LOLLIPOP = 21,
SDK_LOLLIPOP_MR1 = 22,
SDK_MNC = 23,
+ SDK_NOUGAT = 24,
+ SDK_NOUGAT_MR1 = 25,
+ SDK_O = 26, // STOPSHIP replace with real version
};
#endif // H_AAPT_SDK_CONSTANTS
diff --git a/tools/aapt2/ConfigDescription.cpp b/tools/aapt2/ConfigDescription.cpp
index 289919a3..b1bd401 100644
--- a/tools/aapt2/ConfigDescription.cpp
+++ b/tools/aapt2/ConfigDescription.cpp
@@ -254,6 +254,11 @@
out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) |
ResTable_config::UI_MODE_TYPE_WATCH;
return true;
+ } else if (strcmp(name, "vrheadset") == 0) {
+ if (out)
+ out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) |
+ ResTable_config::UI_MODE_TYPE_VR_HEADSET;
+ return true;
}
return false;
@@ -772,7 +777,10 @@
void ConfigDescription::ApplyVersionForCompatibility(
ConfigDescription* config) {
uint16_t min_sdk = 0;
- if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) {
+ if ((config->uiMode & ResTable_config::MASK_UI_MODE_TYPE)
+ == ResTable_config::UI_MODE_TYPE_VR_HEADSET) {
+ min_sdk = SDK_O;
+ } else if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) {
min_sdk = SDK_MARSHMALLOW;
} else if (config->density == ResTable_config::DENSITY_ANY) {
min_sdk = SDK_LOLLIPOP;
diff --git a/tools/aapt2/ConfigDescription_test.cpp b/tools/aapt2/ConfigDescription_test.cpp
index c331dc0..1d22ce0 100644
--- a/tools/aapt2/ConfigDescription_test.cpp
+++ b/tools/aapt2/ConfigDescription_test.cpp
@@ -99,4 +99,12 @@
EXPECT_EQ(std::string("notround-v23"), config.toString().string());
}
+TEST(ConfigDescriptionTest, ParseVrAttribute) {
+ ConfigDescription config;
+ EXPECT_TRUE(TestParse("vrheadset", &config));
+ EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_VR_HEADSET, config.uiMode);
+ EXPECT_EQ(SDK_O, config.sdkVersion);
+ EXPECT_EQ(std::string("vrheadset-v26"), config.toString().string());
+}
+
} // namespace aapt
diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h
index 9b38ecb..5352b53 100644
--- a/tools/aapt2/SdkConstants.h
+++ b/tools/aapt2/SdkConstants.h
@@ -45,6 +45,9 @@
SDK_LOLLIPOP = 21,
SDK_LOLLIPOP_MR1 = 22,
SDK_MARSHMALLOW = 23,
+ SDK_NOUGAT = 24,
+ SDK_NOUGAT_MR1 = 25,
+ SDK_O = 26, // STOPSHIP Replace with real version
};
size_t FindAttributeSdkLevel(const ResourceId& id);