davinci: parts: clang-format everything

Change-Id: Iae92b7197a58b4353dafa7e24d67ebb5f096f2b5
This commit is contained in:
Arian 2020-10-14 23:12:48 +02:00
parent a5fe3b11a6
commit fed308cae8
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9
7 changed files with 77 additions and 80 deletions

View File

@ -26,13 +26,13 @@ import org.lineageos.settings.doze.DozeUtils;
import org.lineageos.settings.popupcamera.PopupCameraUtils; import org.lineageos.settings.popupcamera.PopupCameraUtils;
public class BootCompletedReceiver extends BroadcastReceiver { public class BootCompletedReceiver extends BroadcastReceiver {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String TAG = "XiaomiParts"; private static final String TAG = "XiaomiParts";
@Override @Override
public void onReceive(final Context context, Intent intent) { public void onReceive(final Context context, Intent intent) {
if (DEBUG) Log.d(TAG, "Received boot completed intent"); if (DEBUG)
Log.d(TAG, "Received boot completed intent");
DozeUtils.checkDozeService(context); DozeUtils.checkDozeService(context);
PopupCameraUtils.startService(context); PopupCameraUtils.startService(context);
} }

View File

@ -34,7 +34,8 @@ public class DozeService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service"); if (DEBUG)
Log.d(TAG, "Creating service");
mProximitySensor = new ProximitySensor(this); mProximitySensor = new ProximitySensor(this);
mPickupSensor = new PickupSensor(this); mPickupSensor = new PickupSensor(this);
@ -46,13 +47,15 @@ public class DozeService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (DEBUG) Log.d(TAG, "Starting service"); if (DEBUG)
Log.d(TAG, "Starting service");
return START_STICKY; return START_STICKY;
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
if (DEBUG) Log.d(TAG, "Destroying service"); if (DEBUG)
Log.d(TAG, "Destroying service");
super.onDestroy(); super.onDestroy();
this.unregisterReceiver(mScreenStateReceiver); this.unregisterReceiver(mScreenStateReceiver);
mProximitySensor.disable(); mProximitySensor.disable();
@ -65,23 +68,23 @@ public class DozeService extends Service {
} }
private void onDisplayOn() { private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on"); if (DEBUG)
Log.d(TAG, "Display on");
if (DozeUtils.isPickUpEnabled(this)) { if (DozeUtils.isPickUpEnabled(this)) {
mPickupSensor.disable(); mPickupSensor.disable();
} }
if (DozeUtils.isHandwaveGestureEnabled(this) || if (DozeUtils.isHandwaveGestureEnabled(this) || DozeUtils.isPocketGestureEnabled(this)) {
DozeUtils.isPocketGestureEnabled(this)) {
mProximitySensor.disable(); mProximitySensor.disable();
} }
} }
private void onDisplayOff() { private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off"); if (DEBUG)
Log.d(TAG, "Display off");
if (DozeUtils.isPickUpEnabled(this)) { if (DozeUtils.isPickUpEnabled(this)) {
mPickupSensor.enable(); mPickupSensor.enable();
} }
if (DozeUtils.isHandwaveGestureEnabled(this) || if (DozeUtils.isHandwaveGestureEnabled(this) || DozeUtils.isPocketGestureEnabled(this)) {
DozeUtils.isPocketGestureEnabled(this)) {
mProximitySensor.enable(); mProximitySensor.enable();
} }
} }

View File

@ -21,14 +21,15 @@ import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
public class DozeSettingsActivity extends PreferenceActivity { public class DozeSettingsActivity extends PreferenceActivity {
private static final String TAG_DOZE = "doze"; private static final String TAG_DOZE = "doze";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, getFragmentManager()
new DozeSettingsFragment(), TAG_DOZE).commit(); .beginTransaction()
.replace(android.R.id.content, new DozeSettingsFragment(), TAG_DOZE)
.commit();
} }
} }

View File

@ -42,9 +42,8 @@ import androidx.preference.SwitchPreference;
import org.lineageos.settings.R; import org.lineageos.settings.R;
public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener, public class DozeSettingsFragment extends PreferenceFragment
CompoundButton.OnCheckedChangeListener { implements OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
private TextView mTextView; private TextView mTextView;
private View mSwitchBar; private View mSwitchBar;
@ -62,8 +61,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
final ActionBar actionBar = getActivity().getActionBar(); final ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings", SharedPreferences prefs =
Activity.MODE_PRIVATE); getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) { if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) {
showHelp(); showHelp();
} }
@ -75,10 +74,12 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity())); mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this); mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
PreferenceCategory pickupSensorCategory = (PreferenceCategory) getPreferenceScreen(). PreferenceCategory pickupSensorCategory =
findPreference(DozeUtils.CATEG_PICKUP_SENSOR); (PreferenceCategory) getPreferenceScreen().findPreference(
PreferenceCategory proximitySensorCategory = (PreferenceCategory) getPreferenceScreen(). DozeUtils.CATEG_PICKUP_SENSOR);
findPreference(DozeUtils.CATEG_PROX_SENSOR); PreferenceCategory proximitySensorCategory =
(PreferenceCategory) getPreferenceScreen().findPreference(
DozeUtils.CATEG_PROX_SENSOR);
mPickUpPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_PICK_UP_KEY); mPickUpPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_PICK_UP_KEY);
mPickUpPreference.setEnabled(dozeEnabled); mPickUpPreference.setEnabled(dozeEnabled);
@ -107,10 +108,10 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(
Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, final View view =
container, false); LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
return view; return view;
} }
@ -122,8 +123,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity()); boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());
mTextView = view.findViewById(R.id.switch_text); mTextView = view.findViewById(R.id.switch_text);
mTextView.setText(getString(dozeEnabled ? mTextView.setText(
R.string.switch_bar_on : R.string.switch_bar_off)); getString(dozeEnabled ? R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar = view.findViewById(R.id.switch_bar); mSwitchBar = view.findViewById(R.id.switch_bar);
Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget); Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget);
@ -187,7 +188,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE) getActivity()
.getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
.edit() .edit()
.putBoolean("first_help_shown", true) .putBoolean("first_help_shown", true)
.commit(); .commit();

View File

@ -32,7 +32,6 @@ import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
import static android.provider.Settings.Secure.DOZE_ENABLED; import static android.provider.Settings.Secure.DOZE_ENABLED;
public final class DozeUtils { public final class DozeUtils {
private static final String TAG = "DozeUtils"; private static final String TAG = "DozeUtils";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
@ -48,15 +47,15 @@ public final class DozeUtils {
protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
public static void startService(Context context) { public static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service"); if (DEBUG)
context.startServiceAsUser(new Intent(context, DozeService.class), Log.d(TAG, "Starting service");
UserHandle.CURRENT); context.startServiceAsUser(new Intent(context, DozeService.class), UserHandle.CURRENT);
} }
protected static void stopService(Context context) { protected static void stopService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping service"); if (DEBUG)
context.stopServiceAsUser(new Intent(context, DozeService.class), Log.d(TAG, "Stopping service");
UserHandle.CURRENT); context.stopServiceAsUser(new Intent(context, DozeService.class), UserHandle.CURRENT);
} }
public static void checkDozeService(Context context) { public static void checkDozeService(Context context) {
@ -70,8 +69,8 @@ public final class DozeUtils {
protected static boolean getProxCheckBeforePulse(Context context) { protected static boolean getProxCheckBeforePulse(Context context) {
try { try {
Context con = context.createPackageContext("com.android.systemui", 0); Context con = context.createPackageContext("com.android.systemui", 0);
int id = con.getResources().getIdentifier("doze_proximity_check_before_pulse", int id = con.getResources().getIdentifier(
"bool", "com.android.systemui"); "doze_proximity_check_before_pulse", "bool", "com.android.systemui");
return con.getResources().getBoolean(id); return con.getResources().getBoolean(id);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
return false; return false;
@ -79,33 +78,33 @@ public final class DozeUtils {
} }
protected static boolean enableDoze(Context context, boolean enable) { protected static boolean enableDoze(Context context, boolean enable) {
return Settings.Secure.putInt(context.getContentResolver(), return Settings.Secure.putInt(context.getContentResolver(), DOZE_ENABLED, enable ? 1 : 0);
DOZE_ENABLED, enable ? 1 : 0);
} }
public static boolean isDozeEnabled(Context context) { public static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(), return Settings.Secure.getInt(context.getContentResolver(), DOZE_ENABLED, 1) != 0;
DOZE_ENABLED, 1) != 0;
} }
protected static void launchDozePulse(Context context) { protected static void launchDozePulse(Context context) {
if (DEBUG) Log.d(TAG, "Launch doze pulse"); if (DEBUG)
context.sendBroadcastAsUser(new Intent(DOZE_INTENT), Log.d(TAG, "Launch doze pulse");
new UserHandle(UserHandle.USER_CURRENT)); context.sendBroadcastAsUser(
new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT));
} }
protected static boolean enableAlwaysOn(Context context, boolean enable) { protected static boolean enableAlwaysOn(Context context, boolean enable) {
return Settings.Secure.putIntForUser(context.getContentResolver(), return Settings.Secure.putIntForUser(context.getContentResolver(), DOZE_ALWAYS_ON,
DOZE_ALWAYS_ON, enable ? 1 : 0, UserHandle.USER_CURRENT); enable ? 1 : 0, UserHandle.USER_CURRENT);
} }
protected static boolean isAlwaysOnEnabled(Context context) { protected static boolean isAlwaysOnEnabled(Context context) {
final boolean enabledByDefault = context.getResources() final boolean enabledByDefault = context.getResources().getBoolean(
.getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled); com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
return Settings.Secure.getIntForUser(context.getContentResolver(), return Settings.Secure.getIntForUser(context.getContentResolver(), DOZE_ALWAYS_ON,
DOZE_ALWAYS_ON, alwaysOnDisplayAvailable(context) && enabledByDefault ? 1 : 0, alwaysOnDisplayAvailable(context) && enabledByDefault ? 1 : 0,
UserHandle.USER_CURRENT) != 0; UserHandle.USER_CURRENT)
!= 0;
} }
protected static boolean alwaysOnDisplayAvailable(Context context) { protected static boolean alwaysOnDisplayAvailable(Context context) {
@ -113,8 +112,7 @@ public final class DozeUtils {
} }
protected static boolean isGestureEnabled(Context context, String gesture) { protected static boolean isGestureEnabled(Context context, String gesture) {
return PreferenceManager.getDefaultSharedPreferences(context) return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(gesture, false);
.getBoolean(gesture, false);
} }
protected static boolean isPickUpEnabled(Context context) { protected static boolean isPickUpEnabled(Context context) {

View File

@ -30,7 +30,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
public class PickupSensor implements SensorEventListener { public class PickupSensor implements SensorEventListener {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String TAG = "PickupSensor"; private static final String TAG = "PickupSensor";
@ -50,13 +49,12 @@ public class PickupSensor implements SensorEventListener {
mExecutorService = Executors.newSingleThreadExecutor(); mExecutorService = Executors.newSingleThreadExecutor();
} }
private Future<?> submit(Runnable runnable) { private Future<?> submit(Runnable runnable) { return mExecutorService.submit(runnable); }
return mExecutorService.submit(runnable);
}
@Override @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]); if (DEBUG)
Log.d(TAG, "Got sensor event: " + event.values[0]);
long delta = SystemClock.elapsedRealtime() - mEntryTimestamp; long delta = SystemClock.elapsedRealtime() - mEntryTimestamp;
if (delta < MIN_PULSE_INTERVAL_MS) { if (delta < MIN_PULSE_INTERVAL_MS) {
@ -76,18 +74,17 @@ public class PickupSensor implements SensorEventListener {
} }
protected void enable() { protected void enable() {
if (DEBUG) Log.d(TAG, "Enabling"); if (DEBUG)
Log.d(TAG, "Enabling");
submit(() -> { submit(() -> {
mSensorManager.registerListener(this, mSensor, mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
SensorManager.SENSOR_DELAY_NORMAL);
mEntryTimestamp = SystemClock.elapsedRealtime(); mEntryTimestamp = SystemClock.elapsedRealtime();
}); });
} }
protected void disable() { protected void disable() {
if (DEBUG) Log.d(TAG, "Disabling"); if (DEBUG)
submit(() -> { Log.d(TAG, "Disabling");
mSensorManager.unregisterListener(this, mSensor); submit(() -> { mSensorManager.unregisterListener(this, mSensor); });
});
} }
} }

View File

@ -29,7 +29,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
public class ProximitySensor implements SensorEventListener { public class ProximitySensor implements SensorEventListener {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String TAG = "ProximitySensor"; private static final String TAG = "ProximitySensor";
@ -54,9 +53,7 @@ public class ProximitySensor implements SensorEventListener {
mExecutorService = Executors.newSingleThreadExecutor(); mExecutorService = Executors.newSingleThreadExecutor();
} }
private Future<?> submit(Runnable runnable) { private Future<?> submit(Runnable runnable) { return mExecutorService.submit(runnable); }
return mExecutorService.submit(runnable);
}
@Override @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
@ -74,8 +71,8 @@ public class ProximitySensor implements SensorEventListener {
private boolean shouldPulse(long timestamp) { private boolean shouldPulse(long timestamp) {
long delta = timestamp - mInPocketTime; long delta = timestamp - mInPocketTime;
if (DozeUtils.isHandwaveGestureEnabled(mContext) && if (DozeUtils.isHandwaveGestureEnabled(mContext)
DozeUtils.isPocketGestureEnabled(mContext)) { && DozeUtils.isPocketGestureEnabled(mContext)) {
return true; return true;
} else if (DozeUtils.isHandwaveGestureEnabled(mContext)) { } else if (DozeUtils.isHandwaveGestureEnabled(mContext)) {
return delta < HANDWAVE_MAX_DELTA_NS; return delta < HANDWAVE_MAX_DELTA_NS;
@ -91,17 +88,16 @@ public class ProximitySensor implements SensorEventListener {
} }
protected void enable() { protected void enable() {
if (DEBUG) Log.d(TAG, "Enabling"); if (DEBUG)
Log.d(TAG, "Enabling");
submit(() -> { submit(() -> {
mSensorManager.registerListener(this, mSensor, mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
SensorManager.SENSOR_DELAY_NORMAL);
}); });
} }
protected void disable() { protected void disable() {
if (DEBUG) Log.d(TAG, "Disabling"); if (DEBUG)
submit(() -> { Log.d(TAG, "Disabling");
mSensorManager.unregisterListener(this, mSensor); submit(() -> { mSensorManager.unregisterListener(this, mSensor); });
});
} }
} }