Skip to content

Commit

Permalink
s2: Convert Doze into LeEcoParts
Browse files Browse the repository at this point in the history
 * This is the preparation for turning the package into
   an unified device-settings app.

Change-Id: I425ad525edcc63c2dcccd1e2fb8459f442744970
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
  • Loading branch information
bgcngm authored and Akash98Sky committed Aug 25, 2019
1 parent 7485415 commit 9087944
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ PRODUCT_PACKAGES += \
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/ad_calib.cfg:system/etc/ad_calib.cfg

# Doze mode
# Device specific settings
PRODUCT_PACKAGES += \
Doze
LeEcoParts

# Fake logprint for fingerprint libs
PRODUCT_PACKAGES += \
Expand Down
2 changes: 1 addition & 1 deletion doze/Android.mk → parts/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := Doze
LOCAL_PACKAGE_NAME := LeEcoParts
LOCAL_CERTIFICATE := platform
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PRIVILEGED_MODULE := true
Expand Down
10 changes: 5 additions & 5 deletions doze/AndroidManifest.xml → parts/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015-2016 The CyanogenMod Project
2017 The LineageOS Project
2017-2018 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.lineageos.settings.doze"
package="org.lineageos.settings"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system">
Expand All @@ -41,12 +41,12 @@
</intent-filter>
</receiver>

<service android:name=".DozeService"
android:permission="DozeService">
<service android:name=".doze.DozeService"
android:permission="LeEcoDozeService">
</service>

<activity
android:name=".DozeSettingsActivity"
android:name=".doze.DozeSettingsActivity"
android:label="@string/ambient_display_title"
android:theme="@style/Theme.Main">
<intent-filter>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
* 2017 The LineageOS Project
* 2017-2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,23 +15,24 @@
* limitations under the License.
*/

package org.lineageos.settings.doze;
package org.lineageos.settings;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import org.lineageos.settings.doze.DozeUtils;

public class BootCompletedReceiver extends BroadcastReceiver {

private static final boolean DEBUG = false;
private static final String TAG = "Doze";

private static final String TAG = "LeEcoParts";
@Override
public void onReceive(final Context context, Intent intent) {
if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) {
if (DEBUG) Log.d(TAG, "Starting service");
Utils.startService(context);
if (DozeUtils.isDozeEnabled(context) && DozeUtils.sensorsEnabled(context)) {
if (DEBUG) Log.d(TAG, "Starting Doze service");
DozeUtils.startService(context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ public IBinder onBind(Intent intent) {

private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on");
if (Utils.isPickUpEnabled(this)) {
if (DozeUtils.isPickUpEnabled(this)) {
mTiltSensor.disable();
}
if (Utils.isHandwaveGestureEnabled(this) ||
Utils.isPocketGestureEnabled(this)) {
if (DozeUtils.isHandwaveGestureEnabled(this) ||
DozeUtils.isPocketGestureEnabled(this)) {
mProximitySensor.disable();
}
}

private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off");
if (Utils.isPickUpEnabled(this)) {
if (DozeUtils.isPickUpEnabled(this)) {
mTiltSensor.enable();
}
if (Utils.isHandwaveGestureEnabled(this) ||
Utils.isPocketGestureEnabled(this)) {
if (DozeUtils.isHandwaveGestureEnabled(this) ||
DozeUtils.isPocketGestureEnabled(this)) {
mProximitySensor.enable();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import android.widget.Switch;
import android.widget.TextView;

import org.lineageos.settings.R;

public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
CompoundButton.OnCheckedChangeListener {

Expand All @@ -60,17 +62,17 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
showHelp();
}

boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());

mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
mPickUpPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_PICK_UP_KEY);
mPickUpPreference.setEnabled(dozeEnabled);
mPickUpPreference.setOnPreferenceChangeListener(this);

mHandwavePreference = (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference.setEnabled(dozeEnabled);
mHandwavePreference.setOnPreferenceChangeListener(this);

mPocketPreference = (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
mPocketPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this);

Expand All @@ -79,7 +81,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze,
container, false);
((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
return view;
}
Expand All @@ -88,7 +91,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());

mTextView = view.findViewById(R.id.switch_text);
mTextView.setText(getString(dozeEnabled ?
Expand All @@ -107,15 +110,15 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
Utils.checkDozeService(getActivity());
DozeUtils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
DozeUtils.checkDozeService(getActivity());
return true;
}

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
Utils.enableDoze(getActivity(), isChecked);
Utils.checkDozeService(getActivity());
DozeUtils.enableDoze(getActivity(), isChecked);
DozeUtils.checkDozeService(getActivity());

mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar.setActivated(isChecked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static android.provider.Settings.Secure.DOZE_ENABLED;

public final class Utils {
public final class DozeUtils {

private static final String TAG = "DozeUtils";
private static final boolean DEBUG = false;
Expand All @@ -37,7 +37,7 @@ public final class Utils {
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";

protected static void startService(Context context) {
public static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service");
context.startServiceAsUser(new Intent(context, DozeService.class),
UserHandle.CURRENT);
Expand All @@ -57,7 +57,7 @@ protected static void checkDozeService(Context context) {
}
}

protected static boolean isDozeEnabled(Context context) {
public static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
DOZE_ENABLED, 1) != 0;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ protected static boolean isPocketGestureEnabled(Context context) {
return isGestureEnabled(context, GESTURE_POCKET_KEY);
}

protected static boolean sensorsEnabled(Context context) {
public static boolean sensorsEnabled(Context context) {
return isPickUpEnabled(context) || isHandwaveGestureEnabled(context)
|| isPocketGestureEnabled(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onSensorChanged(SensorEvent event) {
boolean isNear = event.values[0] < mSensor.getMaximumRange();
if (mSawNear && !isNear) {
if (shouldPulse(event.timestamp)) {
Utils.launchDozePulse(mContext);
DozeUtils.launchDozePulse(mContext);
}
} else {
mInPocketTime = event.timestamp;
Expand All @@ -74,11 +74,12 @@ public void onSensorChanged(SensorEvent event) {
private boolean shouldPulse(long timestamp) {
long delta = timestamp - mInPocketTime;

if (Utils.isHandwaveGestureEnabled(mContext) && Utils.isPocketGestureEnabled(mContext)) {
if (DozeUtils.isHandwaveGestureEnabled(mContext) &&
DozeUtils.isPocketGestureEnabled(mContext)) {
return true;
} else if (Utils.isHandwaveGestureEnabled(mContext)) {
} else if (DozeUtils.isHandwaveGestureEnabled(mContext)) {
return delta < HANDWAVE_MAX_DELTA_NS;
} else if (Utils.isPocketGestureEnabled(mContext)) {
} else if (DozeUtils.isPocketGestureEnabled(mContext)) {
return delta >= POCKET_MIN_DELTA_NS;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onSensorChanged(SensorEvent event) {
}

if (event.values[0] == 1) {
Utils.launchDozePulse(mContext);
DozeUtils.launchDozePulse(mContext);
}
}

Expand Down

0 comments on commit 9087944

Please sign in to comment.