Skip to content

Commit 5078079

Browse files
committed
core: Defy usage of NGA in Google Assistant
Next-Generation Assistant (NGA) is nice to have for Google Assistant, but it requires proprietary code in SystemUI to work properly. However, newer Pixel devices (Pixel 4 and 5 series) automatically use NGA with no way to opt out, which breaks the assistant entirely on custom ROMs without NGA support. Report the device as a "Pixel 3 XL" to the Google Assistant app during app process specialization to force the usage of the generic assistant UI and mitigate the issue. This is far from ideal, but we just need to make Google Assistant work for now. Screen-off voice match is not broken with this change because the model name still matches that of a valid device with the feature. Signed-off-by: Danny Lin <[email protected]> Change-Id: I282e7e88cfda50578f016b2ae0bad2e77e9a7238
1 parent 287b11e commit 5078079

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

core/java/com/android/internal/os/Zygote.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.net.LocalServerSocket;
2626
import android.net.LocalSocket;
2727
import android.net.NetworkUtils;
28+
import android.os.Build;
2829
import android.os.FactoryTest;
2930
import android.os.IVold;
3031
import android.os.Process;
@@ -46,6 +47,7 @@
4647
import java.io.FileDescriptor;
4748
import java.io.IOException;
4849
import java.io.InputStreamReader;
50+
import java.lang.reflect.Field;
4951

5052
/** @hide */
5153
public final class Zygote {
@@ -285,6 +287,9 @@ public final class Zygote {
285287
*/
286288
public static final String USAP_POOL_SECONDARY_SOCKET_NAME = "usap_pool_secondary";
287289

290+
private static final boolean PRODUCT_NEEDS_MODEL_EDIT =
291+
SystemProperties.getBoolean("ro.product.needs_model_edit", false);
292+
288293
private Zygote() {}
289294

290295
private static boolean containsInetGid(int[] gids) {
@@ -786,6 +791,34 @@ private static void boostUsapPriority() {
786791

787792
private static native void nativeBoostUsapPriority();
788793

794+
private static void maybeSetGoogleModel(String packageName, String loggingTag) {
795+
if (PRODUCT_NEEDS_MODEL_EDIT &&
796+
packageName != null &&
797+
packageName.startsWith("com.google.android.googlequicksearchbox")) {
798+
/*
799+
* This would be much prettier if we just removed "final" from the MODEL field in Build,
800+
* but that requires changing the API.
801+
*
802+
* While this an awful hack, it's technically safe because the field was populated at
803+
* runtime (in pre-fork Zygote) and it's not a primitive.
804+
*/
805+
try {
806+
// Unlock
807+
Field field = Build.class.getDeclaredField("MODEL");
808+
field.setAccessible(true);
809+
810+
// Edit
811+
String newModel = "Pixel 3 XL";
812+
field.set(null, newModel);
813+
814+
// Lock
815+
field.setAccessible(false);
816+
} catch (NoSuchFieldException | IllegalAccessException e) {
817+
Log.w(loggingTag, "Failed to set fake model name for Google", e);
818+
}
819+
}
820+
}
821+
789822
static void setAppProcessName(ZygoteArguments args, String loggingTag) {
790823
if (args.mNiceName != null) {
791824
Process.setArgV0(args.mNiceName);
@@ -794,6 +827,9 @@ static void setAppProcessName(ZygoteArguments args, String loggingTag) {
794827
} else {
795828
Log.w(loggingTag, "Unable to set package name.");
796829
}
830+
831+
// Modify model to defy Next-Generation Assistant in the Google app
832+
maybeSetGoogleModel(args.mPackageName, loggingTag);
797833
}
798834

799835
private static final String USAP_ERROR_PREFIX = "Invalid command to USAP: ";

0 commit comments

Comments
 (0)