Skip to content

Commit

Permalink
Elmyra: initial base for the service porting
Browse files Browse the repository at this point in the history
All right, this is a huge commit - but don't be afraid, we will strip
out all the unecessary classes.

You are probably wondering "From where did you get the motivation from
decompiling, deobfuscating the classes and make them working on AOSP?".
Simple, the Pixel 2 / 3 got shipped with a hardware sensor that allows
to squeeze the device and trigger some nice actions, I just don't
understand why Google wanted to make all these stuff proprietary even
though it's something that comes up with the device? Complete non-sense,
so I wanted to give this a try and I have managed to get a base working.

As a first step I wanted to keep everything clean and I tried to stay
away from all the bloat, so here's what I have done:

- Decompiled SystemUIGoogle and tried to figure out how this Elmyra
service was working. The tools I have used are dex2jar, Jadx (for
getting a neat android base to work with) and Procyon for more low-level
classes (like Google's protobuf);
- My approach it's been to aim to get the service working, so after
decompiling the classes I started looking on the proprietary blobs
needed for this to work and luckily enough they were just a few;
- Completely skipping the OPA and Settings classes helped me A LOT in
the tracking process and so here I am with a service that fires up and
listens for sensor calls through JNI.

Please, keep in mind that these classes are pretty much machine-like as
they were decompiled and reworked to properly compile with the Android
environment, we need to clean up this base and I am sure we will make
it.

Last but not least, right now the service is being called through a
SystemUI process that calls the GoogleServices class and all the actions
available have been commented out and hardcoded with a small Action I
wrote based on a simple class that was already there; this class is
called Flashlight and allows to trigger the torchlight through our
ActionUtils class.

Change-Id: Icccbbe6b305851628d214fa1f8df873add3c9670
  • Loading branch information
Jertlok authored and Alex committed Feb 13, 2019
1 parent e88e0dd commit e0d49eb
Show file tree
Hide file tree
Showing 106 changed files with 8,249 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/SystemUI/AndroidManifest.xml
Expand Up @@ -642,5 +642,38 @@
</intent-filter>
</receiver>

<service
android:exported="true"
android:name="com.google.android.systemui.elmyra.ElmyraServiceProxy"
android:permission="com.google.android.elmyra.permission.CONFIGURE_ASSIST_GESTURE"/>

</application>

<!-- Elmyra service -->
<permission
android:name="com.android.systemui.permission.SEND_ALERT_BROADCASTS"
android:protectionLevel="preinstalled|signature" />
<permission
android:name="com.google.sensor.elmyra.permission.USE_RAW_SENSOR"
android:protectionLevel="preinstalled|signature" />
<permission
android:name="com.google.sensor.elmyra.permission.USE_SENSOR"
android:protectionLevel="preinstalled|signature" />
<permission
android:name="com.google.android.elmyra.permission.CONFIGURE_ASSIST_GESTURE"
android:protectionLevel="signature" />
<permission
android:name="com.google.android.ambientindication.permission.AMBIENT_INDICATION"
android:protectionLevel="privileged|signature" />

<uses-permission android:name="android.permission.CONFIGURE_ASSIST_GESTURE" />
<uses-permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS" />
<uses-permission android:name="android.permission.REVOKE_RUNTIME_PERMISSIONS" />
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="com.google.android.deskclock.permission.RECEIVE_ALERT_BROADCASTS" />
<uses-permission android:name="com.google.sensor.elmyra.permission.USE_RAW_SENSOR" />
<uses-permission android:name="com.google.sensor.elmyra.permission.USE_SENSOR" />
<uses-permission android:name="com.google.android.elmyra.permission.CONFIGURE_ASSIST_GESTURE" />

</manifest>
Empty file.
2 changes: 2 additions & 0 deletions packages/SystemUI/res/values/config.xml
Expand Up @@ -350,6 +350,8 @@
<item>com.android.systemui.ScreenDecorations</item>
<item>com.android.systemui.fingerprint.FingerprintDialogImpl</item>
<item>com.android.systemui.SliceBroadcastRelayHandler</item>
<!-- Google's service for Elmyra -->
<item>com.google.android.systemui.GoogleServices</item>
</string-array>

<!-- SystemUI vender service, used in config_systemUIServiceComponents. -->
Expand Down
26 changes: 26 additions & 0 deletions packages/SystemUI/res/values/du_arrays.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Elmyra -->
<integer-array name="elmyra_blocking_system_keys">
<item>24</item>
<item>25</item>
<item>26</item>
</integer-array>
<integer-array name="elmyra_lower_threshold">
<item>-450</item>
<item>-650</item>
</integer-array>
<integer-array name="elmyra_slope_sensitivity">
<item>46</item>
<item>46</item>
</integer-array>
<integer-array name="elmyra_time_window">
<item>1000</item>
<item>1000</item>
</integer-array>
<integer-array name="elmyra_upper_threshold">
<item>4000</item>
<item>14000</item>
</integer-array>

</resources>
6 changes: 6 additions & 0 deletions packages/SystemUI/res/values/du_dimens.xml
Expand Up @@ -34,4 +34,10 @@
<dimen name="net_traffic_multi_text_size">8dp</dimen>
<dimen name="net_traffic_txt_img_padding">2dp</dimen>

<!-- Elmyra -->
<item type="dimen" name="elmyra_progress_alpha">0.35</item>
<item type="dimen" name="elmyra_progress_detect_threshold">0.5</item>
<item type="dimen" name="elmyra_progress_report_threshold">0.55</item>
<item type="dimen" name="elmyra_screen_off_adjustment">-0.1</item>

</resources>
11 changes: 11 additions & 0 deletions packages/SystemUI/res/values/du_ids.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Elmyra -->
<item type="id" name="elmyra_feedback_background"/>
<item type="id" name="elmyra_feedback_blue"/>
<item type="id" name="elmyra_feedback_green"/>
<item type="id" name="elmyra_feedback_red"/>
<item type="id" name="elmyra_feedback_view"/>
<item type="id" name="elmyra_feedback_yellow"/>

</resources>
14 changes: 14 additions & 0 deletions packages/SystemUI/res/values/du_integers.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Elmyra -->
<integer name="elmyra_charging_gate_duration">500</integer>
<integer name="elmyra_false_prime_window">50</integer>
<integer name="elmyra_gesture_cooldown_time">450</integer>
<integer name="elmyra_keyguard_proximity_threshold">5</integer>
<integer name="elmyra_snapshot_gesture_delay_ms">100</integer>
<integer name="elmyra_snapshot_logger_gesture_size">10</integer>
<integer name="elmyra_snapshot_logger_incomplete_gesture_size">10</integer>
<integer name="elmyra_system_key_gate_duration">500</integer>
<integer name="elmyra_usb_gate_duration">500</integer>

</resources>
4 changes: 4 additions & 0 deletions packages/SystemUI/res/values/du_strings.xml
Expand Up @@ -118,4 +118,8 @@
<string name="navigation_bar_height_tablets_landscape_title">Height (landscape)</string>
<string name="navigation_bar_width_title">Width</string>

<!-- Elmyra -->
<string name="elmyra_raw_sensor_string_type">com.google.sensor.elmyra.raw</string>

This comment has been minimized.

Copy link
@penn5

penn5 Feb 14, 2019

Pretty sure you want translatable=false on these?

This comment has been minimized.

Copy link
@BoredOutOfMyGit

BoredOutOfMyGit Feb 14, 2019

Member

Just to give you a heads up. That was removed because is not used.

See our external/google repo @penn5

https://github.com/DirtyUnicorns/android_external_google

<string name="google_camera_app_package_name">com.google.android.GoogleCamera</string>

</resources>
@@ -0,0 +1,53 @@
package com.google.android.systemui;

import com.android.systemui.Dumpable;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.VendorServices;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.StatusBar;
// import com.google.android.systemui.ambientmusic.AmbientIndicationContainer;
// import com.google.android.systemui.ambientmusic.AmbientIndicationService;
// import com.google.android.systemui.dreamliner.DockObserver;
import com.google.android.systemui.elmyra.ElmyraContext;
import com.google.android.systemui.elmyra.ElmyraService;
import com.google.android.systemui.elmyra.ServiceConfigurationGoogle;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;

public class GoogleServices extends VendorServices {
private ArrayList<Object> mServices = new ArrayList();

private void addService(Object obj) {
if (obj != null) {
this.mServices.add(obj);
}
}

public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
int i = 0;
while (true) {
int i2 = i;
if (i2 < this.mServices.size()) {
if (this.mServices.get(i2) instanceof Dumpable) {
((Dumpable) this.mServices.get(i2)).dump(fileDescriptor, printWriter, strArr);
}
i = i2 + 1;
} else {
return;
}
}
}

public void start() {
StatusBar statusBar = (StatusBar) SysUiServiceProvider.getComponent(this.mContext, StatusBar.class);
// AmbientIndicationContainer ambientIndicationContainer = (AmbientIndicationContainer) statusBar.getStatusBarWindow().findViewById(R.id.ambient_indication_container);
// ambientIndicationContainer.initializeView(statusBar);
// addService(new AmbientIndicationService(this.mContext, ambientIndicationContainer));
// addService(new DisplayCutoutEmulationAdapter(this.mContext));
// addService(new DockObserver(this.mContext));
if (new ElmyraContext(this.mContext).isAvailable()) {
addService(new ElmyraService(this.mContext, new ServiceConfigurationGoogle(this.mContext)));
}
}
}
@@ -0,0 +1,15 @@
package com.google.android.systemui.elmyra;

import android.content.Context;

public final class ElmyraContext {
private Context mContext;

public ElmyraContext(Context context) {
this.mContext = context;
}

public boolean isAvailable() {
return this.mContext.getPackageManager().hasSystemFeature("android.hardware.sensor.assist");
}
}

0 comments on commit e0d49eb

Please sign in to comment.